diff --git a/AsbCloudApp/Data/StatWellDto.cs b/AsbCloudApp/Data/StatWellDto.cs index 9793e858..1b8ecbeb 100644 --- a/AsbCloudApp/Data/StatWellDto.cs +++ b/AsbCloudApp/Data/StatWellDto.cs @@ -51,5 +51,10 @@ namespace AsbCloudApp.Data /// компании участвующие в строительстве скважины /// public IEnumerable Companies { get; set; } = Enumerable.Empty(); + + /// + /// Отставание от ГГД, дней + /// + public double TvdLagDays { get; set; } = 0; } } diff --git a/AsbCloudInfrastructure/Services/WellInfoService.cs b/AsbCloudInfrastructure/Services/WellInfoService.cs index 9b6986bf..d627dc4e 100644 --- a/AsbCloudInfrastructure/Services/WellInfoService.cs +++ b/AsbCloudInfrastructure/Services/WellInfoService.cs @@ -88,7 +88,6 @@ namespace AsbCloudInfrastructure.Services WellMapInfo = activeWells.Select(well => { var wellMapInfo = well.Adapt(); - // From teltemetryTracker var wellLastTelemetryInfo = lastTelemetryInfo.FirstOrDefault(t => t.IdTelemetry == well.IdTelemetry); var wellOperationsStat = operationsStat.FirstOrDefault(s => s.Id == well.Id); @@ -138,7 +137,7 @@ namespace AsbCloudInfrastructure.Services wellMapInfo.SaubUsage = wellSubsystemStat?.SubsystemAKB?.KUsage ?? 0d; wellMapInfo.SpinUsage = wellSubsystemStat?.SubsystemSpinMaster?.KUsage ?? 0d; - wellMapInfo.TvdLagPercent = 0;// From WellOperationService? + wellMapInfo.TvdLagPercent = wellOperationsStat?.TvdLagDays ?? 0d; wellMapInfo.IdsCompanies = well.Companies.Select(c => c.Id); return wellMapInfo; }).ToArray(); diff --git a/AsbCloudInfrastructure/Services/WellOperationService/OperationsStatService.cs b/AsbCloudInfrastructure/Services/WellOperationService/OperationsStatService.cs index a360a014..f783967e 100644 --- a/AsbCloudInfrastructure/Services/WellOperationService/OperationsStatService.cs +++ b/AsbCloudInfrastructure/Services/WellOperationService/OperationsStatService.cs @@ -7,6 +7,7 @@ using Microsoft.Extensions.Caching.Memory; using System; using System.Collections.Generic; using System.Linq; +using System.Numerics; using System.Threading; using System.Threading.Tasks; @@ -158,10 +159,39 @@ namespace AsbCloudInfrastructure.Services.WellOperationService var timezoneOffsetH = wellService.GetTimezone(well.Id).Hours; statWellDto.Sections = CalcSectionsStats(wellOperations, timezoneOffsetH); statWellDto.Total = GetStatTotal(wellOperations, well.IdState, timezoneOffsetH); + statWellDto.TvdLagDays = CalcTvdLagDays(wellOperations); return statWellDto; } + private double CalcTvdLagDays(IOrderedEnumerable 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 0d; + + var lastFactOperation = factOperations.LastOrDefault(); + + var remainingPlanOperations = operationsOrdered + .Where(o => o.IdType == WellOperation.IdOperationTypePlan) + .Where(o => o.DateStart > lastCorrespondingFactOperation.OperationPlan.DateStart); + + var durationRemain = remainingPlanOperations.Sum(o => o.DurationHours); + var factEnd = lastFactOperation.DateStart.AddHours(durationRemain + lastFactOperation.DurationHours); + var planEnd = lastCorrespondingFactOperation.DateStart.AddHours(durationRemain + lastCorrespondingFactOperation.DurationHours); + var lagDays = (planEnd - factEnd).TotalDays; + + return lagDays; + } + private IEnumerable CalcSectionsStats(IEnumerable operations, double timezoneOffsetH) { var sectionTypeIds = operations