forked from ddrilling/AsbCloudServer
CS2-54: Fixed well section calculation for empty data
This commit is contained in:
parent
154426a5fb
commit
09c47636d1
@ -275,25 +275,24 @@ namespace AsbCloudDb.Model
|
||||
new WellOperationCategory {Id = 1064, Name = "Разбуривание тех.оснастки", Code = 0 },
|
||||
new WellOperationCategory {Id = 1065, Name = "Разбурка ЦКОДа", Code = 0 },
|
||||
new WellOperationCategory {Id = 1066, Name = "Ремонт наг.линии подпорного насоса", Code = 0 },
|
||||
new WellOperationCategory {Id = 1067, Name = "Ремонт наг.линии подпорного насоса", Code = 0 },
|
||||
new WellOperationCategory {Id = 1068, Name = "Сборка КНБК", Code = 0 },
|
||||
new WellOperationCategory {Id = 1069, Name = "Сборка роторной КНБК", Code = 0 },
|
||||
new WellOperationCategory {Id = 1070, Name = "Спуск инструмента", Code = 0 },
|
||||
new WellOperationCategory {Id = 1071, Name = "Спуск КНБК", Code = 0 },
|
||||
new WellOperationCategory {Id = 1072, Name = "Подъем КНБК", Code = 0 },
|
||||
new WellOperationCategory {Id = 1073, Name = "Спуск ЛБТ", Code = 0 },
|
||||
new WellOperationCategory {Id = 1074, Name = "Спуск ОК", Code = 0 },
|
||||
new WellOperationCategory {Id = 1075, Name = "Спуск ЭК", Code = 0 },
|
||||
new WellOperationCategory {Id = 1076, Name = "Тех СПО", Code = 0 },
|
||||
new WellOperationCategory {Id = 1077, Name = "Тех СПО-подъем", Code = 0 },
|
||||
new WellOperationCategory {Id = 1078, Name = "Тех СПО-спуск", Code = 0 },
|
||||
new WellOperationCategory {Id = 1079, Name = "ТО СВП", Code = 0 },
|
||||
new WellOperationCategory {Id = 1080, Name = "Цементаж", Code = 0 },
|
||||
new WellOperationCategory {Id = 1081, Name = "Цементаж кондуктора", Code = 0 },
|
||||
new WellOperationCategory {Id = 1082, Name = "Цементаж направления", Code = 0 },
|
||||
new WellOperationCategory {Id = 1083, Name = "Цементаж ЭК", Code = 0 },
|
||||
new WellOperationCategory {Id = 1084, Name = "Шаблонировка ствола", Code = 0 },
|
||||
new WellOperationCategory {Id = 1085, Name = "Cпуск направления", Code = 0 }
|
||||
new WellOperationCategory {Id = 1067, Name = "Сборка КНБК", Code = 0 },
|
||||
new WellOperationCategory {Id = 1068, Name = "Сборка роторной КНБК", Code = 0 },
|
||||
new WellOperationCategory {Id = 1069, Name = "Спуск инструмента", Code = 0 },
|
||||
new WellOperationCategory {Id = 1070, Name = "Спуск КНБК", Code = 0 },
|
||||
new WellOperationCategory {Id = 1071, Name = "Подъем КНБК", Code = 0 },
|
||||
new WellOperationCategory {Id = 1072, Name = "Спуск ЛБТ", Code = 0 },
|
||||
new WellOperationCategory {Id = 1073, Name = "Спуск ОК", Code = 0 },
|
||||
new WellOperationCategory {Id = 1074, Name = "Спуск ЭК", Code = 0 },
|
||||
new WellOperationCategory {Id = 1075, Name = "Тех СПО", Code = 0 },
|
||||
new WellOperationCategory {Id = 1076, Name = "Тех СПО-подъем", Code = 0 },
|
||||
new WellOperationCategory {Id = 1077, Name = "Тех СПО-спуск", Code = 0 },
|
||||
new WellOperationCategory {Id = 1078, Name = "ТО СВП", Code = 0 },
|
||||
new WellOperationCategory {Id = 1079, Name = "Цементаж", Code = 0 },
|
||||
new WellOperationCategory {Id = 1080, Name = "Цементаж кондуктора", Code = 0 },
|
||||
new WellOperationCategory {Id = 1081, Name = "Цементаж направления", Code = 0 },
|
||||
new WellOperationCategory {Id = 1082, Name = "Цементаж ЭК", Code = 0 },
|
||||
new WellOperationCategory {Id = 1083, Name = "Шаблонировка ствола", Code = 0 },
|
||||
new WellOperationCategory {Id = 1084, Name = "Cпуск направления", Code = 0 }
|
||||
});
|
||||
});
|
||||
|
||||
@ -413,43 +412,43 @@ namespace AsbCloudDb.Model
|
||||
{
|
||||
entity.HasData(new List<WellOperation> {
|
||||
new WellOperation{ Id = 1, IdWell = 1, IdWellSectionType = 1,
|
||||
IdCategory = 18, IdType = 0,
|
||||
IdCategory = 1018, IdType = 0,
|
||||
WellDepth = 200, StartDate = DateTime.Now.AddHours(1),
|
||||
DurationHours = 1.2},
|
||||
new WellOperation{ Id = 2, IdWell = 1, IdWellSectionType = 1,
|
||||
IdCategory = 18, IdType = 1,
|
||||
IdCategory = 1018, IdType = 1,
|
||||
WellDepth = 300, StartDate = DateTime.Now.AddHours(1),
|
||||
DurationHours = 1},
|
||||
new WellOperation{ Id = 3, IdWell = 1, IdWellSectionType = 1,
|
||||
IdCategory = 71, IdType = 0,
|
||||
IdCategory = 1071, IdType = 0,
|
||||
WellDepth = 400, StartDate = DateTime.Now.AddHours(2.5),
|
||||
DurationHours = 15.2},
|
||||
new WellOperation{ Id = 4, IdWell = 1, IdWellSectionType = 1,
|
||||
IdCategory = 71, IdType = 1,
|
||||
IdCategory = 1071, IdType = 1,
|
||||
WellDepth = 500, StartDate = DateTime.Now.AddHours(3),
|
||||
DurationHours = 17.2},
|
||||
new WellOperation{ Id = 5, IdWell = 1, IdWellSectionType = 2,
|
||||
IdCategory = 72, IdType = 0,
|
||||
IdCategory = 1072, IdType = 0,
|
||||
WellDepth = 600, StartDate = DateTime.Now.AddHours(4),
|
||||
DurationHours = 5},
|
||||
new WellOperation{ Id = 6, IdWell = 1, IdWellSectionType = 2,
|
||||
IdCategory = 72, IdType = 1,
|
||||
IdCategory = 1072, IdType = 1,
|
||||
WellDepth = 700, StartDate = DateTime.Now.AddHours(4.3),
|
||||
DurationHours = 7},
|
||||
new WellOperation{ Id = 7, IdWell = 1, IdWellSectionType = 2,
|
||||
IdCategory = 74, IdType = 0,
|
||||
IdCategory = 1074, IdType = 0,
|
||||
WellDepth = 800, StartDate = DateTime.Now.AddHours(5),
|
||||
DurationHours = 12},
|
||||
new WellOperation{ Id = 8, IdWell = 1, IdWellSectionType = 2,
|
||||
IdCategory = 74, IdType = 1,
|
||||
IdCategory = 1074, IdType = 1,
|
||||
WellDepth = 900, StartDate = DateTime.Now.AddHours(4.5),
|
||||
DurationHours = 12},
|
||||
new WellOperation{ Id = 9, IdWell = 1, IdWellSectionType = 3,
|
||||
IdCategory = 72, IdType = 0,
|
||||
IdCategory = 1072, IdType = 0,
|
||||
WellDepth = 950, StartDate = DateTime.Now.AddHours(5),
|
||||
DurationHours = 2},
|
||||
new WellOperation{ Id = 10, IdWell = 1, IdWellSectionType = 3,
|
||||
IdCategory = 72, IdType = 1,
|
||||
IdCategory = 1072, IdType = 1,
|
||||
WellDepth = 900, StartDate = DateTime.Now.AddHours(5),
|
||||
DurationHours = 2.5}
|
||||
});
|
||||
|
@ -29,18 +29,20 @@ namespace AsbCloudInfrastructure.Services
|
||||
public async Task<PaginationContainer<WellSectionDto>> GetSectionsByWellIdAsync(int idWell,
|
||||
int skip, int take, CancellationToken token = default)
|
||||
{
|
||||
var groupedWellOperationsQuery = (from w in db.WellOperations
|
||||
var wellOperations = await (from w in db.WellOperations
|
||||
where w.IdWell == idWell
|
||||
select w)
|
||||
.Include(w => w.WellSectionType)
|
||||
.GroupBy(op => op.IdWellSectionType);
|
||||
.ToListAsync(token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
var wellOperationsGroupedBySections = wellOperations
|
||||
.GroupBy(op => op.IdWellSectionType).ToList();
|
||||
|
||||
if (skip > 0)
|
||||
groupedWellOperationsQuery = groupedWellOperationsQuery.Skip(skip);
|
||||
wellOperationsGroupedBySections = wellOperationsGroupedBySections.Skip(skip).ToList();
|
||||
|
||||
var wellOperationsGroupedBySections = await groupedWellOperationsQuery
|
||||
.Take(take).ToListAsync(token)
|
||||
.ConfigureAwait(false);
|
||||
wellOperationsGroupedBySections = wellOperationsGroupedBySections.Take(take).ToList();
|
||||
|
||||
var result = new PaginationContainer<WellSectionDto>
|
||||
{
|
||||
@ -68,12 +70,12 @@ namespace AsbCloudInfrastructure.Services
|
||||
|
||||
var dtos = new List<WellSectionDto>();
|
||||
|
||||
for(int i = 0; i <= wellOperationsGroupedBySections.Count; i++)
|
||||
for(int i = 0; i < wellOperationsGroupedBySections.Count; i++)
|
||||
{
|
||||
var dto = new WellSectionDto
|
||||
{
|
||||
SectionType = wellOperationsGroupedBySections[i]
|
||||
.FirstOrDefault().OperationCategory.Name,
|
||||
.FirstOrDefault().WellSectionType.Caption,
|
||||
WellDepthPlan = depthsPlanFactList[i].DepthPlan,
|
||||
WellDepthFact = depthsPlanFactList[i].DepthFact,
|
||||
DurationPlan = durationsPlanFactList[i].DurationPlan,
|
||||
@ -215,49 +217,79 @@ namespace AsbCloudInfrastructure.Services
|
||||
private static IEnumerable<(double MechSpeedPlan, double MechSpeedFact)> GetWellMechSpeedPlanFact(
|
||||
IEnumerable<IGrouping<int, WellOperation>> groupedOperations)
|
||||
{
|
||||
var mechSpeedBase = GetParams(groupedOperations, 18);
|
||||
var mechSpeedBase = GetParams(groupedOperations, 1018);
|
||||
|
||||
return mechSpeedBase.Select(el =>
|
||||
(
|
||||
MechSpeedPlan: el.DepthDifferencePlanSum / el.DurationDifferencePlanSum,
|
||||
MechSpeedFact: el.DepthDifferenceFactSum / el.DurationDifferenceFactSum
|
||||
));
|
||||
return CalculateResult(mechSpeedBase);
|
||||
}
|
||||
|
||||
private static IEnumerable<(double BhaUpSpeedPlan, double BhaUpSpeedFact)> GetWellBhaUpSpeedPlanFact(
|
||||
IEnumerable<IGrouping<int, WellOperation>> groupedOperations)
|
||||
{
|
||||
var bhaUpSpeedBase = GetParams(groupedOperations, 72);
|
||||
var bhaUpSpeedBase = GetParams(groupedOperations, 1072);
|
||||
|
||||
return bhaUpSpeedBase.Select(el =>
|
||||
(
|
||||
BhaUpSpeedPlan: el.DepthDifferencePlanSum / el.DurationDifferencePlanSum,
|
||||
BhaUpSpeedFact: el.DepthDifferenceFactSum / el.DurationDifferenceFactSum
|
||||
));
|
||||
return CalculateResult(bhaUpSpeedBase);
|
||||
}
|
||||
|
||||
private static IEnumerable<(double BhaDownSpeedPlan, double BhaDownSpeedFact)> GetWellBhaDownSpeedPlanFact(
|
||||
IEnumerable<IGrouping<int, WellOperation>> groupedOperations)
|
||||
{
|
||||
var bhaDownSpeedBase = GetParams(groupedOperations, 71);
|
||||
var bhaDownSpeedBase = GetParams(groupedOperations, 1071);
|
||||
|
||||
return bhaDownSpeedBase.Select(el =>
|
||||
(
|
||||
BhaDownSpeedPlan: el.DepthDifferencePlanSum / el.DurationDifferencePlanSum,
|
||||
BhaDownSpeedFact: el.DepthDifferenceFactSum / el.DurationDifferenceFactSum
|
||||
));
|
||||
return CalculateResult(bhaDownSpeedBase);
|
||||
}
|
||||
|
||||
private static IEnumerable<(double CasingDownSpeedPlan, double CasingDownSpeedFact)> GetWellCasingDownPlanFact(
|
||||
IEnumerable<IGrouping<int, WellOperation>> groupedOperations)
|
||||
{
|
||||
var casingDownBase = GetParams(groupedOperations, 74);
|
||||
var casingDownBase = GetParams(groupedOperations, 1074);
|
||||
|
||||
return casingDownBase.Select(el =>
|
||||
return CalculateResult(casingDownBase);
|
||||
}
|
||||
|
||||
private static IEnumerable<(double RouteSpeedPlan, double RouteSpeedFact)> GetWellRouteSpeedsPlanFact(
|
||||
IEnumerable<IGrouping<int, WellOperation>> groupedOperations)
|
||||
{
|
||||
var bhaRaiseDecreaseCollection = new List<(WellOperation FirstBhaPositionDecreasePlan,
|
||||
WellOperation LastBhaPositionIncreasePlan,
|
||||
WellOperation FirstBhaPositionDecreaseFact,
|
||||
WellOperation LastBhaPositionIncreaseFact)>();
|
||||
|
||||
foreach (var group in groupedOperations)
|
||||
{
|
||||
var firstBhaPositionDecreasePlan = group.Any(o => o.IdCategory == 1071 && o.IdType == 0)
|
||||
? group.First(o => o.IdCategory == 1071 && o.IdType == 0)
|
||||
: null;
|
||||
|
||||
var lastBhaPositionIncreasePlan = group.Any(o => o.IdCategory == 1072 && o.IdType == 0)
|
||||
? group.Last(o => o.IdCategory == 1072 && o.IdType == 0)
|
||||
: null;
|
||||
|
||||
var firstBhaPositionDecreaseFact = group.Any(o => o.IdCategory == 1071 && o.IdType == 1)
|
||||
? group.First(o => o.IdCategory == 1071 && o.IdType == 1)
|
||||
: null;
|
||||
|
||||
var lastBhaPositionIncreaseFact = group.Any(o => o.IdCategory == 1072 && o.IdType == 1)
|
||||
? group.Last(o => o.IdCategory == 1072 && o.IdType == 1)
|
||||
: null;
|
||||
|
||||
bhaRaiseDecreaseCollection.Add((firstBhaPositionDecreasePlan,
|
||||
lastBhaPositionIncreasePlan, firstBhaPositionDecreaseFact,
|
||||
lastBhaPositionIncreaseFact));
|
||||
}
|
||||
|
||||
var routeSpeedsBase = bhaRaiseDecreaseCollection.Select(el =>
|
||||
(
|
||||
CasingDownSpeedPlan: el.DepthDifferencePlanSum / el.DurationDifferencePlanSum,
|
||||
CasingDownSpeedFact: el.DepthDifferenceFactSum / el.DurationDifferenceFactSum
|
||||
)).ToList();
|
||||
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 CalculateResult(routeSpeedsBase);
|
||||
}
|
||||
|
||||
private static IEnumerable<(double DepthDifferencePlanSum,
|
||||
@ -278,54 +310,18 @@ namespace AsbCloudInfrastructure.Services
|
||||
));
|
||||
}
|
||||
|
||||
private static IEnumerable<(double RouteSpeedPlan, double RouteSpeedFact)> GetWellRouteSpeedsPlanFact(
|
||||
IEnumerable<IGrouping<int, WellOperation>> groupedOperations)
|
||||
private static IEnumerable<(double DataPlan, double DataFact)> CalculateResult(IEnumerable<(double Item1Plan,
|
||||
double Item1Fact, double Item2Plan, double Item2Fact)> rawData)
|
||||
{
|
||||
var bhaRaiseDecreaseCollection = new List<(WellOperation FirstBhaPositionDecreasePlan,
|
||||
WellOperation LastBhaPositionIncreasePlan,
|
||||
WellOperation FirstBhaPositionDecreaseFact,
|
||||
WellOperation LastBhaPositionIncreaseFact)>();
|
||||
|
||||
foreach (var group in groupedOperations)
|
||||
{
|
||||
var firstBhaPositionDecreasePlan = group.Any(o => o.IdCategory == 71 && o.IdType == 0)
|
||||
? group.First(o => o.IdCategory == 71 && o.IdType == 0)
|
||||
: null;
|
||||
|
||||
var lastBhaPositionIncreasePlan = group.Any(o => o.IdCategory == 72 && o.IdType == 0)
|
||||
? group.First(o => o.IdCategory == 72 && o.IdType == 0)
|
||||
: null;
|
||||
|
||||
var firstBhaPositionDecreaseFact = group.Any(o => o.IdCategory == 71 && o.IdType == 1)
|
||||
? group.First(o => o.IdCategory == 71 && o.IdType == 1)
|
||||
: null;
|
||||
|
||||
var lastBhaPositionIncreaseFact = group.Any(o => o.IdCategory == 71 && o.IdType == 1)
|
||||
? group.First(o => o.IdCategory == 71 && o.IdType == 1)
|
||||
: null;
|
||||
|
||||
bhaRaiseDecreaseCollection.Add((firstBhaPositionDecreasePlan,
|
||||
lastBhaPositionIncreasePlan, firstBhaPositionDecreaseFact,
|
||||
lastBhaPositionIncreaseFact));
|
||||
}
|
||||
|
||||
var routeSpeedsBase = bhaRaiseDecreaseCollection.Select(el => new
|
||||
{
|
||||
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 =>
|
||||
return rawData.Select(el =>
|
||||
(
|
||||
RouteSpeedPlan: el.RouteDepthPlan / el.RouteDurationPlan,
|
||||
RouteSpeedFact: el.RouteDepthFact / el.RouteDurationFact
|
||||
)).ToList();
|
||||
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)
|
||||
));
|
||||
}
|
||||
|
||||
private async Task<WellSectionType> GetWellSectionTypeFromCacheAndAssertAsync(string wellSectionType, CancellationToken token = default)
|
||||
|
Loading…
Reference in New Issue
Block a user