From 20d306a24c09df7e4d1ae3035bd1257a25df680f 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=20=D0=90=D0=BB=D0=B5=D0=BA?= =?UTF-8?q?=D1=81=D0=B0=D0=BD=D0=B4=D1=80=D0=BE=D0=B2=D0=B8=D1=87?= Date: Wed, 2 Aug 2023 11:34:42 +0500 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D1=80=D0=B0=D1=81=D1=81=D1=87=D1=91=D1=82=D0=B0?= =?UTF-8?q?=20=D0=BE=D1=82=D0=BA=D0=BB=D0=BE=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?=20=D0=BF=D0=BE=20=D0=A2=D0=92=D0=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudApp/Data/StatWellDto.cs | 4 +- AsbCloudApp/Data/WellMapInfoDto.cs | 5 +- AsbCloudApp/Data/WellOperationDto.cs | 5 ++ .../Services/WellInfoService.cs | 5 +- .../OperationsStatService.cs | 71 ++++++++++--------- 5 files changed, 48 insertions(+), 42 deletions(-) diff --git a/AsbCloudApp/Data/StatWellDto.cs b/AsbCloudApp/Data/StatWellDto.cs index 92df13ef..59ffd3d7 100644 --- a/AsbCloudApp/Data/StatWellDto.cs +++ b/AsbCloudApp/Data/StatWellDto.cs @@ -53,8 +53,8 @@ namespace AsbCloudApp.Data public IEnumerable Companies { get; set; } = Enumerable.Empty(); /// - /// Отставание от ГГД, дней + /// Отставание от ГГД, проценты /// - public double TvdLagDays { get; set; } = 0; + public double? TvdLagPercent { get; set; } } } diff --git a/AsbCloudApp/Data/WellMapInfoDto.cs b/AsbCloudApp/Data/WellMapInfoDto.cs index 42a48534..242ecb6c 100644 --- a/AsbCloudApp/Data/WellMapInfoDto.cs +++ b/AsbCloudApp/Data/WellMapInfoDto.cs @@ -95,9 +95,8 @@ namespace AsbCloudApp.Data public PlanFactDto WellDepth { get; set; } = null!; /// - /// Отставание от ГГД, дни + /// Отставание от ГГД, проценты /// - public double TvdLagDays { get; set; } - + public double TvdLagPercent { get; set; } } } diff --git a/AsbCloudApp/Data/WellOperationDto.cs b/AsbCloudApp/Data/WellOperationDto.cs index 31b50243..b3dc537c 100644 --- a/AsbCloudApp/Data/WellOperationDto.cs +++ b/AsbCloudApp/Data/WellOperationDto.cs @@ -89,6 +89,11 @@ namespace AsbCloudApp.Data [DateValidation(GtDate = "2010-01-01T00:00:00")] public DateTime DateStart { get; set; } + /// + /// Дата окончания операции + /// + public DateTime DateEnd => DateStart.AddHours(DurationHours); + /// /// Продолжительность, часы /// diff --git a/AsbCloudInfrastructure/Services/WellInfoService.cs b/AsbCloudInfrastructure/Services/WellInfoService.cs index 4f92afe9..7066ef22 100644 --- a/AsbCloudInfrastructure/Services/WellInfoService.cs +++ b/AsbCloudInfrastructure/Services/WellInfoService.cs @@ -138,8 +138,7 @@ namespace AsbCloudInfrastructure.Services wellMapInfo.FirstFactOperationDateStart = wellOperationsStat?.Total.Fact?.Start ?? wellOperationsStat?.Total.Plan?.Start; - wellMapInfo.LastPredictOperationDateEnd = wellOperationsStat?.Total.Plan?.End? - .AddDays(wellOperationsStat?.TvdLagDays ?? 0d); + wellMapInfo.LastPredictOperationDateEnd = wellOperationsStat?.Total.Plan?.End; wellMapInfo.WellDepth = new() { @@ -163,7 +162,7 @@ namespace AsbCloudInfrastructure.Services wellMapInfo.SaubUsage = wellSubsystemStat?.SubsystemAKB?.KUsage ?? 0d; wellMapInfo.SpinUsage = wellSubsystemStat?.SubsystemSpinMaster?.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); return wellMapInfo; diff --git a/AsbCloudInfrastructure/Services/WellOperationService/OperationsStatService.cs b/AsbCloudInfrastructure/Services/WellOperationService/OperationsStatService.cs index 2757dbfd..465f98f9 100644 --- a/AsbCloudInfrastructure/Services/WellOperationService/OperationsStatService.cs +++ b/AsbCloudInfrastructure/Services/WellOperationService/OperationsStatService.cs @@ -9,6 +9,8 @@ using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; +using AsbCloudApp.Data.SAUB; +using AsbCloudInfrastructure.Services.SAUB; namespace AsbCloudInfrastructure.Services.WellOperationService { @@ -18,13 +20,16 @@ namespace AsbCloudInfrastructure.Services.WellOperationService private readonly IAsbCloudDbContext db; private readonly IMemoryCache memoryCache; private readonly IWellService wellService; + private readonly TelemetryDataCache telemetryDataCache; - public OperationsStatService(IAsbCloudDbContext db, IMemoryCache memoryCache, IWellService wellService) + public OperationsStatService(IAsbCloudDbContext db, IMemoryCache memoryCache, IWellService wellService, + TelemetryDataCache telemetryDataCache) { this.db = db; this.memoryCache = memoryCache; this.wellService = wellService; - } + this.telemetryDataCache = telemetryDataCache; + } public async Task GetOrDefaultStatClusterAsync(int idCluster, int idCompany, CancellationToken token) { @@ -168,45 +173,43 @@ 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); + statWellDto.TvdLagPercent = CalcTvdLagPercent(well.IdTelemetry, wellOperations + .Select(x => x.Adapt())); return statWellDto; } - private static double CalcTvdLagDays(IOrderedEnumerable wellOperations) - { - var operationsOrdered = wellOperations - .OrderBy(o => o.DateStart); + private double? CalcTvdLagPercent(int? idTelemetry, IEnumerable wellOperations) + { + if (!idTelemetry.HasValue) + return null; - var factOperations = operationsOrdered - .Where(o => o.IdType == WellOperation.IdOperationTypeFact); + var currentDate = DateTime.UtcNow; - var lastCorrespondingFactOperation = factOperations - .LastOrDefault(o => o.IdPlan is not null); + var lastFactOperation = telemetryDataCache.GetLastOrDefault(idTelemetry.Value); + + wellOperations = wellOperations + .Where(o => o.IdType == WellOperation.IdOperationTypePlan) + .OrderBy(o => o.DateEnd); + + var wellOperationFrom = wellOperations + .LastOrDefault(o => o.DateEnd <= currentDate); + + var wellOperationTo = wellOperations + .FirstOrDefault(o => o.DateEnd >= currentDate); + + var wellOperationDepthFrom = wellOperationFrom?.DepthEnd; + var wellOperationDepthTo = wellOperationTo?.DepthStart ?? wellOperationDepthFrom; + + var wellOperationDateFrom = wellOperationFrom?.DateEnd; + var wellOperationDateTo = wellOperationTo?.DateStart ?? wellOperationDateFrom; - if (lastCorrespondingFactOperation is null) - return 0d; - - var lastCorrespondingPlanOperation = wellOperations - .FirstOrDefault(o => o.Id == lastCorrespondingFactOperation.IdPlan); + var planDepth = (wellOperationDateTo - wellOperationDateFrom)?.TotalHours * + (wellOperationDepthTo - wellOperationDepthFrom) / + (currentDate - wellOperationDateFrom)?.TotalHours + wellOperationDepthFrom; - if (lastCorrespondingPlanOperation is null) - return 0d; - - var lastFactOperation = factOperations.Last(); - - var remainingPlanOperations = operationsOrdered - .Where(o => o.IdType == WellOperation.IdOperationTypePlan) - .Where(o => o.DateStart > lastCorrespondingPlanOperation.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; - } + return (1 - lastFactOperation?.WellDepth / planDepth) * 100; + } private IEnumerable CalcSectionsStats(IEnumerable operations, double timezoneOffsetH) { @@ -544,4 +547,4 @@ namespace AsbCloudInfrastructure.Services.WellOperationService } } -} +} \ No newline at end of file