Изменения рассчёта отклонения по ТВД

This commit is contained in:
parent f6ac5b5a98
commit 20d306a24c
5 changed files with 48 additions and 42 deletions

View File

@ -53,8 +53,8 @@ namespace AsbCloudApp.Data
public IEnumerable<CompanyDto> Companies { get; set; } = Enumerable.Empty<CompanyDto>(); public IEnumerable<CompanyDto> Companies { get; set; } = Enumerable.Empty<CompanyDto>();
/// <summary> /// <summary>
/// Отставание от ГГД, дней /// Отставание от ГГД, проценты
/// </summary> /// </summary>
public double TvdLagDays { get; set; } = 0; public double? TvdLagPercent { get; set; }
} }
} }

View File

@ -95,9 +95,8 @@ namespace AsbCloudApp.Data
public PlanFactDto<double?> WellDepth { get; set; } = null!; public PlanFactDto<double?> WellDepth { get; set; } = null!;
/// <summary> /// <summary>
/// Отставание от ГГД, дни /// Отставание от ГГД, проценты
/// </summary> /// </summary>
public double TvdLagDays { get; set; } public double TvdLagPercent { get; set; }
} }
} }

View File

@ -89,6 +89,11 @@ namespace AsbCloudApp.Data
[DateValidation(GtDate = "2010-01-01T00:00:00")] [DateValidation(GtDate = "2010-01-01T00:00:00")]
public DateTime DateStart { get; set; } public DateTime DateStart { get; set; }
/// <summary>
/// Дата окончания операции
/// </summary>
public DateTime DateEnd => DateStart.AddHours(DurationHours);
/// <summary> /// <summary>
/// Продолжительность, часы /// Продолжительность, часы
/// </summary> /// </summary>

View File

