forked from ddrilling/AsbCloudServer
Статистика по скважине
1. Вернул подсчёт отклонения по ГГД в днях 2. Добавил дни бурения скважины
This commit is contained in:
parent
ab166487fb
commit
d9dac97b9e
@ -53,8 +53,13 @@ namespace AsbCloudApp.Data
|
||||
public IEnumerable<CompanyDto> Companies { get; set; } = Enumerable.Empty<CompanyDto>();
|
||||
|
||||
/// <summary>
|
||||
/// Отставание от ГГД, проценты
|
||||
/// Отставание от ГГД, дни
|
||||
/// </summary>
|
||||
public double? TvdLagPercent { get; set; }
|
||||
public double? TvdLagDays { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Кол-во дней бурения по ГГД
|
||||
/// </summary>
|
||||
public double? TvdDrillingDays { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -125,8 +125,13 @@ namespace AsbCloudApp.Data
|
||||
public PlanFactDto<double?> WellDepth { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Отставание от ГГД, проценты
|
||||
/// Отставание от ГГД, дни
|
||||
/// </summary>
|
||||
public double TvdLagPercent { get; set; }
|
||||
public double? TvdLagDays { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Кол-во дней бурения по ГГД
|
||||
/// </summary>
|
||||
public double? TvdDrillingDays { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -188,7 +188,8 @@ namespace AsbCloudInfrastructure.Services
|
||||
wellMapInfo.SaubUsage = wellSubsystemStat?.SubsystemAKB?.KUsage ?? 0d;
|
||||
wellMapInfo.SpinUsage = wellSubsystemStat?.SubsystemSpinMaster?.KUsage ?? 0d;
|
||||
wellMapInfo.TorqueKUsage = wellSubsystemStat?.SubsystemTorqueMaster?.KUsage ?? 0d;
|
||||
wellMapInfo.TvdLagPercent = wellOperationsStat?.TvdLagPercent ?? 0d;
|
||||
wellMapInfo.TvdLagDays = wellOperationsStat?.TvdLagDays;
|
||||
wellMapInfo.TvdDrillingDays = wellOperationsStat?.TvdDrillingDays;
|
||||
wellMapInfo.IdsCompanies = well.Companies.Select(c => c.Id);
|
||||
|
||||
return wellMapInfo;
|
||||
|
@ -172,81 +172,65 @@ public class OperationsStatService : IOperationsStatService
|
||||
var timezoneOffsetH = wellService.GetTimezone(well.Id).Hours;
|
||||
statWellDto.Sections = CalcSectionsStats(wellOperations, timezoneOffsetH);
|
||||
statWellDto.Total = GetStatTotal(wellOperations, well.IdState, timezoneOffsetH);
|
||||
statWellDto.TvdLagPercent = CalcTvdLagPercent(well.IdTelemetry, wellOperations);
|
||||
statWellDto.TvdLagDays = CalcTvdLagDays(wellOperations);
|
||||
statWellDto.TvdDrillingDays = CalcDrillingDays(wellOperations);
|
||||
|
||||
return statWellDto;
|
||||
}
|
||||
|
||||
private double? CalcTvdLagPercent(int? idTelemetry, IOrderedEnumerable<WellOperation> wellOperations)
|
||||
private static double? CalcDrillingDays(IEnumerable<WellOperation> wellOperations)
|
||||
{
|
||||
var currentDate = DateTimeOffset.UtcNow;
|
||||
var operationsOrdered = wellOperations
|
||||
.OrderBy(o => o.DateStart);
|
||||
|
||||
var wellDepth = wellOperations
|
||||
.LastOrDefault(o => o.IdType == WellOperation.IdOperationTypeFact)?.DepthEnd;
|
||||
|
||||
if (idTelemetry.HasValue)
|
||||
wellDepth = telemetryDataCache.GetLastOrDefault(idTelemetry.Value)?.WellDepth;
|
||||
var factOperations = operationsOrdered
|
||||
.Where(o => o.IdType == WellOperation.IdOperationTypeFact);
|
||||
|
||||
if (wellDepth is null)
|
||||
if (!factOperations.Any())
|
||||
return null;
|
||||
|
||||
var operationFrom = factOperations.First();
|
||||
|
||||
var operationTo = factOperations.Last();
|
||||
|
||||
return (operationTo.DateStart.AddHours(operationFrom.DurationHours) - operationFrom.DateStart).TotalDays;
|
||||
}
|
||||
|
||||
private static double? CalcTvdLagDays(IEnumerable<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 null;
|
||||
|
||||
var lastCorrespondingPlanOperation = wellOperations
|
||||
.FirstOrDefault(o => o.Id == lastCorrespondingFactOperation.IdPlan);
|
||||
|
||||
if (lastCorrespondingPlanOperation is null)
|
||||
return null;
|
||||
|
||||
var planOperations = wellOperations
|
||||
var lastFactOperation = factOperations.Last();
|
||||
|
||||
var remainingPlanOperations = operationsOrdered
|
||||
.Where(o => o.IdType == WellOperation.IdOperationTypePlan)
|
||||
.OrderBy(o => o.DateStart.AddHours(o.DurationHours));
|
||||
.Where(o => o.DateStart > lastCorrespondingPlanOperation.DateStart);
|
||||
|
||||
if (!planOperations.Any())
|
||||
return null;
|
||||
var durationRemain = remainingPlanOperations.Sum(o => o.DurationHours);
|
||||
|
||||
var planDepth = CalcPlanDepth(planOperations, currentDate);
|
||||
var factEnd = lastFactOperation.DateStart.AddHours(durationRemain + lastFactOperation.DurationHours);
|
||||
var planEnd = lastCorrespondingFactOperation.DateStart.AddHours(durationRemain + lastCorrespondingFactOperation.DurationHours);
|
||||
var lagDays = (planEnd - factEnd).TotalDays;
|
||||
|
||||
if (planDepth is null)
|
||||
return null;
|
||||
|
||||
if (planDepth == 0d)
|
||||
return 0d;
|
||||
|
||||
return (1 - wellDepth / planDepth) * 100;
|
||||
return lagDays;
|
||||
}
|
||||
|
||||
private static double? CalcPlanDepth(IOrderedEnumerable<WellOperation> planOperations, DateTimeOffset currentDate)
|
||||
{
|
||||
var operationIn = planOperations
|
||||
.FirstOrDefault(o => o.DateStart <= currentDate && o.DateStart.AddHours(o.DurationHours) >= currentDate);
|
||||
|
||||
if (operationIn is not null)
|
||||
return Interpolate(
|
||||
operationIn.DepthStart,
|
||||
operationIn.DepthEnd,
|
||||
operationIn.DateStart,
|
||||
operationIn.DateStart.AddHours(operationIn.DurationHours),
|
||||
currentDate);
|
||||
|
||||
var operationFrom = planOperations
|
||||
.LastOrDefault(o => o.DateStart.AddHours(o.DurationHours) <= currentDate);
|
||||
|
||||
var operationTo = planOperations
|
||||
.FirstOrDefault(o => o.DateStart >= currentDate);
|
||||
|
||||
if (operationFrom is null && operationTo is not null)
|
||||
return 0d;
|
||||
else if (operationFrom is not null && operationTo is not null)
|
||||
{
|
||||
return Interpolate(
|
||||
operationFrom.DepthEnd,
|
||||
operationTo.DepthStart,
|
||||
operationFrom.DateStart.AddHours(operationTo.DurationHours),
|
||||
operationTo.DateStart,
|
||||
currentDate);
|
||||
}
|
||||
else if (operationFrom is not null && operationTo is null)
|
||||
return operationFrom.DepthEnd;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static double Interpolate(double y0, double y1, DateTimeOffset x0, DateTimeOffset x1, DateTimeOffset x)
|
||||
=> y0 + (y1 - y0) * (x - x0).TotalMinutes / (x1 - x0).TotalMinutes;
|
||||
|
||||
private IEnumerable<StatSectionDto> CalcSectionsStats(IEnumerable<WellOperation> operations, double timezoneOffsetH)
|
||||
{
|
||||
var sectionTypeIds = operations
|
||||
|
Loading…
Reference in New Issue
Block a user