Fixed WellSection service

This commit is contained in:
KharchenkoVV 2021-08-18 16:27:18 +05:00
parent ae3a5c1ac7
commit 8bcaf18cb1

View File

@ -215,29 +215,19 @@ namespace AsbCloudInfrastructure.Services
private static IEnumerable<(double MechSpeedPlan, double MechSpeedFact)> GetWellMechSpeedPlanFact(
IEnumerable<IGrouping<int, WellOperation>> 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<IGrouping<int, WellOperation>> 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<IGrouping<int, WellOperation>> 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<IGrouping<int, WellOperation>> groupedOperations)
{
var casingDownBase = GetParams(groupedOperations, 4);
var casingDownBase = GetParams(groupedOperations, 74);
return casingDownBase.Select(el =>
(
@ -291,25 +281,27 @@ namespace AsbCloudInfrastructure.Services
private static IEnumerable<(double RouteSpeedPlan, double RouteSpeedFact)> GetWellRouteSpeedsPlanFact(
IEnumerable<IGrouping<int, WellOperation>> 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)
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 == 6 && o.Type == 1)
? group.First(o => o.IdOperationCategory == 5 && o.Type == 1)
var lastBhaPositionIncreaseFact = group.Any(o => o.IdOperationCategory == 71 && o.Type == 1)
? group.First(o => o.IdOperationCategory == 71 && o.Type == 1)
: null;
bhaRaiseDecreaseCollection.Add((firstBhaPositionDecreasePlan,
@ -317,16 +309,16 @@ namespace AsbCloudInfrastructure.Services
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 =>