forked from ddrilling/AsbCloudServer
OperationsStatService. Исправлен расчет плановой глубины, для определения отставания от ГГД.
This commit is contained in:
parent
8fc4a4d598
commit
05e373e16b
@ -12,11 +12,10 @@ 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 IMemoryCache memoryCache;
|
||||
private readonly IWellService wellService;
|
||||
@ -180,7 +179,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
|
||||
|
||||
private double? CalcTvdLagPercent(int? idTelemetry, IOrderedEnumerable<WellOperation> wellOperations)
|
||||
{
|
||||
var currentDate = DateTime.UtcNow;
|
||||
var currentDate = DateTimeOffset.UtcNow;
|
||||
|
||||
var wellDepth = wellOperations
|
||||
.LastOrDefault(o => o.IdType == WellOperation.IdOperationTypeFact)?.DepthEnd;
|
||||
@ -188,35 +187,66 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
|
||||
if (idTelemetry.HasValue)
|
||||
wellDepth = telemetryDataCache.GetLastOrDefault(idTelemetry.Value)?.WellDepth;
|
||||
|
||||
if (wellDepth is null)
|
||||
return null;
|
||||
|
||||
var planOperations = wellOperations
|
||||
.Where(o => o.IdType == WellOperation.IdOperationTypePlan)
|
||||
.OrderBy(o => o.DateStart.AddHours(o.DurationHours));
|
||||
|
||||
var wellOperationFrom = planOperations
|
||||
.LastOrDefault(o => o.DateStart.AddHours(o.DurationHours) <= currentDate);
|
||||
|
||||
var wellOperationTo = planOperations
|
||||
.FirstOrDefault(o => o.DateStart >= currentDate);
|
||||
|
||||
var wellOperationDepthFrom = wellOperationFrom?.DepthEnd;
|
||||
var wellOperationDepthTo = wellOperationTo?.DepthStart ?? wellOperationDepthFrom;
|
||||
|
||||
var wellOperationDateFrom = wellOperationFrom?.DateStart.AddHours(wellOperationFrom.DurationHours);
|
||||
var wellOperationDateTo = wellOperationTo?.DateStart ?? currentDate;
|
||||
|
||||
if (wellOperationDateTo <= wellOperationDateFrom ||
|
||||
currentDate <= wellOperationDateFrom ||
|
||||
(wellOperationDateTo - wellOperationDateFrom)?.TotalHours is null or 0)
|
||||
if (!planOperations.Any())
|
||||
return null;
|
||||
|
||||
var planDepth = (currentDate - wellOperationDateFrom)?.TotalHours *
|
||||
(wellOperationDepthTo - wellOperationDepthFrom) /
|
||||
(wellOperationDateTo - wellOperationDateFrom)?.TotalHours +
|
||||
wellOperationDepthFrom;
|
||||
var planDepth = CalcPlanDepth(planOperations, currentDate);
|
||||
|
||||
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)
|
||||
{
|
||||
var sectionTypeIds = operations
|
||||
@ -551,6 +581,4 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
|
||||
destination.DateStart = source.DateStart.ToRemoteDateTime(tzOffsetHours);
|
||||
return destination;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user