From efdcb4f211ea66e500980e48c6e4fcad9fde7ec8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A4=D1=80=D0=BE=D0=BB=D0=BE=D0=B2?= Date: Fri, 11 Mar 2022 16:53:31 +0500 Subject: [PATCH] Add nptDays to WellOperationService --- .../OperationsStatService.cs | 43 ++++++++----------- .../WellOperationService.cs | 21 +++++++++ 2 files changed, 38 insertions(+), 26 deletions(-) diff --git a/AsbCloudInfrastructure/Services/WellOperationService/OperationsStatService.cs b/AsbCloudInfrastructure/Services/WellOperationService/OperationsStatService.cs index c6a089ec..ad511ed3 100644 --- a/AsbCloudInfrastructure/Services/WellOperationService/OperationsStatService.cs +++ b/AsbCloudInfrastructure/Services/WellOperationService/OperationsStatService.cs @@ -20,15 +20,6 @@ namespace AsbCloudInfrastructure.Services.WellOperationService private readonly CacheTable cacheSectionsTypes; private readonly CacheTable cacheWellType; private readonly CacheTable cacheCluster; - private const int idOperationBhaAssembly = 1025; - private const int idOperationBhaDisassembly = 1026; - private const int idOperationNonProductiveTime = 1043; - private const int idOperationDrilling = 1001; - private const int idOperationBhaDown = 1046; - private const int idOperationBhaUp = 1047; - private const int idOperationCasingDown = 1048; - private const int idOperationTypePlan = 0; - private const int idOperationTypeFact = 1; public OperationsStatService(IAsbCloudDbContext db, CacheDb cache, IWellService wellService, ITelemetryService telemetryService) @@ -203,8 +194,8 @@ namespace AsbCloudInfrastructure.Services.WellOperationService .ToDictionary(s => s.Id); var sections = new List(sectionTypes.Count); - var operationsPlan = operations.Where(o => o.IdType == idOperationTypePlan); - var operationsFact = operations.Where(o => o.IdType == idOperationTypeFact); + var operationsPlan = operations.Where(o => o.IdType == WellOperationService.idOperationTypePlan); + var operationsFact = operations.Where(o => o.IdType == WellOperationService.idOperationTypeFact); foreach ((var id, var sectionType) in sectionTypes) { @@ -223,8 +214,8 @@ namespace AsbCloudInfrastructure.Services.WellOperationService private static PlanFactBase GetStatTotal(IEnumerable operations, int idWellState, double timezoneOffsetH) { - var operationsPlan = operations.Where(o => o.IdType == idOperationTypePlan); - var operationsFact = operations.Where(o => o.IdType == idOperationTypeFact); + var operationsPlan = operations.Where(o => o.IdType == WellOperationService.idOperationTypePlan); + var operationsFact = operations.Where(o => o.IdType == WellOperationService.idOperationTypeFact); var factEnd = CalcStat(operationsFact, timezoneOffsetH); if (factEnd is not null && idWellState != 2) factEnd.End = null; @@ -265,7 +256,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService BhaUpSpeed = CalcBhaUpSpeed(races), CasingDownSpeed = CalcCasingDownSpeed(operations), NonProductiveHours = operations - .Where(o => o.IdCategory == idOperationNonProductiveTime) + .Where(o => o.IdCategory == WellOperationService.idOperationNonProductiveTime) .Sum(o => o.DurationHours), }; return section; @@ -273,7 +264,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService private static double CalcROP(IEnumerable operationsProps) { - var drillingOperations = operationsProps.Where(o => o.IdCategory == idOperationDrilling); + var drillingOperations = operationsProps.Where(o => o.IdCategory == WellOperationService.idOperationDrilling); var dDepth = 0d; var dHours = 0d; foreach (var operation in drillingOperations) @@ -287,7 +278,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService private static double CalcCasingDownSpeed(IEnumerable operationsProps) { - var ops = operationsProps.Where(o => o.IdCategory == idOperationCasingDown); + var ops = operationsProps.Where(o => o.IdCategory == WellOperationService.idOperationCasingDown); var depth = 0d; var dHours = 0d; foreach (var operation in ops) @@ -306,7 +297,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService .GetEnumerator(); while (iterator.MoveNext()) { - if (iterator.Current.IdCategory == idOperationBhaAssembly) + if (iterator.Current.IdCategory == WellOperationService.idOperationBhaAssembly) { var race = new Race { @@ -316,11 +307,11 @@ namespace AsbCloudInfrastructure.Services.WellOperationService }; while (iterator.MoveNext()) { - if (iterator.Current.IdCategory == idOperationNonProductiveTime) + if (iterator.Current.IdCategory == WellOperationService.idOperationNonProductiveTime) { race.NonProductiveHours += iterator.Current.DurationHours; } - if (iterator.Current.IdCategory == idOperationBhaDisassembly) + if (iterator.Current.IdCategory == WellOperationService.idOperationBhaDisassembly) { race.EndDate = iterator.Current.DateStart.ToRemoteDateTime(timezoneOffsetH); race.EndWellDepth = iterator.Current.DepthStart; @@ -355,9 +346,9 @@ namespace AsbCloudInfrastructure.Services.WellOperationService dDepth += race.StartWellDepth; for (var i = 0; i < race.Operations.Count; i++) { - if (race.Operations[i].IdCategory == idOperationBhaDown) + if (race.Operations[i].IdCategory == WellOperationService.idOperationBhaDown) dHours += race.Operations[i].DurationHours; - if (race.Operations[i].IdCategory == idOperationDrilling) + if (race.Operations[i].IdCategory == WellOperationService.idOperationDrilling) break; } } @@ -373,9 +364,9 @@ namespace AsbCloudInfrastructure.Services.WellOperationService dDepth += race.EndWellDepth; for (var i = race.Operations.Count - 1; i > 0; i--) { - if (race.Operations[i].IdCategory == idOperationBhaUp) + if (race.Operations[i].IdCategory == WellOperationService.idOperationBhaUp) dHours += race.Operations[i].DurationHours; - if (race.Operations[i].IdCategory == idOperationDrilling) + if (race.Operations[i].IdCategory == WellOperationService.idOperationDrilling) break; } } @@ -395,12 +386,12 @@ namespace AsbCloudInfrastructure.Services.WellOperationService .ConfigureAwait(false); var wellOperationsPlan = wellOperations - .Where(o => o.IdType == idOperationTypePlan) + .Where(o => o.IdType == WellOperationService.idOperationTypePlan) .OrderBy(o => o.DateStart) .ThenBy(o => o.DepthEnd); var wellOperationsFact = wellOperations - .Where(o => o.IdType == idOperationTypeFact) + .Where(o => o.IdType == WellOperationService.idOperationTypeFact) .OrderBy(o => o.DateStart) .ThenBy(o => o.DepthEnd); @@ -424,7 +415,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService var plan = item.Item1; var fact = item.Item2; - if (fact?.IdCategory == idOperationNonProductiveTime) + if (fact?.IdCategory == WellOperationService.idOperationNonProductiveTime) { nptDays += fact.DurationHours; } diff --git a/AsbCloudInfrastructure/Services/WellOperationService/WellOperationService.cs b/AsbCloudInfrastructure/Services/WellOperationService/WellOperationService.cs index 6de4a701..72a13718 100644 --- a/AsbCloudInfrastructure/Services/WellOperationService/WellOperationService.cs +++ b/AsbCloudInfrastructure/Services/WellOperationService/WellOperationService.cs @@ -19,6 +19,16 @@ namespace AsbCloudInfrastructure.Services.WellOperationService private readonly CacheTable cachedOperationCategories; private readonly CacheTable cachedSectionTypes; + public const int idOperationBhaAssembly = 1025; + public const int idOperationBhaDisassembly = 1026; + public const int idOperationNonProductiveTime = 1043; + public const int idOperationDrilling = 1001; + public const int idOperationBhaDown = 1046; + public const int idOperationBhaUp = 1047; + public const int idOperationCasingDown = 1048; + public const int idOperationTypePlan = 0; + public const int idOperationTypeFact = 1; + public WellOperationService(IAsbCloudDbContext db, CacheDb cache, IWellService wellService) { this.db = db; @@ -59,6 +69,8 @@ namespace AsbCloudInfrastructure.Services.WellOperationService .Include(s => s.OperationCategory) .Where(s => s.IdWell == idWell); + var dateStart = query.Min(o => o.DateStart); + if (operationType != default) query = query.Where(e => e.IdType == (int)operationType); @@ -105,12 +117,21 @@ namespace AsbCloudInfrastructure.Services.WellOperationService var entities = await query.Take(take).AsNoTracking() .ToListAsync(token).ConfigureAwait(false); + var nptHours = 0d; + foreach (var entity in entities) { var dto = entity.Adapt(); + dto.Day = (entity.DateStart - dateStart).TotalDays; dto.WellSectionTypeName = entity.WellSectionType.Caption; dto.DateStart = entity.DateStart.ToRemoteDateTime(timezone.Hours); dto.CategoryName = entity.OperationCategory.Name; + if(entity.IdType == idOperationTypeFact) + { + if(entity.IdCategory == idOperationNonProductiveTime) + nptHours += entity.DurationHours; + dto.NptHours = nptHours; + } result.Items.Add(dto); }