forked from ddrilling/AsbCloudServer
Merge branch 'dev' into feature/refactoring_api_route
This commit is contained in:
commit
b3ed280d8f
@ -53,8 +53,8 @@ namespace AsbCloudApp.Data
|
|||||||
public IEnumerable<CompanyDto> Companies { get; set; } = Enumerable.Empty<CompanyDto>();
|
public IEnumerable<CompanyDto> Companies { get; set; } = Enumerable.Empty<CompanyDto>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Отставание от ГГД, дней
|
/// Отставание от ГГД, проценты
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public double TvdLagDays { get; set; } = 0;
|
public double? TvdLagPercent { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -95,9 +95,8 @@ namespace AsbCloudApp.Data
|
|||||||
public PlanFactDto<double?> WellDepth { get; set; } = null!;
|
public PlanFactDto<double?> WellDepth { get; set; } = null!;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Отставание от ГГД, дни
|
/// Отставание от ГГД, проценты
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public double TvdLagDays { get; set; }
|
public double TvdLagPercent { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -138,8 +138,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
wellMapInfo.FirstFactOperationDateStart = wellOperationsStat?.Total.Fact?.Start
|
wellMapInfo.FirstFactOperationDateStart = wellOperationsStat?.Total.Fact?.Start
|
||||||
?? wellOperationsStat?.Total.Plan?.Start;
|
?? wellOperationsStat?.Total.Plan?.Start;
|
||||||
|
|
||||||
wellMapInfo.LastPredictOperationDateEnd = wellOperationsStat?.Total.Plan?.End?
|
wellMapInfo.LastPredictOperationDateEnd = wellOperationsStat?.Total.Plan?.End;
|
||||||
.AddDays(wellOperationsStat?.TvdLagDays ?? 0d);
|
|
||||||
|
|
||||||
wellMapInfo.WellDepth = new()
|
wellMapInfo.WellDepth = new()
|
||||||
{
|
{
|
||||||
@ -163,7 +162,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
wellMapInfo.SaubUsage = wellSubsystemStat?.SubsystemAKB?.KUsage ?? 0d;
|
wellMapInfo.SaubUsage = wellSubsystemStat?.SubsystemAKB?.KUsage ?? 0d;
|
||||||
wellMapInfo.SpinUsage = wellSubsystemStat?.SubsystemSpinMaster?.KUsage ?? 0d;
|
wellMapInfo.SpinUsage = wellSubsystemStat?.SubsystemSpinMaster?.KUsage ?? 0d;
|
||||||
wellMapInfo.TorqueKUsage = wellSubsystemStat?.SubsystemTorqueMaster?.KUsage ?? 0d;
|
wellMapInfo.TorqueKUsage = wellSubsystemStat?.SubsystemTorqueMaster?.KUsage ?? 0d;
|
||||||
wellMapInfo.TvdLagDays = wellOperationsStat?.TvdLagDays ?? 0d;
|
wellMapInfo.TvdLagPercent = wellOperationsStat?.TvdLagPercent ?? 0d;
|
||||||
wellMapInfo.IdsCompanies = well.Companies.Select(c => c.Id);
|
wellMapInfo.IdsCompanies = well.Companies.Select(c => c.Id);
|
||||||
|
|
||||||
return wellMapInfo;
|
return wellMapInfo;
|
||||||
|
@ -9,21 +9,25 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using AsbCloudApp.Data.SAUB;
|
||||||
|
using AsbCloudInfrastructure.Services.SAUB;
|
||||||
|
|
||||||
namespace AsbCloudInfrastructure.Services.WellOperationService
|
namespace AsbCloudInfrastructure.Services.WellOperationService;
|
||||||
{
|
|
||||||
|
|
||||||
public class OperationsStatService : IOperationsStatService
|
public class OperationsStatService : IOperationsStatService
|
||||||
{
|
{
|
||||||
private readonly IAsbCloudDbContext db;
|
private readonly IAsbCloudDbContext db;
|
||||||
private readonly IMemoryCache memoryCache;
|
private readonly IMemoryCache memoryCache;
|
||||||
private readonly IWellService wellService;
|
private readonly IWellService wellService;
|
||||||
|
private readonly TelemetryDataCache<TelemetryDataSaubDto> telemetryDataCache;
|
||||||
|
|
||||||
public OperationsStatService(IAsbCloudDbContext db, IMemoryCache memoryCache, IWellService wellService)
|
public OperationsStatService(IAsbCloudDbContext db, IMemoryCache memoryCache, IWellService wellService,
|
||||||
|
TelemetryDataCache<TelemetryDataSaubDto> telemetryDataCache)
|
||||||
{
|
{
|
||||||
this.db = db;
|
this.db = db;
|
||||||
this.memoryCache = memoryCache;
|
this.memoryCache = memoryCache;
|
||||||
this.wellService = wellService;
|
this.wellService = wellService;
|
||||||
|
this.telemetryDataCache = telemetryDataCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<StatClusterDto?> GetOrDefaultStatClusterAsync(int idCluster, int idCompany, CancellationToken token)
|
public async Task<StatClusterDto?> GetOrDefaultStatClusterAsync(int idCluster, int idCompany, CancellationToken token)
|
||||||
@ -168,46 +172,81 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
|
|||||||
var timezoneOffsetH = wellService.GetTimezone(well.Id).Hours;
|
var timezoneOffsetH = wellService.GetTimezone(well.Id).Hours;
|
||||||
statWellDto.Sections = CalcSectionsStats(wellOperations, timezoneOffsetH);
|
statWellDto.Sections = CalcSectionsStats(wellOperations, timezoneOffsetH);
|
||||||
statWellDto.Total = GetStatTotal(wellOperations, well.IdState, timezoneOffsetH);
|
statWellDto.Total = GetStatTotal(wellOperations, well.IdState, timezoneOffsetH);
|
||||||
statWellDto.TvdLagDays = CalcTvdLagDays(wellOperations);
|
statWellDto.TvdLagPercent = CalcTvdLagPercent(well.IdTelemetry, wellOperations);
|
||||||
|
|
||||||
return statWellDto;
|
return statWellDto;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static double CalcTvdLagDays(IOrderedEnumerable<WellOperation> wellOperations)
|
private double? CalcTvdLagPercent(int? idTelemetry, IOrderedEnumerable<WellOperation> wellOperations)
|
||||||
{
|
{
|
||||||
var operationsOrdered = wellOperations
|
var currentDate = DateTimeOffset.UtcNow;
|
||||||
.OrderBy(o => o.DateStart);
|
|
||||||
|
|
||||||
var factOperations = operationsOrdered
|
var wellDepth = wellOperations
|
||||||
.Where(o => o.IdType == WellOperation.IdOperationTypeFact);
|
.LastOrDefault(o => o.IdType == WellOperation.IdOperationTypeFact)?.DepthEnd;
|
||||||
|
|
||||||
var lastCorrespondingFactOperation = factOperations
|
if (idTelemetry.HasValue)
|
||||||
.LastOrDefault(o => o.IdPlan is not null);
|
wellDepth = telemetryDataCache.GetLastOrDefault(idTelemetry.Value)?.WellDepth;
|
||||||
|
|
||||||
if (lastCorrespondingFactOperation is null)
|
if (wellDepth is null)
|
||||||
return 0d;
|
return null;
|
||||||
|
|
||||||
var lastCorrespondingPlanOperation = wellOperations
|
var planOperations = wellOperations
|
||||||
.FirstOrDefault(o => o.Id == lastCorrespondingFactOperation.IdPlan);
|
|
||||||
|
|
||||||
if (lastCorrespondingPlanOperation is null)
|
|
||||||
return 0d;
|
|
||||||
|
|
||||||
var lastFactOperation = factOperations.Last();
|
|
||||||
|
|
||||||
var remainingPlanOperations = operationsOrdered
|
|
||||||
.Where(o => o.IdType == WellOperation.IdOperationTypePlan)
|
.Where(o => o.IdType == WellOperation.IdOperationTypePlan)
|
||||||
.Where(o => o.DateStart > lastCorrespondingPlanOperation.DateStart);
|
.OrderBy(o => o.DateStart.AddHours(o.DurationHours));
|
||||||
|
|
||||||
var durationRemain = remainingPlanOperations.Sum(o => o.DurationHours);
|
if (!planOperations.Any())
|
||||||
|
return null;
|
||||||
|
|
||||||
var factEnd = lastFactOperation.DateStart.AddHours(durationRemain + lastFactOperation.DurationHours);
|
var planDepth = CalcPlanDepth(planOperations, currentDate);
|
||||||
var planEnd = lastCorrespondingFactOperation.DateStart.AddHours(durationRemain + lastCorrespondingFactOperation.DurationHours);
|
|
||||||
var lagDays = (planEnd - factEnd).TotalDays;
|
|
||||||
|
|
||||||
return lagDays;
|
if (planDepth is null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
if (planDepth == 0d)
|
||||||
|
return 0d;
|
||||||
|
|
||||||
|
return (1 - wellDepth / planDepth) * 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static double? CalcPlanDepth(IOrderedEnumerable<WellOperation> planOperations, DateTimeOffset currentDate)
|
||||||
|
{
|
||||||
|
var operationIn = planOperations
|
||||||
|
.FirstOrDefault(o => o.DateStart <= currentDate && o.DateStart.AddHours(o.DurationHours) >= currentDate);
|
||||||
|
|
||||||
|
if (operationIn is not null)
|
||||||
|
return Interpolate(
|
||||||
|
operationIn.DepthStart,
|
||||||
|
operationIn.DepthEnd,
|
||||||
|
operationIn.DateStart,
|
||||||
|
operationIn.DateStart.AddHours(operationIn.DurationHours),
|
||||||
|
currentDate);
|
||||||
|
|
||||||
|
var operationFrom = planOperations
|
||||||
|
.LastOrDefault(o => o.DateStart.AddHours(o.DurationHours) <= currentDate);
|
||||||
|
|
||||||
|
var operationTo = planOperations
|
||||||
|
.FirstOrDefault(o => o.DateStart >= currentDate);
|
||||||
|
|
||||||
|
if (operationFrom is null && operationTo is not null)
|
||||||
|
return 0d;
|
||||||
|
else if (operationFrom is not null && operationTo is not null)
|
||||||
|
{
|
||||||
|
return Interpolate(
|
||||||
|
operationFrom.DepthEnd,
|
||||||
|
operationTo.DepthStart,
|
||||||
|
operationFrom.DateStart.AddHours(operationTo.DurationHours),
|
||||||
|
operationTo.DateStart,
|
||||||
|
currentDate);
|
||||||
|
}
|
||||||
|
else if (operationFrom is not null && operationTo is null)
|
||||||
|
return operationFrom.DepthEnd;
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static double Interpolate(double y0, double y1, DateTimeOffset x0, DateTimeOffset x1, DateTimeOffset x)
|
||||||
|
=> y0 + (y1 - y0) * (x - x0).TotalMinutes / (x1 - x0).TotalMinutes;
|
||||||
|
|
||||||
private IEnumerable<StatSectionDto> CalcSectionsStats(IEnumerable<WellOperation> operations, double timezoneOffsetH)
|
private IEnumerable<StatSectionDto> CalcSectionsStats(IEnumerable<WellOperation> operations, double timezoneOffsetH)
|
||||||
{
|
{
|
||||||
var sectionTypeIds = operations
|
var sectionTypeIds = operations
|
||||||
@ -543,5 +582,3 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
|
|||||||
return destination;
|
return destination;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user