From 8bcaf18cb10bb90417e776320c4d35fdd94a513b Mon Sep 17 00:00:00 2001 From: KharchenkoVV Date: Wed, 18 Aug 2021 16:27:18 +0500 Subject: [PATCH] Fixed WellSection service --- .../Services/WellSectionService.cs | 66 ++++++++----------- 1 file changed, 29 insertions(+), 37 deletions(-) diff --git a/AsbCloudInfrastructure/Services/WellSectionService.cs b/AsbCloudInfrastructure/Services/WellSectionService.cs index d3d1da8b..937029fa 100644 --- a/AsbCloudInfrastructure/Services/WellSectionService.cs +++ b/AsbCloudInfrastructure/Services/WellSectionService.cs @@ -215,29 +215,19 @@ namespace AsbCloudInfrastructure.Services private static IEnumerable<(double MechSpeedPlan, double MechSpeedFact)> GetWellMechSpeedPlanFact( IEnumerable> groupedOperations) { - var mechSpeedBase = groupedOperations.Select(g => new - { - DepthChangePlanSum = g.Where(o => o.Type == 0 && o.IdOperationCategory == 1) - .Select((el, i) => i > 0 ? el.WellDepth - g.ElementAt(i - 1).WellDepth : 0).Sum(), - DurationsPlanSum = g.Where(o => o.Type == 0 && o.IdOperationCategory == 1) - .Select(el => el.DurationHours).Sum(), - DepthChangeFactSum = g.Where(o => o.Type == 1 && o.IdOperationCategory == 1) - .Select((el, i) => i > 0 ? el.WellDepth - g.ElementAt(i - 1).WellDepth : 0).Sum(), - DurationsFactSum = g.Where(o => o.Type == 1 && o.IdOperationCategory == 1) - .Select(el => el.DurationHours).Sum() - }); + var mechSpeedBase = GetParams(groupedOperations, 18); return mechSpeedBase.Select(el => ( - MechSpeedPlan: el.DepthChangePlanSum / el.DurationsPlanSum, - MechSpeedFact: el.DepthChangeFactSum / el.DurationsFactSum + MechSpeedPlan: el.DepthDifferencePlanSum / el.DurationDifferencePlanSum, + MechSpeedFact: el.DepthDifferenceFactSum / el.DurationDifferenceFactSum )); } private static IEnumerable<(double BhaUpSpeedPlan, double BhaUpSpeedFact)> GetWellBhaUpSpeedPlanFact( IEnumerable> groupedOperations) { - var bhaUpSpeedBase = GetParams(groupedOperations, 2); + var bhaUpSpeedBase = GetParams(groupedOperations, 72); return bhaUpSpeedBase.Select(el => ( @@ -249,7 +239,7 @@ namespace AsbCloudInfrastructure.Services private static IEnumerable<(double BhaDownSpeedPlan, double BhaDownSpeedFact)> GetWellBhaDownSpeedPlanFact( IEnumerable> groupedOperations) { - var bhaDownSpeedBase = GetParams(groupedOperations, 3); + var bhaDownSpeedBase = GetParams(groupedOperations, 71); return bhaDownSpeedBase.Select(el => ( @@ -261,7 +251,7 @@ namespace AsbCloudInfrastructure.Services private static IEnumerable<(double CasingDownSpeedPlan, double CasingDownSpeedFact)> GetWellCasingDownPlanFact( IEnumerable> groupedOperations) { - var casingDownBase = GetParams(groupedOperations, 4); + var casingDownBase = GetParams(groupedOperations, 74); return casingDownBase.Select(el => ( @@ -291,42 +281,44 @@ namespace AsbCloudInfrastructure.Services private static IEnumerable<(double RouteSpeedPlan, double RouteSpeedFact)> GetWellRouteSpeedsPlanFact( IEnumerable> groupedOperations) { - var bhaRaiseDecreaseCollection = new List<(WellOperation FirstDecreasePlan, WellOperation LastIncreasePlan, - WellOperation FirstDecreaseFact, WellOperation LastIncreaseFact)>(); + var bhaRaiseDecreaseCollection = new List<(WellOperation FirstBhaPositionDecreasePlan, + WellOperation LastBhaPositionIncreasePlan, + WellOperation FirstBhaPositionDecreaseFact, + WellOperation LastBhaPositionIncreaseFact)>(); foreach (var group in groupedOperations) { - var firstBhaPositionDecreasePlan = group.Any(o => o.IdOperationCategory == 5 && o.Type == 0) - ? group.First(o => o.IdOperationCategory == 5 && o.Type == 0) + var firstBhaPositionDecreasePlan = group.Any(o => o.IdOperationCategory == 71 && o.Type == 0) + ? group.First(o => o.IdOperationCategory == 71 && o.Type == 0) : null; - var lastBhaPositionIncreasePlan = group.Any(o => o.IdOperationCategory == 6 && o.Type == 0) - ? group.First(o => o.IdOperationCategory == 5 && o.Type == 0) + var lastBhaPositionIncreasePlan = group.Any(o => o.IdOperationCategory == 72 && o.Type == 0) + ? group.First(o => o.IdOperationCategory == 72 && o.Type == 0) : null; - var firstBhaPositionDecreaseFact = group.Any(o => o.IdOperationCategory == 5 && o.Type == 1) - ? group.First(o => o.IdOperationCategory == 5 && o.Type == 1) - : null; - - var lastBhaPositionIncreaseFact = group.Any(o => o.IdOperationCategory == 6 && o.Type == 1) - ? group.First(o => o.IdOperationCategory == 5 && o.Type == 1) + var firstBhaPositionDecreaseFact = group.Any(o => o.IdOperationCategory == 71 && o.Type == 1) + ? group.First(o => o.IdOperationCategory == 71 && o.Type == 1) : null; + var lastBhaPositionIncreaseFact = group.Any(o => o.IdOperationCategory == 71 && o.Type == 1) + ? group.First(o => o.IdOperationCategory == 71 && o.Type == 1) + : null; + bhaRaiseDecreaseCollection.Add((firstBhaPositionDecreasePlan, lastBhaPositionIncreasePlan, firstBhaPositionDecreaseFact, lastBhaPositionIncreaseFact)); } - var routeSpeedsBase = bhaRaiseDecreaseCollection.Select(el => new // TODO: check value for null + var routeSpeedsBase = bhaRaiseDecreaseCollection.Select(el => new { - RouteDepthPlan = el.FirstDecreasePlan.WellDepth - el.LastIncreasePlan.WellDepth, - RouteDepthFact = el.FirstDecreaseFact.WellDepth - el.LastIncreaseFact.WellDepth, - RouteDurationPlan = (el.LastIncreasePlan.StartDate + - TimeSpan.FromHours(el.LastIncreasePlan.DurationHours) - - el.FirstDecreasePlan.StartDate).TotalHours, - RouteDurationFact = (el.LastIncreaseFact.StartDate + - TimeSpan.FromHours(el.LastIncreaseFact.DurationHours) - - el.FirstDecreaseFact.StartDate).TotalHours + RouteDepthPlan = (el.FirstBhaPositionDecreasePlan?.WellDepth - el.LastBhaPositionIncreasePlan?.WellDepth) ?? 0, + RouteDepthFact = (el.FirstBhaPositionDecreaseFact?.WellDepth - el.LastBhaPositionIncreaseFact?.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 }); return routeSpeedsBase.Select(el =>