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

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>();
/// <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!;
/// <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")]
public DateTime DateStart { get; set; }
/// <summary>
/// Дата окончания операции
/// </summary>
public DateTime DateEnd => DateStart.AddHours(DurationHours);
/// <summary>
/// Продолжительность, часы
/// </summary>

View File

@ -138,8 +138,7 @@ namespace AsbCloudInfrastructure.Services
wellMapInfo.FirstFactOperationDateStart = wellOperationsStat?.Total.Fact?.Start
?? wellOperationsStat?.Total.Plan?.Start;
wellMapInfo.LastPredictOperationDateEnd = wellOperationsStat?.Total.Plan?.End?
.AddDays(wellOperationsStat?.TvdLagDays ?? 0d);
wellMapInfo.LastPredictOperationDateEnd = wellOperationsStat?.Total.Plan?.End;
wellMapInfo.WellDepth = new()
{
@ -163,7 +162,7 @@ namespace AsbCloudInfrastructure.Services
wellMapInfo.SaubUsage = wellSubsystemStat?.SubsystemAKB?.KUsage ?? 0d;
wellMapInfo.SpinUsage = wellSubsystemStat?.SubsystemSpinMaster?.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);
return wellMapInfo;

View File

@ -9,6 +9,8 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Data.SAUB;
using AsbCloudInfrastructure.Services.SAUB;
namespace AsbCloudInfrastructure.Services.WellOperationService
{
@ -18,13 +20,16 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
private readonly IAsbCloudDbContext db;
private readonly IMemoryCache memoryCache;
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.memoryCache = memoryCache;
this.wellService = wellService;
}
this.telemetryDataCache = telemetryDataCache;
}
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;
statWellDto.Sections = CalcSectionsStats(wellOperations, 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;
}
private static double CalcTvdLagDays(IOrderedEnumerable<WellOperation> wellOperations)
{
var operationsOrdered = wellOperations
.OrderBy(o => o.DateStart);
private double? CalcTvdLagPercent(int? idTelemetry, IEnumerable<WellOperationDto> wellOperations)
{
if (!idTelemetry.HasValue)
return null;
var factOperations = operationsOrdered
.Where(o => o.IdType == WellOperation.IdOperationTypeFact);
var currentDate = DateTime.UtcNow;
var lastCorrespondingFactOperation = factOperations
.LastOrDefault(o => o.IdPlan is not null);
var lastFactOperation = telemetryDataCache.GetLastOrDefault(idTelemetry.Value);
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)
return 0d;
var lastCorrespondingPlanOperation = wellOperations
.FirstOrDefault(o => o.Id == lastCorrespondingFactOperation.IdPlan);
var planDepth = (wellOperationDateTo - wellOperationDateFrom)?.TotalHours *
(wellOperationDepthTo - wellOperationDepthFrom) /
(currentDate - wellOperationDateFrom)?.TotalHours + wellOperationDepthFrom;
if (lastCorrespondingPlanOperation is null)
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;
}
return (1 - lastFactOperation?.WellDepth / planDepth) * 100;
}
private IEnumerable<StatSectionDto> CalcSectionsStats(IEnumerable<WellOperation> operations, double timezoneOffsetH)
{
@ -544,4 +547,4 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
}
}
}
}