From 3a978bddc57856073965eb323ef800b34d1f0dd6 Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Tue, 13 Feb 2024 17:29:20 +0500 Subject: [PATCH] draft 1 --- .../ProcessMapReportDataSaubStatService.cs | 66 ++++++++++--------- 1 file changed, 36 insertions(+), 30 deletions(-) diff --git a/AsbCloudInfrastructure/Services/ProcessMaps/Report/ProcessMapReportDataSaubStatService.cs b/AsbCloudInfrastructure/Services/ProcessMaps/Report/ProcessMapReportDataSaubStatService.cs index 35bf06a8..b25f2eb8 100644 --- a/AsbCloudInfrastructure/Services/ProcessMaps/Report/ProcessMapReportDataSaubStatService.cs +++ b/AsbCloudInfrastructure/Services/ProcessMaps/Report/ProcessMapReportDataSaubStatService.cs @@ -22,17 +22,20 @@ namespace AsbCloudInfrastructure.Services.ProcessMaps.Report private readonly IChangeLogRepository processMapPlanBaseRepository; private readonly IDataSaubStatRepository dataSaubStatRepository; private readonly IWellOperationRepository wellOperationRepository; + private readonly IWellOperationCategoryRepository wellOperationCategoryRepository; public ProcessMapReportDataSaubStatService(IWellService wellService, IChangeLogRepository processMapPlanBaseRepository, IDataSaubStatRepository dataSaubStatRepository, - IWellOperationRepository wellOperationRepository + IWellOperationRepository wellOperationRepository, + IWellOperationCategoryRepository wellOperationCategoryRepository ) { this.wellService = wellService; this.processMapPlanBaseRepository = processMapPlanBaseRepository; this.dataSaubStatRepository = dataSaubStatRepository; this.wellOperationRepository = wellOperationRepository; + this.wellOperationCategoryRepository = wellOperationCategoryRepository; } public async Task> GetAsync(int idWell, DataSaubStatRequest request, CancellationToken token) @@ -81,19 +84,37 @@ namespace AsbCloudInfrastructure.Services.ProcessMaps.Report DataSaubStatRequest request, IEnumerable processMapPlanWellDrillings, Span dataSaubStats, - IEnumerable wellOperations, - IEnumerable wellOperationCategories + IEnumerable wellOperations ) { var list = new List(); var firstElemInInterval = dataSaubStats[0]; + int GetSection(DataSaubStatDto data) + => wellOperations.MinBy(o => data.DateStart - o.DateStart)!.IdWellSectionType; + + ProcessMapPlanDrillingDto? GetProcessMapPlan(int idWellSectionType, DataSaubStatDto data) + => processMapPlanWellDrillings + .Where(p => p.IdWellSectionType == idWellSectionType) + .Where(p => p.DepthStart <= data.DepthStart) + .Where(p => p.DepthEnd >= data.DepthStart) + .Where(p => IsModeMatchOperationCategory(p.IdMode, data.IdCategory)) + .WhereActualAtMoment(data.DateStart) + .FirstOrDefault(); + + var idWellSectionType = GetSection(firstElemInInterval); + var prevProcessMapPlan = GetProcessMapPlan(idWellSectionType, firstElemInInterval); var indexStart = 0; + for (var i = 1; i < dataSaubStats.Length; i++) { var currentElem = dataSaubStats[i]; - if (IsNewInterval(currentElem, firstElemInInterval, request) || i == dataSaubStats.Length - 1) + idWellSectionType = GetSection(currentElem); + var processMapPlan = GetProcessMapPlan(idWellSectionType, currentElem); + + if (IsNewInterval(currentElem, firstElemInInterval, request) || i == dataSaubStats.Length - 1 || processMapPlan != prevProcessMapPlan) { + prevProcessMapPlan = processMapPlan; var length = i - indexStart; var span = dataSaubStats.Slice(indexStart, length); @@ -104,26 +125,7 @@ namespace AsbCloudInfrastructure.Services.ProcessMaps.Report var firstElemInSpan = span[0]; var lastElemInISpan = span[^1]; - var nearestOperation = wellOperations.MinBy(o => firstElemInSpan.DateStart - o.DateStart); - if (nearestOperation is null) - continue; - - var processMapPlanFilteredByDepth = processMapPlanWellDrillings - .Where(x => x.IdWellSectionType == nearestOperation.IdWellSectionType) - .Where(x => x.DepthStart >= firstElemInSpan.DepthStart) - .Where(x => x.DepthEnd <= lastElemInISpan.DepthEnd) - .WhereActualAtMoment(DateTimeOffset.Now) - .ToArray(); - - if (!processMapPlanFilteredByDepth.Any()) - continue; - - var wellOperationCategoryName = wellOperationCategories. - Where(c => c.Id == currentElem.IdCategory) - .FirstOrDefault() - ?.Name ?? string.Empty; - - var elem = CalcStat(processMapPlanFilteredByDepth, span, nearestOperation, wellOperationCategoryName); + var elem = CalcStat(processMapPlan, idWellSectionType, span); if (elem is not null) list.Add(elem); } @@ -131,11 +133,15 @@ namespace AsbCloudInfrastructure.Services.ProcessMaps.Report return list; } + private bool IsModeMatchOperationCategory(int idMode, int idCategory) + { + throw new NotImplementedException(); + } + private ProcessMapReportDataSaubStatDto? CalcStat( - ProcessMapPlanDrillingDto[] processMapPlanFilteredByDepth, - Span span, - WellOperationDto nearestOperation, - string wellOperationCategoryName + ProcessMapPlanDrillingDto? processMapPlanFilteredByDepth, + int idWellSectionType, + Span span ) { var firstElemInInterval = span[0]; @@ -149,7 +155,7 @@ namespace AsbCloudInfrastructure.Services.ProcessMaps.Report return new ProcessMapReportDataSaubStatDto() { DateStart = firstElemInInterval.DateStart.DateTime, - WellSectionTypeName = nearestOperation.WellSectionTypeName ?? string.Empty, + WellSectionTypeName = nearestOperation.WellSectionTypeName ?? string.Empty, DepthStart = firstElemInInterval.DepthStart, DepthEnd = lastElemInInterval.DepthEnd, DeltaDepth = deltaDepth, @@ -157,7 +163,7 @@ namespace AsbCloudInfrastructure.Services.ProcessMaps.Report DrillingMode = wellOperationCategoryName, PressureDiff = new ProcessMapReportDataSaubStatParamsDto() { - SetpointPlanMax = processMapPlanFilteredByDepth.Max(p => p.DeltaPressurePlan), + SetpointPlanMax = processMapPlanFilteredByDepth?.DeltaPressurePlan, SetpointPlanMin = processMapPlanFilteredByDepth.Min(p => p.DeltaPressurePlan), SetpointFact = firstElemInInterval.PressureSp - firstElemInInterval.PressureIdle, FactWavg = aggregatedValues.Pressure,