fixed calculations

This commit is contained in:
Фролов 2021-08-26 10:18:59 +05:00
parent fb914cc2b9
commit 7231fad19e

View File

@ -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<OperationParams> 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<StatSectionDto>(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<StatOperationsDto> GetStat(IEnumerable<WellOperation> 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<StatOperationsDto>
{
Plan = CalcStat(operationsPlan),
@ -189,41 +191,26 @@ namespace AsbCloudInfrastructure.Services
private static StatOperationsDto CalcStat(IEnumerable<OperationParams> 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<OperationParams> 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<OperationParams> operationsProps)
//{
//}
private static double CalcROP(IEnumerable<OperationParams> 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<OperationParams> operations)
private static double CalcCasingDownSpeed(IEnumerable<OperationParams> 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<Race> GetCompleteRaces(IEnumerable<OperationParams> operations)
{
var races = new List<Race>();
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<OperationParams>(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<Race> 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<Race> 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<Race> 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<OperationParams> MakeOperationsExt(IEnumerable<WellOperation> 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<Race> GetCompleteRaces(IEnumerable<OperationParams> operations)
{
var races = new List<Race>();
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;
}
}
}