Add nptDays to WellOperationService

This commit is contained in:
Фролов 2022-03-11 16:53:31 +05:00
parent 8de73084f2
commit efdcb4f211
2 changed files with 38 additions and 26 deletions

View File

@ -20,15 +20,6 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
private readonly CacheTable<WellSectionType> cacheSectionsTypes;
private readonly CacheTable<WellType> cacheWellType;
private readonly CacheTable<Cluster> cacheCluster;
private const int idOperationBhaAssembly = 1025;
private const int idOperationBhaDisassembly = 1026;
private const int idOperationNonProductiveTime = 1043;
private const int idOperationDrilling = 1001;
private const int idOperationBhaDown = 1046;
private const int idOperationBhaUp = 1047;
private const int idOperationCasingDown = 1048;
private const int idOperationTypePlan = 0;
private const int idOperationTypeFact = 1;
public OperationsStatService(IAsbCloudDbContext db, CacheDb cache, IWellService wellService,
ITelemetryService telemetryService)
@ -203,8 +194,8 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
.ToDictionary(s => s.Id);
var sections = new List<StatSectionDto>(sectionTypes.Count);
var operationsPlan = operations.Where(o => o.IdType == idOperationTypePlan);
var operationsFact = operations.Where(o => o.IdType == idOperationTypeFact);
var operationsPlan = operations.Where(o => o.IdType == WellOperationService.idOperationTypePlan);
var operationsFact = operations.Where(o => o.IdType == WellOperationService.idOperationTypeFact);
foreach ((var id, var sectionType) in sectionTypes)
{
@ -223,8 +214,8 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
private static PlanFactBase<StatOperationsDto> GetStatTotal(IEnumerable<WellOperation> operations,
int idWellState, double timezoneOffsetH)
{
var operationsPlan = operations.Where(o => o.IdType == idOperationTypePlan);
var operationsFact = operations.Where(o => o.IdType == idOperationTypeFact);
var operationsPlan = operations.Where(o => o.IdType == WellOperationService.idOperationTypePlan);
var operationsFact = operations.Where(o => o.IdType == WellOperationService.idOperationTypeFact);
var factEnd = CalcStat(operationsFact, timezoneOffsetH);
if (factEnd is not null && idWellState != 2)
factEnd.End = null;
@ -265,7 +256,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
BhaUpSpeed = CalcBhaUpSpeed(races),
CasingDownSpeed = CalcCasingDownSpeed(operations),
NonProductiveHours = operations
.Where(o => o.IdCategory == idOperationNonProductiveTime)
.Where(o => o.IdCategory == WellOperationService.idOperationNonProductiveTime)
.Sum(o => o.DurationHours),
};
return section;
@ -273,7 +264,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
private static double CalcROP(IEnumerable<WellOperation> operationsProps)
{
var drillingOperations = operationsProps.Where(o => o.IdCategory == idOperationDrilling);
var drillingOperations = operationsProps.Where(o => o.IdCategory == WellOperationService.idOperationDrilling);
var dDepth = 0d;
var dHours = 0d;
foreach (var operation in drillingOperations)
@ -287,7 +278,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
private static double CalcCasingDownSpeed(IEnumerable<WellOperation> operationsProps)
{
var ops = operationsProps.Where(o => o.IdCategory == idOperationCasingDown);
var ops = operationsProps.Where(o => o.IdCategory == WellOperationService.idOperationCasingDown);
var depth = 0d;
var dHours = 0d;
foreach (var operation in ops)
@ -306,7 +297,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
.GetEnumerator();
while (iterator.MoveNext())
{
if (iterator.Current.IdCategory == idOperationBhaAssembly)
if (iterator.Current.IdCategory == WellOperationService.idOperationBhaAssembly)
{
var race = new Race
{
@ -316,11 +307,11 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
};
while (iterator.MoveNext())
{
if (iterator.Current.IdCategory == idOperationNonProductiveTime)
if (iterator.Current.IdCategory == WellOperationService.idOperationNonProductiveTime)
{
race.NonProductiveHours += iterator.Current.DurationHours;
}
if (iterator.Current.IdCategory == idOperationBhaDisassembly)
if (iterator.Current.IdCategory == WellOperationService.idOperationBhaDisassembly)
{
race.EndDate = iterator.Current.DateStart.ToRemoteDateTime(timezoneOffsetH);
race.EndWellDepth = iterator.Current.DepthStart;
@ -355,9 +346,9 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
dDepth += race.StartWellDepth;
for (var i = 0; i < race.Operations.Count; i++)
{
if (race.Operations[i].IdCategory == idOperationBhaDown)
if (race.Operations[i].IdCategory == WellOperationService.idOperationBhaDown)
dHours += race.Operations[i].DurationHours;
if (race.Operations[i].IdCategory == idOperationDrilling)
if (race.Operations[i].IdCategory == WellOperationService.idOperationDrilling)
break;
}
}
@ -373,9 +364,9 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
dDepth += race.EndWellDepth;
for (var i = race.Operations.Count - 1; i > 0; i--)
{
if (race.Operations[i].IdCategory == idOperationBhaUp)
if (race.Operations[i].IdCategory == WellOperationService.idOperationBhaUp)
dHours += race.Operations[i].DurationHours;
if (race.Operations[i].IdCategory == idOperationDrilling)
if (race.Operations[i].IdCategory == WellOperationService.idOperationDrilling)
break;
}
}
@ -395,12 +386,12 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
.ConfigureAwait(false);
var wellOperationsPlan = wellOperations
.Where(o => o.IdType == idOperationTypePlan)
.Where(o => o.IdType == WellOperationService.idOperationTypePlan)
.OrderBy(o => o.DateStart)
.ThenBy(o => o.DepthEnd);
var wellOperationsFact = wellOperations
.Where(o => o.IdType == idOperationTypeFact)
.Where(o => o.IdType == WellOperationService.idOperationTypeFact)
.OrderBy(o => o.DateStart)
.ThenBy(o => o.DepthEnd);
@ -424,7 +415,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
var plan = item.Item1;
var fact = item.Item2;
if (fact?.IdCategory == idOperationNonProductiveTime)
if (fact?.IdCategory == WellOperationService.idOperationNonProductiveTime)
{
nptDays += fact.DurationHours;
}

View File

@ -19,6 +19,16 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
private readonly CacheTable<WellOperationCategory> cachedOperationCategories;
private readonly CacheTable<WellSectionType> cachedSectionTypes;
public const int idOperationBhaAssembly = 1025;
public const int idOperationBhaDisassembly = 1026;
public const int idOperationNonProductiveTime = 1043;
public const int idOperationDrilling = 1001;
public const int idOperationBhaDown = 1046;
public const int idOperationBhaUp = 1047;
public const int idOperationCasingDown = 1048;
public const int idOperationTypePlan = 0;
public const int idOperationTypeFact = 1;
public WellOperationService(IAsbCloudDbContext db, CacheDb cache, IWellService wellService)
{
this.db = db;
@ -59,6 +69,8 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
.Include(s => s.OperationCategory)
.Where(s => s.IdWell == idWell);
var dateStart = query.Min(o => o.DateStart);
if (operationType != default)
query = query.Where(e => e.IdType == (int)operationType);
@ -105,12 +117,21 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
var entities = await query.Take(take).AsNoTracking()
.ToListAsync(token).ConfigureAwait(false);
var nptHours = 0d;
foreach (var entity in entities)
{
var dto = entity.Adapt<WellOperationDto>();
dto.Day = (entity.DateStart - dateStart).TotalDays;
dto.WellSectionTypeName = entity.WellSectionType.Caption;
dto.DateStart = entity.DateStart.ToRemoteDateTime(timezone.Hours);
dto.CategoryName = entity.OperationCategory.Name;
if(entity.IdType == idOperationTypeFact)
{
if(entity.IdCategory == idOperationNonProductiveTime)
nptHours += entity.DurationHours;
dto.NptHours = nptHours;
}
result.Items.Add(dto);
}