From 31fd4bda1a4ada8fd19823ded273e02ce293e24a Mon Sep 17 00:00:00 2001 From: KharchenkoVV Date: Mon, 23 Aug 2021 14:52:34 +0500 Subject: [PATCH] CS2-65: Fixed well section calculation --- AsbCloudDb/Model/AsbCloudDbContext.cs | 148 ++++++------ .../Services/WellSectionService.cs | 224 ++++++------------ 2 files changed, 149 insertions(+), 223 deletions(-) diff --git a/AsbCloudDb/Model/AsbCloudDbContext.cs b/AsbCloudDb/Model/AsbCloudDbContext.cs index 0f9ce0d1..7a2a15ba 100644 --- a/AsbCloudDb/Model/AsbCloudDbContext.cs +++ b/AsbCloudDb/Model/AsbCloudDbContext.cs @@ -399,47 +399,47 @@ namespace AsbCloudDb.Model DurationHours = 1.2}, new WellOperation{ Id = 2, IdWell = 1, IdWellSectionType = 2, IdCategory = 1001, IdType = 0, - WellDepth = 300, StartDate = DateTime.Now.AddHours(2.5), - DurationHours = 1.5}, + WellDepth = 210, StartDate = DateTime.Now.AddHours(2), + DurationHours = 1.2}, new WellOperation{ Id = 3, IdWell = 1, IdWellSectionType = 2, IdCategory = 1001, IdType = 1, - WellDepth = 210, StartDate = DateTime.Now.AddHours(1.5), + WellDepth = 200, StartDate = DateTime.Now.AddHours(1.5), DurationHours = 1}, new WellOperation{ Id = 4, IdWell = 1, IdWellSectionType = 2, IdCategory = 1001, IdType = 1, - WellDepth = 310, StartDate = DateTime.Now.AddHours(2), + WellDepth = 220, StartDate = DateTime.Now.AddHours(2), DurationHours = 1.5}, new WellOperation{ Id = 5, IdWell = 1, IdWellSectionType = 3, IdCategory = 1001, IdType = 0, - WellDepth = 200, StartDate = DateTime.Now.AddHours(1), + WellDepth = 300, StartDate = DateTime.Now.AddHours(1), DurationHours = 1.2}, new WellOperation{ Id = 6, IdWell = 1, IdWellSectionType = 3, IdCategory = 1001, IdType = 0, - WellDepth = 300, StartDate = DateTime.Now.AddHours(2.5), - DurationHours = 1.5}, + WellDepth = 310, StartDate = DateTime.Now.AddHours(2), + DurationHours = 1.2}, new WellOperation{ Id = 7, IdWell = 1, IdWellSectionType = 3, IdCategory = 1001, IdType = 1, - WellDepth = 210, StartDate = DateTime.Now.AddHours(1.5), + WellDepth = 300, StartDate = DateTime.Now.AddHours(1.5), DurationHours = 1}, new WellOperation{ Id = 8, IdWell = 1, IdWellSectionType = 3, IdCategory = 1001, IdType = 1, - WellDepth = 310, StartDate = DateTime.Now.AddHours(2), + WellDepth = 320, StartDate = DateTime.Now.AddHours(2), DurationHours = 1.5}, new WellOperation{ Id = 9, IdWell = 1, IdWellSectionType = 4, IdCategory = 1001, IdType = 0, - WellDepth = 500, StartDate = DateTime.Now.AddHours(1), + WellDepth = 400, StartDate = DateTime.Now.AddHours(1), DurationHours = 1.2}, new WellOperation{ Id = 10, IdWell = 1, IdWellSectionType = 4, IdCategory = 1001, IdType = 0, - WellDepth = 510, StartDate = DateTime.Now.AddHours(2), + WellDepth = 420, StartDate = DateTime.Now.AddHours(2), DurationHours = 1.2}, new WellOperation{ Id = 11, IdWell = 1, IdWellSectionType = 4, IdCategory = 1001, IdType = 1, - WellDepth = 510, StartDate = DateTime.Now.AddHours(1.5), + WellDepth = 410, StartDate = DateTime.Now.AddHours(1.5), DurationHours = 1}, new WellOperation{ Id = 12, IdWell = 1, IdWellSectionType = 4, IdCategory = 1001, IdType = 1, - WellDepth = 520, StartDate = DateTime.Now.AddHours(2), + WellDepth = 420, StartDate = DateTime.Now.AddHours(2), DurationHours = 1.5}, @@ -457,144 +457,140 @@ namespace AsbCloudDb.Model DurationHours = 15.2}, new WellOperation{ Id = 16, IdWell = 1, IdWellSectionType = 2, IdCategory = 1046, IdType = 1, - WellDepth = 230, StartDate = DateTime.Now.AddHours(3.1), + WellDepth = 220, StartDate = DateTime.Now.AddHours(3.1), DurationHours = 17.8}, new WellOperation{ Id = 17, IdWell = 1, IdWellSectionType = 3, IdCategory = 1046, IdType = 0, - WellDepth = 200, StartDate = DateTime.Now.AddHours(2.5), - DurationHours = 15.5}, + WellDepth = 300, StartDate = DateTime.Now.AddHours(2.5), + DurationHours = 16.2}, new WellOperation{ Id = 18, IdWell = 1, IdWellSectionType = 3, IdCategory = 1046, IdType = 0, - WellDepth = 210, StartDate = DateTime.Now.AddHours(3), + WellDepth = 320, StartDate = DateTime.Now.AddHours(3.5), DurationHours = 17.2}, new WellOperation{ Id = 19, IdWell = 1, IdWellSectionType = 3, IdCategory = 1046, IdType = 1, - WellDepth = 220, StartDate = DateTime.Now.AddHours(2.7), + WellDepth = 315, StartDate = DateTime.Now.AddHours(2.7), DurationHours = 15.2}, new WellOperation{ Id = 20, IdWell = 1, IdWellSectionType = 3, IdCategory = 1046, IdType = 1, - WellDepth = 230, StartDate = DateTime.Now.AddHours(3.1), - DurationHours = 17.8}, + WellDepth = 320, StartDate = DateTime.Now.AddHours(3), + DurationHours = 18.2}, new WellOperation{ Id = 21, IdWell = 1, IdWellSectionType = 4, IdCategory = 1046, IdType = 0, - WellDepth = 700, StartDate = DateTime.Now.AddHours(2.5), + WellDepth = 410, StartDate = DateTime.Now.AddHours(2.5), DurationHours = 16.2}, new WellOperation{ Id = 22, IdWell = 1, IdWellSectionType = 4, IdCategory = 1046, IdType = 0, - WellDepth = 720, StartDate = DateTime.Now.AddHours(3.5), + WellDepth = 420, StartDate = DateTime.Now.AddHours(3.5), DurationHours = 17.2}, new WellOperation{ Id = 23, IdWell = 1, IdWellSectionType = 4, IdCategory = 1046, IdType = 1, - WellDepth = 715, StartDate = DateTime.Now.AddHours(2.7), + WellDepth = 415, StartDate = DateTime.Now.AddHours(2.7), DurationHours = 15.2}, new WellOperation{ Id = 24, IdWell = 1, IdWellSectionType = 4, IdCategory = 1046, IdType = 1, - WellDepth = 720, StartDate = DateTime.Now.AddHours(3), + WellDepth = 420, StartDate = DateTime.Now.AddHours(3), DurationHours = 18.2}, new WellOperation{ Id = 25, IdWell = 1, IdWellSectionType = 2, IdCategory = 1047, IdType = 0, - WellDepth = 600, StartDate = DateTime.Now.AddHours(4), - DurationHours = 5}, + WellDepth = 200, StartDate = DateTime.Now.AddHours(5.25), + DurationHours = 2.1}, new WellOperation{ Id = 26, IdWell = 1, IdWellSectionType = 2, IdCategory = 1047, IdType = 0, - WellDepth = 650, StartDate = DateTime.Now.AddHours(4.5), - DurationHours = 5.5}, + WellDepth = 220, StartDate = DateTime.Now.AddHours(7.5), + DurationHours = 2}, new WellOperation{ Id = 27, IdWell = 1, IdWellSectionType = 2, IdCategory = 1047, IdType = 1, - WellDepth = 700, StartDate = DateTime.Now.AddHours(5.5), - DurationHours = 8}, + WellDepth = 200, StartDate = DateTime.Now.AddHours(5.15), + DurationHours = 2.75}, new WellOperation{ Id = 28, IdWell = 1, IdWellSectionType = 2, IdCategory = 1047, IdType = 1, - WellDepth = 710, StartDate = DateTime.Now.AddHours(5.7), - DurationHours = 7.2}, + WellDepth = 250, StartDate = DateTime.Now.AddHours(6.5), + DurationHours = 3.5}, new WellOperation{ Id = 29, IdWell = 1, IdWellSectionType = 3, IdCategory = 1047, IdType = 0, - WellDepth = 600, StartDate = DateTime.Now.AddHours(4), - DurationHours = 5}, + WellDepth = 300, StartDate = DateTime.Now.AddHours(5.25), + DurationHours = 2.1}, new WellOperation{ Id = 30, IdWell = 1, IdWellSectionType = 3, IdCategory = 1047, IdType = 0, - WellDepth = 650, StartDate = DateTime.Now.AddHours(4.5), - DurationHours = 5.5}, + WellDepth = 310, StartDate = DateTime.Now.AddHours(7.5), + DurationHours = 2}, new WellOperation{ Id = 31, IdWell = 1, IdWellSectionType = 3, IdCategory = 1047, IdType = 1, - WellDepth = 700, StartDate = DateTime.Now.AddHours(5.5), - DurationHours = 8}, + WellDepth = 300, StartDate = DateTime.Now.AddHours(5.15), + DurationHours = 2.75}, new WellOperation{ Id = 32, IdWell = 1, IdWellSectionType = 3, IdCategory = 1047, IdType = 1, - WellDepth = 710, StartDate = DateTime.Now.AddHours(5.7), - DurationHours = 7.2}, + WellDepth = 330, StartDate = DateTime.Now.AddHours(6.5), + DurationHours = 3.5}, new WellOperation{ Id = 33, IdWell = 1, IdWellSectionType = 4, IdCategory = 1047, IdType = 0, - WellDepth = 1000, StartDate = DateTime.Now.AddHours(5.25), + WellDepth = 400, StartDate = DateTime.Now.AddHours(5.25), DurationHours = 2.1}, new WellOperation{ Id = 34, IdWell = 1, IdWellSectionType = 4, IdCategory = 1047, IdType = 0, - WellDepth = 1100, StartDate = DateTime.Now.AddHours(7.5), + WellDepth = 410, StartDate = DateTime.Now.AddHours(7.5), DurationHours = 2}, new WellOperation{ Id = 35, IdWell = 1, IdWellSectionType = 4, IdCategory = 1047, IdType = 1, - WellDepth = 1000, StartDate = DateTime.Now.AddHours(5.15), + WellDepth = 400, StartDate = DateTime.Now.AddHours(5.15), DurationHours = 2.75}, new WellOperation{ Id = 36, IdWell = 1, IdWellSectionType = 4, IdCategory = 1047, IdType = 1, - WellDepth = 1250, StartDate = DateTime.Now.AddHours(6.5), + WellDepth = 420, StartDate = DateTime.Now.AddHours(6.5), DurationHours = 3.5}, - new WellOperation{ Id = 37, IdWell = 1, IdWellSectionType = 2, + new WellOperation{ Id = 41, IdWell = 1, IdWellSectionType = 2, IdCategory = 1048, IdType = 0, - WellDepth = 600, StartDate = DateTime.Now.AddHours(4), - DurationHours = 5}, - new WellOperation{ Id = 38, IdWell = 1, IdWellSectionType = 2, + WellDepth = 210, StartDate = DateTime.Now.AddHours(5), + DurationHours = 2}, + new WellOperation{ Id = 42, IdWell = 1, IdWellSectionType = 2, IdCategory = 1048, IdType = 0, - WellDepth = 650, StartDate = DateTime.Now.AddHours(4.2), - DurationHours = 5.5}, - new WellOperation{ Id = 39, IdWell = 1, IdWellSectionType = 2, + WellDepth = 250, StartDate = DateTime.Now.AddHours(7.5), + DurationHours = 2}, + new WellOperation{ Id = 43, IdWell = 1, IdWellSectionType = 2, IdCategory = 1048, IdType = 1, - WellDepth = 700, StartDate = DateTime.Now.AddHours(5.5), - DurationHours = 7}, - new WellOperation{ Id = 40, IdWell = 1, IdWellSectionType = 2, + WellDepth = 210, StartDate = DateTime.Now.AddHours(5), + DurationHours = 2.5}, + new WellOperation{ Id = 44, IdWell = 1, IdWellSectionType = 2, IdCategory = 1048, IdType = 1, - WellDepth = 710, StartDate = DateTime.Now.AddHours(5.7), - DurationHours = 7.5}, - new WellOperation{ Id = 41, IdWell = 1, IdWellSectionType = 3, + WellDepth = 220, StartDate = DateTime.Now.AddHours(6.5), + DurationHours = 2.5}, + new WellOperation{ Id = 45, IdWell = 1, IdWellSectionType = 3, IdCategory = 1048, IdType = 0, - WellDepth = 600, StartDate = DateTime.Now.AddHours(4), - DurationHours = 5}, - new WellOperation{ Id = 42, IdWell = 1, IdWellSectionType = 3, + WellDepth = 310, StartDate = DateTime.Now.AddHours(5), + DurationHours = 2}, + new WellOperation{ Id = 46, IdWell = 1, IdWellSectionType = 3, IdCategory = 1048, IdType = 0, - WellDepth = 650, StartDate = DateTime.Now.AddHours(4.2), - DurationHours = 5.5}, - new WellOperation{ Id = 43, IdWell = 1, IdWellSectionType = 3, + WellDepth = 350, StartDate = DateTime.Now.AddHours(7.5), + DurationHours = 2}, + new WellOperation{ Id = 47, IdWell = 1, IdWellSectionType = 3, IdCategory = 1048, IdType = 1, - WellDepth = 700, StartDate = DateTime.Now.AddHours(5.5), - DurationHours = 7}, - new WellOperation{ Id = 44, IdWell = 1, IdWellSectionType = 3, - IdCategory = 1048, IdType = 1, - WellDepth = 710, StartDate = DateTime.Now.AddHours(5.7), - DurationHours = 7.5}, + WellDepth = 300, StartDate = DateTime.Now.AddHours(5), + DurationHours = 2.5}, new WellOperation{ Id = 48, IdWell = 1, IdWellSectionType = 3, - IdCategory = 1048, IdType = 0, - WellDepth = 910, StartDate = DateTime.Now.AddHours(5), - DurationHours = 12}, + IdCategory = 1048, IdType = 1, + WellDepth = 310, StartDate = DateTime.Now.AddHours(6.5), + DurationHours = 2.5}, new WellOperation{ Id = 49, IdWell = 1, IdWellSectionType = 4, IdCategory = 1048, IdType = 0, - WellDepth = 910, StartDate = DateTime.Now.AddHours(5), + WellDepth = 410, StartDate = DateTime.Now.AddHours(5), DurationHours = 2}, new WellOperation{ Id = 50, IdWell = 1, IdWellSectionType = 4, IdCategory = 1048, IdType = 0, - WellDepth = 950, StartDate = DateTime.Now.AddHours(7.5), + WellDepth = 450, StartDate = DateTime.Now.AddHours(7.5), DurationHours = 2}, new WellOperation{ Id = 51, IdWell = 1, IdWellSectionType = 4, IdCategory = 1048, IdType = 1, - WellDepth = 980, StartDate = DateTime.Now.AddHours(5), + WellDepth = 400, StartDate = DateTime.Now.AddHours(5), DurationHours = 2.5}, new WellOperation{ Id = 52, IdWell = 1, IdWellSectionType = 4, IdCategory = 1048, IdType = 1, - WellDepth = 1010, StartDate = DateTime.Now.AddHours(6.5), + WellDepth = 410, StartDate = DateTime.Now.AddHours(6.5), DurationHours = 2.5}, }); diff --git a/AsbCloudInfrastructure/Services/WellSectionService.cs b/AsbCloudInfrastructure/Services/WellSectionService.cs index e7aa43c2..a3a26a06 100644 --- a/AsbCloudInfrastructure/Services/WellSectionService.cs +++ b/AsbCloudInfrastructure/Services/WellSectionService.cs @@ -51,19 +51,33 @@ namespace AsbCloudInfrastructure.Services wellOperationsGroupedBySections.Add(groupedWellOperationsClone.First()); - var depthsPlanFactList = GetWellDepthPlanFact(wellOperationsGroupedBySections).ToList(); + var depthsPlanList = GetWellDepthStats(wellOperationsGroupedBySections, 0).ToList(); - var durationsPlanFactList = GetWellDurationPlanFact(wellOperationsGroupedBySections).ToList(); + var depthsFactList = GetWellDepthStats(wellOperationsGroupedBySections, 1).ToList(); - var mechSpeedsList = GetWellMechSpeedPlanFact(wellOperationsGroupedBySections).ToList(); + var durationsPlanList = GetWellDurationStats(wellOperationsGroupedBySections, 0).ToList(); - var bhaUpSpeedList = GetWellBhaUpSpeedPlanFact(wellOperationsGroupedBySections).ToList(); + var durationsFactList = GetWellDurationStats(wellOperationsGroupedBySections, 1).ToList(); - var bhaDownSpeedList = GetWellBhaDownSpeedPlanFact(wellOperationsGroupedBySections).ToList(); + var mechSpeedsPlanList = GetWellStats(wellOperationsGroupedBySections, 1001, 0).ToList(); - var casingDownList = GetWellCasingDownPlanFact(wellOperationsGroupedBySections).ToList(); + var mechSpeedsFactList = GetWellStats(wellOperationsGroupedBySections, 1001, 1).ToList(); - var routeSpeeds = GetWellRouteSpeedsPlanFact(wellOperationsGroupedBySections).ToList(); + var bhaUpSpeedPlanList = GetWellStats(wellOperationsGroupedBySections, 1046, 0).ToList(); + + var bhaUpSpeedFactList = GetWellStats(wellOperationsGroupedBySections, 1046, 1).ToList(); + + var bhaDownSpeedPlanList = GetWellStats(wellOperationsGroupedBySections, 1047, 0).ToList(); + + var bhaDownSpeedFactList = GetWellStats(wellOperationsGroupedBySections, 1047, 1).ToList(); + + var casingDownPlanList = GetWellStats(wellOperationsGroupedBySections, 1048, 0).ToList(); + + var casingDownFactList = GetWellStats(wellOperationsGroupedBySections, 1048, 1).ToList(); + + var routeSpeedsPlan = GetWellRouteSpeedStats(wellOperationsGroupedBySections, 0).ToList(); + + var routeSpeedsFact = GetWellRouteSpeedStats(wellOperationsGroupedBySections, 1).ToList(); var dtos = new List(); @@ -73,20 +87,20 @@ namespace AsbCloudInfrastructure.Services { SectionType = wellOperationsGroupedBySections[i] .FirstOrDefault().WellSectionType.Caption, - WellDepthPlan = depthsPlanFactList[i].DepthPlan, - WellDepthFact = depthsPlanFactList[i].DepthFact, - DurationPlan = durationsPlanFactList[i].DurationPlan, - DurationFact = durationsPlanFactList[i].DurationFact, - MechSpeedPlan = mechSpeedsList[i].MechSpeedPlan, - MechSpeedFact = mechSpeedsList[i].MechSpeedFact, - BhaUpSpeedPlan = bhaUpSpeedList[i].BhaUpSpeedPlan, - BhaUpSpeedFact = bhaUpSpeedList[i].BhaUpSpeedFact, - BhaDownSpeedPlan = bhaDownSpeedList[i].BhaDownSpeedPlan, - BhaDownSpeedFact = bhaDownSpeedList[i].BhaDownSpeedFact, - CasingDownSpeedPlan = casingDownList[i].CasingDownSpeedPlan, - CasingDownSpeedFact = casingDownList[i].CasingDownSpeedFact, - RouteSpeedPlan = routeSpeeds[i].RouteSpeedPlan, - RouteSpeedFact = routeSpeeds[i].RouteSpeedFact + WellDepthPlan = depthsPlanList[i], + WellDepthFact = depthsFactList[i], + DurationPlan = durationsPlanList[i], + DurationFact = durationsFactList[i], + MechSpeedPlan = mechSpeedsPlanList[i], + MechSpeedFact = mechSpeedsFactList[i], + BhaUpSpeedPlan = bhaUpSpeedPlanList[i], + BhaUpSpeedFact = bhaUpSpeedFactList[i], + BhaDownSpeedPlan = bhaDownSpeedPlanList[i], + BhaDownSpeedFact = bhaDownSpeedFactList[i], + CasingDownSpeedPlan = casingDownPlanList[i], + CasingDownSpeedFact = casingDownFactList[i], + RouteSpeedPlan = routeSpeedsPlan[i], + RouteSpeedFact = routeSpeedsFact[i] }; dtos.Add(dto); @@ -110,166 +124,82 @@ namespace AsbCloudInfrastructure.Services return dto; } - private static PaginationContainer PaginateData(IEnumerable> groupedCollection, - int skip, int take) + private static IEnumerable GetWellDepthStats( + IEnumerable> groupedOperations, int type) { - if (skip > 0) - groupedCollection = groupedCollection.Skip(skip).ToList(); - - groupedCollection = groupedCollection.Take(take).ToList(); - - var result = new PaginationContainer - { - Skip = skip, - Take = take, - Count = groupedCollection.Count() - }; - - return result; + return groupedOperations.Select(group => group.Where(o => o.IdType == type) + .DefaultIfEmpty().Max(w => w?.WellDepth ?? 0.0)); } + - private static IEnumerable<(double DepthPlan, double DepthFact)> GetWellDepthPlanFact( - IEnumerable> groupedOperations) - { - return groupedOperations - .Select(group => - ( - DepthPlan: group.Where(o => o.IdType == 0).Max(w => w.WellDepth), - DepthFact: group.Where(o => o.IdType == 1).Max(w => w.WellDepth) - )); - } - - private static IEnumerable<(double DurationPlan, double DurationFact)> GetWellDurationPlanFact( - IEnumerable> groupedOperations) + private static IEnumerable GetWellDurationStats( + IEnumerable> groupedOperations, int type) { var durationsPlanFactsBase = groupedOperations.Select(group => new { - DurationMaxPlan = group.Where(o => o.IdType == 0).Select(op => op.StartDate + - TimeSpan.FromHours(op.DurationHours)).Max(), + DurationMax = group.Where(o => o.IdType == type).DefaultIfEmpty() + .Max(op => op?.StartDate + TimeSpan.FromHours(op?.DurationHours ?? 0)) ?? default, - DurationMinPlan = group.Where(o => o.IdType == 0).Min(i => i.StartDate), - - DurationMaxFact = group.Where(o => o.IdType == 1).Select(op => op.StartDate + - TimeSpan.FromHours(op.DurationHours)).Max(), - - DurationMinFact = group.Where(o => o.IdType == 1).Min(i => i.StartDate) + DurationMin = group.Where(o => o.IdType == type).DefaultIfEmpty() + .Min(op => op?.StartDate) ?? default }); return durationsPlanFactsBase.Select(o => - ( - DurationPlan: (o.DurationMaxPlan - o.DurationMinPlan).TotalHours, - DurationFact: (o.DurationMaxFact - o.DurationMinFact).TotalHours - )); + (o.DurationMax - o.DurationMin).TotalHours); } - private static IEnumerable<(double MechSpeedPlan, double MechSpeedFact)> GetWellMechSpeedPlanFact( - IEnumerable> groupedOperations) + private static IEnumerable GetWellStats( + IEnumerable> groupedOperations, int idCategory, int type) { - var mechSpeedBase = GetParams(groupedOperations, 1001); + var mechSpeedBase = groupedOperations.Select(g => + ( + DepthDifferenceSum: g.Where(o => o.IdType == type && o.IdCategory == idCategory) + .Select((el, i) => i > 0 ? el.WellDepth - g.ElementAt(i - 1).WellDepth : 0).Sum(), + DurationDifferenceSum: g.Where(o => o.IdType == type && o.IdCategory == idCategory) + .Select(el => el.DurationHours).Sum() + )); return CalculateResult(mechSpeedBase); } - private static IEnumerable<(double BhaDownSpeedPlan, double BhaDownSpeedFact)> GetWellBhaDownSpeedPlanFact( - IEnumerable> groupedOperations) + private static IEnumerable GetWellRouteSpeedStats( + IEnumerable> groupedOperations, int type) { - var bhaDownSpeedBase = GetParams(groupedOperations, 1046); - - return CalculateResult(bhaDownSpeedBase); - } - - private static IEnumerable<(double BhaUpSpeedPlan, double BhaUpSpeedFact)> GetWellBhaUpSpeedPlanFact( - IEnumerable> groupedOperations) - { - var bhaUpSpeedBase = GetParams(groupedOperations, 1047); - - return CalculateResult(bhaUpSpeedBase); - } - - private static IEnumerable<(double CasingDownSpeedPlan, double CasingDownSpeedFact)> GetWellCasingDownPlanFact( - IEnumerable> groupedOperations) - { - var casingDownBase = GetParams(groupedOperations, 1048); - - return CalculateResult(casingDownBase); - } - - private static IEnumerable<(double RouteSpeedPlan, double RouteSpeedFact)> GetWellRouteSpeedsPlanFact( - IEnumerable> groupedOperations) - { - var bhaRaiseDecreaseCollection = new List<(WellOperation FirstBhaPositionDecreasePlan, - WellOperation LastBhaPositionIncreasePlan, - WellOperation FirstBhaPositionDecreaseFact, - WellOperation LastBhaPositionIncreaseFact)>(); + var bhaRaiseDecreaseCollection = new List<(WellOperation FirstBhaPositionDecrease, + WellOperation LastBhaPositionIncrease)>(); foreach (var group in groupedOperations) { - var firstBhaPositionDecreasePlan = group.Any(o => o.IdCategory == 1046 && o.IdType == 0) - ? group.First(o => o.IdCategory == 1046 && o.IdType == 0) - : null; + var firstBhaPositionDecrease = group.Any(o => o.IdCategory == 1046 && o.IdType == type) + ? group.First(o => o.IdCategory == 1046 && o.IdType == type) + : null; - var lastBhaPositionIncreasePlan = group.Any(o => o.IdCategory == 1047 && o.IdType == 0) - ? group.Last(o => o.IdCategory == 1047 && o.IdType == 0) - : null; + var lastBhaPositionIncrease = group.Any(o => o.IdCategory == 1047 && o.IdType == type) + ? group.Last(o => o.IdCategory == 1047 && o.IdType == type) + : null; - var firstBhaPositionDecreaseFact = group.Any(o => o.IdCategory == 1046 && o.IdType == 1) - ? group.First(o => o.IdCategory == 1046 && o.IdType == 1) - : null; - - var lastBhaPositionIncreaseFact = group.Any(o => o.IdCategory == 1047 && o.IdType == 1) - ? group.Last(o => o.IdCategory == 1047 && o.IdType == 1) - : null; - - bhaRaiseDecreaseCollection.Add((firstBhaPositionDecreasePlan, - lastBhaPositionIncreasePlan, firstBhaPositionDecreaseFact, - lastBhaPositionIncreaseFact)); + bhaRaiseDecreaseCollection.Add((firstBhaPositionDecrease, lastBhaPositionIncrease)); } var routeSpeedsBase = bhaRaiseDecreaseCollection.Select(el => ( - RouteDepthPlan: (el.LastBhaPositionIncreasePlan?.WellDepth - el.FirstBhaPositionDecreasePlan?.WellDepth) ?? 0, - RouteDepthFact: (el.LastBhaPositionIncreaseFact?.WellDepth - el.FirstBhaPositionDecreaseFact?.WellDepth) ?? 0, - RouteDurationPlan: (el.LastBhaPositionIncreasePlan?.StartDate + - TimeSpan.FromHours(el.LastBhaPositionIncreasePlan?.DurationHours ?? 0) - - el.FirstBhaPositionDecreasePlan?.StartDate)?.TotalHours ?? 0, - RouteDurationFact: (el.LastBhaPositionIncreaseFact?.StartDate + - TimeSpan.FromHours(el.LastBhaPositionIncreaseFact?.DurationHours ?? 0) - - el.FirstBhaPositionDecreaseFact?.StartDate)?.TotalHours ?? 0 + RouteDepth: (el.LastBhaPositionIncrease?.WellDepth - el.FirstBhaPositionDecrease?.WellDepth) ?? 0, + RouteDuration: (el.LastBhaPositionIncrease?.StartDate + + TimeSpan.FromHours(el.LastBhaPositionIncrease?.DurationHours ?? 0) - + el.FirstBhaPositionDecrease?.StartDate)?.TotalHours ?? 0 )); return CalculateResult(routeSpeedsBase); } - private static IEnumerable<(double DepthDifferencePlanSum, - double DurationDifferencePlanSum, double DepthDifferenceFactSum, - double DurationDifferenceFactSum)> GetParams(IEnumerable> items, - int IdCategory) - { - return items.Select(g => - ( - DepthDifferencePlanSum: g.Where(o => o.IdType == 0 && o.IdCategory == IdCategory) - .Select((el, i) => i > 0 ? el.WellDepth - g.ElementAt(i - 1).WellDepth : 0).Sum(), - DurationDifferencePlanSum: g.Where(o => o.IdType == 0 && o.IdCategory == IdCategory) - .Select(el => el.DurationHours).Sum(), - DepthDifferenceFactSum: g.Where(o => o.IdType == 1 && o.IdCategory == IdCategory) - .Select((el, i) => i > 0 ? el.WellDepth - g.ElementAt(i - 1).WellDepth : 0).Sum(), - DurationDifferenceFactSum: g.Where(o => o.IdType == 1 && o.IdCategory == IdCategory) - .Select(el => el.DurationHours).Sum() - )); - } - - private static IEnumerable<(double DataPlan, double DataFact)> CalculateResult(IEnumerable<(double Item1Plan, - double Item1Fact, double Item2Plan, double Item2Fact)> rawData) + private static IEnumerable CalculateResult(IEnumerable<(double, + double)> rawData) { return rawData.Select(el => - ( - RouteSpeedPlan: (el.Item1Plan / el.Item2Plan) is double.NaN - ? 0 - : (el.Item1Plan / el.Item2Plan), - RouteSpeedFact: (el.Item1Fact / el.Item2Fact) is double.NaN - ? 0 - : (el.Item1Fact / el.Item2Fact) - )); + (el.Item1 / el.Item2) is double.NaN + ? 0 + : (el.Item1 / el.Item2) + ); } private async Task GetWellSectionTypeFromCacheAndAssertAsync(string wellSectionType, CancellationToken token = default)