@ -138,8 +138,7 @@ namespace AsbCloudInfrastructure.Services
wellMapInfo.FirstFactOperationDateStart = wellOperationsStat?.Total.Fact?.Start wellMapInfo.FirstFactOperationDateStart = wellOperationsStat?.Total.Fact?.Start
?? wellOperationsStat?.Total.Plan?.Start; ?? wellOperationsStat?.Total.Plan?.Start;
wellMapInfo.LastPredictOperationDateEnd = wellOperationsStat?.Total.Plan?.End? wellMapInfo.LastPredictOperationDateEnd = wellOperationsStat?.Total.Plan?.End;
.AddDays(wellOperationsStat?.TvdLagDays ?? 0d);
wellMapInfo.WellDepth = new() wellMapInfo.WellDepth = new()
{ {
@ -163,7 +162,7 @@ namespace AsbCloudInfrastructure.Services
wellMapInfo.SaubUsage = wellSubsystemStat?.SubsystemAKB?.KUsage ?? 0d; wellMapInfo.SaubUsage = wellSubsystemStat?.SubsystemAKB?.KUsage ?? 0d;
wellMapInfo.SpinUsage = wellSubsystemStat?.SubsystemSpinMaster?.KUsage ?? 0d; wellMapInfo.SpinUsage = wellSubsystemStat?.SubsystemSpinMaster?.KUsage ?? 0d;
wellMapInfo.TorqueKUsage = wellSubsystemStat?.SubsystemTorqueMaster?.KUsage ?? 0d; wellMapInfo.TorqueKUsage = wellSubsystemStat?.SubsystemTorqueMaster?.KUsage ?? 0d;
wellMapInfo.TvdLagDays = wellOperationsStat?.TvdLagDays ?? 0d; wellMapInfo.TvdLagPercent = wellOperationsStat?.TvdLagPercent ?? 0d;
wellMapInfo.IdsCompanies = well.Companies.Select(c => c.Id); wellMapInfo.IdsCompanies = well.Companies.Select(c => c.Id);
return wellMapInfo; return wellMapInfo;

View File

@ -9,6 +9,8 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using AsbCloudApp.Data.SAUB;
using AsbCloudInfrastructure.Services.SAUB;
namespace AsbCloudInfrastructure.Services.WellOperationService namespace AsbCloudInfrastructure.Services.WellOperationService
{ {
@ -18,13 +20,16 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
private readonly IAsbCloudDbContext db; private readonly IAsbCloudDbContext db;
private readonly IMemoryCache memoryCache; private readonly IMemoryCache memoryCache;
private readonly IWellService wellService; private readonly IWellService wellService;
private readonly TelemetryDataCache<TelemetryDataSaubDto> telemetryDataCache;
public OperationsStatService(IAsbCloudDbContext db, IMemoryCache memoryCache, IWellService wellService) public OperationsStatService(IAsbCloudDbContext db, IMemoryCache memoryCache, IWellService wellService,
TelemetryDataCache<TelemetryDataSaubDto> telemetryDataCache)
{ {
this.db = db; this.db = db;
this.memoryCache = memoryCache; this.memoryCache = memoryCache;
this.wellService = wellService; this.wellService = wellService;
} this.telemetryDataCache = telemetryDataCache;
}
public async Task<StatClusterDto?> GetOrDefaultStatClusterAsync(int idCluster, int idCompany, CancellationToken token) public async Task<StatClusterDto?> GetOrDefaultStatClusterAsync(int idCluster, int idCompany, CancellationToken token)
{ {
@ -168,45 +173,43 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
var timezoneOffsetH = wellService.GetTimezone(well.Id).Hours; var timezoneOffsetH = wellService.GetTimezone(well.Id).Hours;
statWellDto.Sections = CalcSectionsStats(wellOperations, timezoneOffsetH); statWellDto.Sections = CalcSectionsStats(wellOperations, timezoneOffsetH);
statWellDto.Total = GetStatTotal(wellOperations, well.IdState, timezoneOffsetH); statWellDto.Total = GetStatTotal(wellOperations, well.IdState, timezoneOffsetH);
statWellDto.TvdLagDays = CalcTvdLagDays(wellOperations); statWellDto.TvdLagPercent = CalcTvdLagPercent(well.IdTelemetry, wellOperations
.Select(x => x.Adapt<WellOperationDto>()));
return statWellDto; return statWellDto;
} }
private static double CalcTvdLagDays(IOrderedEnumerable<WellOperation> wellOperations) private double? CalcTvdLagPercent(int? idTelemetry, IEnumerable<WellOperationDto> wellOperations)
{ {
var operationsOrdered = wellOperations if (!idTelemetry.HasValue)
.OrderBy(o => o.DateStart); return null;
var factOperations = operationsOrdered var currentDate = DateTime.UtcNow;
.Where(o => o.IdType == WellOperation.IdOperationTypeFact);
var lastCorrespondingFactOperation = factOperations var lastFactOperation = telemetryDataCache.GetLastOrDefault(idTelemetry.Value);
.LastOrDefault(o => o.IdPlan is not null);
wellOperations = wellOperations
.Where(o => o.IdType == WellOperation.IdOperationTypePlan)
.OrderBy(o => o.DateEnd);
var wellOperationFrom = wellOperations
.LastOrDefault(o => o.DateEnd <= currentDate);
var wellOperationTo = wellOperations
.FirstOrDefault(o => o.DateEnd >= currentDate);
var wellOperationDepthFrom = wellOperationFrom?.DepthEnd;
var wellOperationDepthTo = wellOperationTo?.DepthStart ?? wellOperationDepthFrom;
var wellOperationDateFrom = wellOperationFrom?.DateEnd;
var wellOperationDateTo = wellOperationTo?.DateStart ?? wellOperationDateFrom;
if (lastCorrespondingFactOperation is null) var planDepth = (wellOperationDateTo - wellOperationDateFrom)?.TotalHours *
return 0d; (wellOperationDepthTo - wellOperationDepthFrom) /
(currentDate - wellOperationDateFrom)?.TotalHours + wellOperationDepthFrom;
var lastCorrespondingPlanOperation = wellOperations
.FirstOrDefault(o => o.Id == lastCorrespondingFactOperation.IdPlan);
if (lastCorrespondingPlanOperation is null) return (1 - lastFactOperation?.WellDepth / planDepth) * 100;
return 0d; }
var lastFactOperation = factOperations.Last();
var remainingPlanOperations = operationsOrdered
.Where(o => o.IdType == WellOperation.IdOperationTypePlan)
.Where(o => o.DateStart > lastCorrespondingPlanOperation.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) private IEnumerable<StatSectionDto> CalcSectionsStats(IEnumerable<WellOperation> operations, double timezoneOffsetH)
{ {
@ -544,4 +547,4 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
} }
} }
} }