StatWellDto Add TvdLagDays and calculation.

This commit is contained in:
ngfrolov 2023-03-06 16:12:26 +05:00
parent 546ac8068e
commit 1ca72d50d1
Signed by: ng.frolov
GPG Key ID: E99907A0357B29A7
3 changed files with 36 additions and 2 deletions

View File

@ -51,5 +51,10 @@ namespace AsbCloudApp.Data
/// компании участвующие в строительстве скважины
/// </summary>
public IEnumerable<CompanyDto> Companies { get; set; } = Enumerable.Empty<CompanyDto>();
/// <summary>
/// Отставание от ГГД, дней
/// </summary>
public double TvdLagDays { get; set; } = 0;
}
}

View File

@ -88,7 +88,6 @@ namespace AsbCloudInfrastructure.Services
WellMapInfo = activeWells.Select(well => {
var wellMapInfo = well.Adapt<WellMapInfoWithComanies>();
// From teltemetryTracker
var wellLastTelemetryInfo = lastTelemetryInfo.FirstOrDefault(t => t.IdTelemetry == well.IdTelemetry);
var wellOperationsStat = operationsStat.FirstOrDefault(s => s.Id == well.Id);
@ -138,7 +137,7 @@ namespace AsbCloudInfrastructure.Services
wellMapInfo.SaubUsage = wellSubsystemStat?.SubsystemAKB?.KUsage ?? 0d;
wellMapInfo.SpinUsage = wellSubsystemStat?.SubsystemSpinMaster?.KUsage ?? 0d;
wellMapInfo.TvdLagPercent = 0;// From WellOperationService?
wellMapInfo.TvdLagPercent = wellOperationsStat?.TvdLagDays ?? 0d;
wellMapInfo.IdsCompanies = well.Companies.Select(c => c.Id);
return wellMapInfo;
}).ToArray();

View File

@ -7,6 +7,7 @@ using Microsoft.Extensions.Caching.Memory;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Threading;
using System.Threading.Tasks;
@ -158,10 +159,39 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
var timezoneOffsetH = wellService.GetTimezone(well.Id).Hours;
statWellDto.Sections = CalcSectionsStats(wellOperations, timezoneOffsetH);
statWellDto.Total = GetStatTotal(wellOperations, well.IdState, timezoneOffsetH);
statWellDto.TvdLagDays = CalcTvdLagDays(wellOperations);
return statWellDto;
}
private double CalcTvdLagDays(IOrderedEnumerable<WellOperation> wellOperations)
{
var operationsOrdered = wellOperations
.OrderBy(o => o.DateStart);
var factOperations = operationsOrdered
.Where(o => o.IdType == WellOperation.IdOperationTypeFact);
var lastCorrespondingFactOperation = factOperations
.LastOrDefault(o => o.IdPlan is not null);
if (lastCorrespondingFactOperation is null)
return 0d;
var lastFactOperation = factOperations.LastOrDefault();
var remainingPlanOperations = operationsOrdered
.Where(o => o.IdType == WellOperation.IdOperationTypePlan)
.Where(o => o.DateStart > lastCorrespondingFactOperation.OperationPlan.DateStart);
var durationRemain = remainingPlanOperations.Sum(o => o.DurationHours);
var factEnd = lastFactOperation.DateStart.AddHours(durationRemain + lastFactOperation.DurationHours);
var planEnd = lastCorrespondingFactOperation.DateStart.AddHours(durationRemain + lastCorrespondingFactOperation.DurationHours);
var lagDays = (planEnd - factEnd).TotalDays;
return lagDays;
}
private IEnumerable<StatSectionDto> CalcSectionsStats(IEnumerable<WellOperation> operations, double timezoneOffsetH)
{
var sectionTypeIds = operations