From 7231fad19e7a8dcd0c25af0c451e1f129980cc3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A4=D1=80=D0=BE=D0=BB=D0=BE=D0=B2?= Date: Thu, 26 Aug 2021 10:18:59 +0500 Subject: [PATCH] fixed calculations --- .../Services/WellOperationsStatService.cs | 175 +++++++++++------- 1 file changed, 106 insertions(+), 69 deletions(-) diff --git a/AsbCloudInfrastructure/Services/WellOperationsStatService.cs b/AsbCloudInfrastructure/Services/WellOperationsStatService.cs index 7db0bd6b..7a9eaca8 100644 --- a/AsbCloudInfrastructure/Services/WellOperationsStatService.cs +++ b/AsbCloudInfrastructure/Services/WellOperationsStatService.cs @@ -25,7 +25,7 @@ namespace AsbCloudInfrastructure.Services WellDepth = operation.WellDepth; DeltaDepth = 0; - DurationHours = operation.DurationHours; + Hours = operation.DurationHours; } public int IdWellSectionType { get; } public int IdCategory { get; } @@ -33,7 +33,7 @@ namespace AsbCloudInfrastructure.Services public DateTime Start { get; } public double WellDepth { get; set; } public double DeltaDepth { get; set; } - public double DurationHours { get; set; } + public double Hours { get; set; } } class Race @@ -47,6 +47,8 @@ namespace AsbCloudInfrastructure.Services public double DeltaDepth => EndWellDepth - StartWellDepth; public double DeltaHoursTimeNoNpt => (EndDate - StartDate).TotalHours - NonProductiveHours; public double Speed => DeltaDepth / (DeltaHoursTimeNoNpt + double.Epsilon); + + public List operations { get; internal set; } } public class WellOperationsStatService : IWellOperationsStatService @@ -132,8 +134,8 @@ namespace AsbCloudInfrastructure.Services Caption = well.Caption, WellType = wellType?.Caption, Companies = await wellService.GetCompaniesAsync(idWell, token), - Sections = CalcSectionsStats(operations), - Total = GetStat(operations), + Sections = CalcSectionsStats(wellOperations), + Total = GetStat(wellOperations), }; return statWellDto; } @@ -150,7 +152,7 @@ namespace AsbCloudInfrastructure.Services var sections = new List(sectionTypes.Count); var operationsPlan = MakeOperationsExt(operations.Where(o => o.IdType == 0)); - var operationsFact = MakeOperationsExt(operations.Where(o => o.IdType == 0)); + var operationsFact = MakeOperationsExt(operations.Where(o => o.IdType == 1)); foreach ((var id, var sectionType) in sectionTypes) { @@ -169,7 +171,7 @@ namespace AsbCloudInfrastructure.Services private static PlanFactBase GetStat(IEnumerable operations) { var operationsPlan = MakeOperationsExt(operations.Where(o => o.IdType == 0)); - var operationsFact = MakeOperationsExt(operations.Where(o => o.IdType == 0)); + var operationsFact = MakeOperationsExt(operations.Where(o => o.IdType == 1)); var section = new PlanFactBase { Plan = CalcStat(operationsPlan), @@ -189,41 +191,26 @@ namespace AsbCloudInfrastructure.Services private static StatOperationsDto CalcStat(IEnumerable operations) { + var races = GetCompleteRaces(operations); + var section = new StatOperationsDto { Start = operations.First().Start, - End = operations.Max(o => (o.Start.AddHours(o.DurationHours))), + End = operations.Max(o => (o.Start.AddHours(o.Hours))), WellDepthStart = operations.Min(o => o.WellDepth), WellDepthEnd = operations.Max(o => o.WellDepth), - RouteSpeed = CalcAvgRaceSpeed(operations), Rop = CalcROP(operations), - BhaDownSpeed = CalcSpeedByOperation(operations, idOperationBhaDown), - BhaUpSpeed = CalcSpeedByOperation(operations, idOperationBhaUp), - CasingDownSpeed = CalcSpeedByOperation(operations, IdOperationCasingDown), + RouteSpeed = CalcAvgRaceSpeed(races), + BhaDownSpeed = CalcBhaDownSpeed(races), + BhaUpSpeed = CalcBhaUpSpeed(races), + CasingDownSpeed = CalcCasingDownSpeed(operations), + NonProductiveHours = operations + .Where(o => o.IdCategory == idOperationNonProductiveTime) + .Sum(o => o.Hours), }; return section; } - // this will be deleted - private static double CalcSpeedByOperation(IEnumerable operationsProps, int idOperation) - { - var ops = operationsProps.Where(o => o.IdCategory == idOperation); - var maxDepth = 0d; - var dHours = 0d; - foreach (var operation in ops) - { - if (maxDepth < operation.WellDepth) - maxDepth = operation.WellDepth; - dHours += operation.DurationHours; - } - return maxDepth / (dHours + double.Epsilon); - } - - //private static double CalcBhaDownSpeed(IEnumerable operationsProps) - //{ - - //} - private static double CalcROP(IEnumerable operationsProps) { var drillingOperations = operationsProps.Where(o => o.IdCategory == idOperationDrilling); @@ -232,14 +219,62 @@ namespace AsbCloudInfrastructure.Services foreach (var operation in drillingOperations) { dDepth += operation.DeltaDepth; - dHours += operation.DurationHours; + dHours += operation.Hours; } return dDepth / (dHours + double.Epsilon); } - private static double CalcAvgRaceSpeed(IEnumerable operations) + private static double CalcCasingDownSpeed(IEnumerable operationsProps) + { + var ops = operationsProps.Where(o => o.IdCategory == IdOperationCasingDown); + var depth = 0d; + var dHours = 0d; + foreach (var operation in ops) + { + depth += operation.WellDepth; + dHours += operation.Hours; + } + return depth / (dHours + double.Epsilon); + } + + private static IEnumerable GetCompleteRaces(IEnumerable operations) + { + var races = new List(); + var iterator = operations + .OrderBy(o => o.Start) + .GetEnumerator(); + while (iterator.MoveNext()) + { + if (iterator.Current.IdCategory == idOperationBhaAssembly) + { + var race = new Race + { + StartDate = iterator.Current.Start.AddHours(iterator.Current.Hours), + StartWellDepth = iterator.Current.WellDepth, + operations = new List(4), + }; + while (iterator.MoveNext()) + { + if (iterator.Current.IdCategory == idOperationNonProductiveTime) + { + race.NonProductiveHours += iterator.Current.Hours; + } + if (iterator.Current.IdCategory == idOperationBhaDisassembly) + { + race.EndDate = iterator.Current.Start; + race.EndWellDepth = iterator.Current.WellDepth; + races.Add(race); + break; + } + race.operations.Add(iterator.Current); + } + } + } + return races; + } + + private static double CalcAvgRaceSpeed(IEnumerable races) { - var races = GetCompleteRaces(operations); var dDepth = 0d; var dHours = 0d; foreach (var race in races) @@ -250,6 +285,42 @@ namespace AsbCloudInfrastructure.Services return dDepth / (dHours + double.Epsilon); } + private static double CalcBhaDownSpeed(IEnumerable races) + { + var dDepth = 0d; + var dHours = 0d; + foreach (var race in races) + { + dDepth += race.StartWellDepth; + for (var i = 0; i < race.operations.Count; i++) + { + if (race.operations[i].IdCategory == idOperationBhaDown) + dHours += race.operations[i].Hours; + if (race.operations[i].IdCategory == idOperationDrilling) + break; + } + } + return dDepth / (dHours + double.Epsilon); + } + + private static double CalcBhaUpSpeed(IEnumerable races) + { + var dDepth = 0d; + var dHours = 0d; + foreach (var race in races) + { + dDepth += race.EndWellDepth; + for (var i = race.operations.Count -1; i > 0 ; i--) + { + if (race.operations[i].IdCategory == idOperationBhaUp) + dHours += race.operations[i].Hours; + if (race.operations[i].IdCategory == idOperationDrilling) + break; + } + } + return dDepth / (dHours + double.Epsilon); + } + private static IEnumerable MakeOperationsExt(IEnumerable operations) { var sortedOperations = operations.OrderBy(o => o.StartDate); @@ -265,46 +336,12 @@ namespace AsbCloudInfrastructure.Services current = new OperationParams(item){ WellDepth = Helper.Max(wellDepth, item.WellDepth) }; pre.DeltaDepth = current.WellDepth - wellDepth; wellDepth = current.WellDepth; - pre.DurationHours = (current.Start - pre.Start).TotalHours; + pre.Hours = (current.Start - pre.Start).TotalHours; ops.Add(pre); pre = current; } ops.Add(current); return ops; } - - private static IEnumerable GetCompleteRaces(IEnumerable operations) - { - var races = new List(); - var iterator = operations - .OrderBy(o => o.Start) - .GetEnumerator(); - while (iterator.MoveNext()) - { - if (iterator.Current.IdCategory == idOperationBhaAssembly) - { - var race = new Race - { - StartDate = iterator.Current.Start.AddHours(iterator.Current.DurationHours), - StartWellDepth = iterator.Current.WellDepth - }; - while (iterator.MoveNext()) - { - if (iterator.Current.IdCategory == idOperationNonProductiveTime) - { - race.NonProductiveHours += iterator.Current.DurationHours; - } - if (iterator.Current.IdCategory == idOperationBhaDisassembly) - { - race.EndDate = iterator.Current.Start; - race.EndWellDepth = iterator.Current.WellDepth; - races.Add(race); - break; - } - } - } - } - return races; - } } }