From d9dac97b9ea1e75836606827902097ee8cfa157d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D1=82=D0=B5=D0=BF=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=94?= =?UTF-8?q?=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9?= Date: Wed, 27 Sep 2023 13:49:55 +0500 Subject: [PATCH] =?UTF-8?q?=D0=A1=D1=82=D0=B0=D1=82=D0=B8=D1=81=D1=82?= =?UTF-8?q?=D0=B8=D0=BA=D0=B0=20=D0=BF=D0=BE=20=D1=81=D0=BA=D0=B2=D0=B0?= =?UTF-8?q?=D0=B6=D0=B8=D0=BD=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Вернул подсчёт отклонения по ГГД в днях 2. Добавил дни бурения скважины --- AsbCloudApp/Data/StatWellDto.cs | 9 +- AsbCloudApp/Data/WellMapInfoDto.cs | 9 +- .../Services/WellInfoService.cs | 3 +- .../OperationsStatService.cs | 104 ++++++++---------- 4 files changed, 60 insertions(+), 65 deletions(-) diff --git a/AsbCloudApp/Data/StatWellDto.cs b/AsbCloudApp/Data/StatWellDto.cs index 59ffd3d7..af5323f6 100644 --- a/AsbCloudApp/Data/StatWellDto.cs +++ b/AsbCloudApp/Data/StatWellDto.cs @@ -53,8 +53,13 @@ namespace AsbCloudApp.Data public IEnumerable Companies { get; set; } = Enumerable.Empty(); /// - /// Отставание от ГГД, проценты + /// Отставание от ГГД, дни /// - public double? TvdLagPercent { get; set; } + public double? TvdLagDays { get; set; } + + /// + /// Кол-во дней бурения по ГГД + /// + public double? TvdDrillingDays { get; set; } } } diff --git a/AsbCloudApp/Data/WellMapInfoDto.cs b/AsbCloudApp/Data/WellMapInfoDto.cs index 8b0bdb58..5f6ca5a7 100644 --- a/AsbCloudApp/Data/WellMapInfoDto.cs +++ b/AsbCloudApp/Data/WellMapInfoDto.cs @@ -125,8 +125,13 @@ namespace AsbCloudApp.Data public PlanFactDto WellDepth { get; set; } = null!; /// - /// Отставание от ГГД, проценты + /// Отставание от ГГД, дни /// - public double TvdLagPercent { get; set; } + public double? TvdLagDays { get; set; } + + /// + /// Кол-во дней бурения по ГГД + /// + public double? TvdDrillingDays { get; set; } } } diff --git a/AsbCloudInfrastructure/Services/WellInfoService.cs b/AsbCloudInfrastructure/Services/WellInfoService.cs index efcfd54d..eea573cc 100644 --- a/AsbCloudInfrastructure/Services/WellInfoService.cs +++ b/AsbCloudInfrastructure/Services/WellInfoService.cs @@ -188,7 +188,8 @@ namespace AsbCloudInfrastructure.Services wellMapInfo.SaubUsage = wellSubsystemStat?.SubsystemAKB?.KUsage ?? 0d; wellMapInfo.SpinUsage = wellSubsystemStat?.SubsystemSpinMaster?.KUsage ?? 0d; wellMapInfo.TorqueKUsage = wellSubsystemStat?.SubsystemTorqueMaster?.KUsage ?? 0d; - wellMapInfo.TvdLagPercent = wellOperationsStat?.TvdLagPercent ?? 0d; + wellMapInfo.TvdLagDays = wellOperationsStat?.TvdLagDays; + wellMapInfo.TvdDrillingDays = wellOperationsStat?.TvdDrillingDays; wellMapInfo.IdsCompanies = well.Companies.Select(c => c.Id); return wellMapInfo; diff --git a/AsbCloudInfrastructure/Services/WellOperationService/OperationsStatService.cs b/AsbCloudInfrastructure/Services/WellOperationService/OperationsStatService.cs index e3c63e04..a63586e6 100644 --- a/AsbCloudInfrastructure/Services/WellOperationService/OperationsStatService.cs +++ b/AsbCloudInfrastructure/Services/WellOperationService/OperationsStatService.cs @@ -172,81 +172,65 @@ public class OperationsStatService : IOperationsStatService var timezoneOffsetH = wellService.GetTimezone(well.Id).Hours; statWellDto.Sections = CalcSectionsStats(wellOperations, timezoneOffsetH); statWellDto.Total = GetStatTotal(wellOperations, well.IdState, timezoneOffsetH); - statWellDto.TvdLagPercent = CalcTvdLagPercent(well.IdTelemetry, wellOperations); + statWellDto.TvdLagDays = CalcTvdLagDays(wellOperations); + statWellDto.TvdDrillingDays = CalcDrillingDays(wellOperations); return statWellDto; } - private double? CalcTvdLagPercent(int? idTelemetry, IOrderedEnumerable wellOperations) + private static double? CalcDrillingDays(IEnumerable wellOperations) { - var currentDate = DateTimeOffset.UtcNow; + var operationsOrdered = wellOperations + .OrderBy(o => o.DateStart); - var wellDepth = wellOperations - .LastOrDefault(o => o.IdType == WellOperation.IdOperationTypeFact)?.DepthEnd; - - if (idTelemetry.HasValue) - wellDepth = telemetryDataCache.GetLastOrDefault(idTelemetry.Value)?.WellDepth; + var factOperations = operationsOrdered + .Where(o => o.IdType == WellOperation.IdOperationTypeFact); - if (wellDepth is null) + if (!factOperations.Any()) + return null; + + var operationFrom = factOperations.First(); + + var operationTo = factOperations.Last(); + + return (operationTo.DateStart.AddHours(operationFrom.DurationHours) - operationFrom.DateStart).TotalDays; + } + + private static double? CalcTvdLagDays(IEnumerable wellOperations) + { + var operationsOrdered = wellOperations + .OrderBy(o => o.DateStart); + + var factOperations = operationsOrdered + .Where(o => o.IdType == WellOperation.IdOperationTypeFact); + + var lastCorrespondingFactOperation = factOperations + .LastOrDefault(o => o.IdPlan is not null); + + if (lastCorrespondingFactOperation is null) + return null; + + var lastCorrespondingPlanOperation = wellOperations + .FirstOrDefault(o => o.Id == lastCorrespondingFactOperation.IdPlan); + + if (lastCorrespondingPlanOperation is null) return null; - var planOperations = wellOperations + var lastFactOperation = factOperations.Last(); + + var remainingPlanOperations = operationsOrdered .Where(o => o.IdType == WellOperation.IdOperationTypePlan) - .OrderBy(o => o.DateStart.AddHours(o.DurationHours)); + .Where(o => o.DateStart > lastCorrespondingPlanOperation.DateStart); - if (!planOperations.Any()) - return null; + var durationRemain = remainingPlanOperations.Sum(o => o.DurationHours); - var planDepth = CalcPlanDepth(planOperations, currentDate); + var factEnd = lastFactOperation.DateStart.AddHours(durationRemain + lastFactOperation.DurationHours); + var planEnd = lastCorrespondingFactOperation.DateStart.AddHours(durationRemain + lastCorrespondingFactOperation.DurationHours); + var lagDays = (planEnd - factEnd).TotalDays; - if (planDepth is null) - return null; - - if (planDepth == 0d) - return 0d; - - return (1 - wellDepth / planDepth) * 100; + return lagDays; } - private static double? CalcPlanDepth(IOrderedEnumerable 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 CalcSectionsStats(IEnumerable operations, double timezoneOffsetH) { var sectionTypeIds = operations