расчет глубин для статистики по группам телеметрии выведен в отдельный метод сервиса DetectedOperations.

изменение метода статистики по активным скважинам
This commit is contained in:
eugeniy_ivanov 2022-11-03 13:30:16 +05:00
parent bcdfb1933e
commit a51208cb1d
4 changed files with 50 additions and 69 deletions

View File

@ -10,27 +10,23 @@ namespace AsbCloudApp.Data.Subsystems
/// <summary>
/// Активная скважина
/// </summary>
public WellDto ActiveWell { get; set; }
/// <summary>
/// Наработки подсистем
/// </summary>
public IEnumerable<SubsystemStatDto> listSubsystemStat { get; set; }
public WellDto ActiveWell { get; set; }
/// <summary>
/// Наработки подсистемы АКБ
/// </summary>
public SubsystemStatDto SubsystemAKB { get; set; }
public SubsystemStatDto? SubsystemAKB { get; set; }
/// <summary>
/// Наработки подсистемы МСЕ
/// </summary>
public SubsystemStatDto SubsystemMSE { get; set; }
public SubsystemStatDto? SubsystemMSE { get; set; }
/// <summary>
/// Наработки подсистемы СПИН
/// </summary>
public SubsystemStatDto SubsystemSpinMaster { get; set; }
public SubsystemStatDto? SubsystemSpinMaster { get; set; }
/// <summary>
/// Наработки подсистемы ТОРК
/// </summary>
public SubsystemStatDto SubsystemTorqueMaster { get; set; }
public SubsystemStatDto? SubsystemTorqueMaster { get; set; }
}
}

View File

@ -45,10 +45,9 @@ namespace AsbCloudApp.Services
/// </summary>
/// <param name="gtDate"></param>
/// <param name="ltDate"></param>
/// <param name="token"></param>
/// <param name="wellTimezoneHours"></param>
/// <param name="token"></param>
/// <returns>кортеж - ид телеметрии, интервалы глубины забоя </returns>
Task<IEnumerable<(int, double, double)>?> GetDepthIntervalAllOperationsAsync(DateTime gtDate, DateTime ltDate, double wellTimezoneHours, CancellationToken token);
Task<IEnumerable<(int,double, double)>?> GetDepthIntervalAllOperationsAsync(DateTimeOffset gtDate, DateTimeOffset ltDate, CancellationToken token);
/// <summary>
/// Удалить операции

View File

@ -84,24 +84,28 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
return dtos;
}
public async Task<IEnumerable<(int, double, double)>?> GetDepthIntervalAllOperationsAsync(DateTime gtDate, DateTime ltDate, double wellTimezoneHours ,CancellationToken token)
public async Task<IEnumerable<(int, double, double)>?> GetDepthIntervalAllOperationsAsync(DateTimeOffset gtDate, DateTimeOffset ltDate, CancellationToken token)
{
var query = db.Set<DetectedOperation>()
.Include(o => o.OperationCategory)
.Where(o => o.DateStart >= gtDate.ToUtcDateTimeOffset(wellTimezoneHours))
.Where(o => o.DateEnd <= ltDate.ToUtcDateTimeOffset(wellTimezoneHours));
if (query is null)
return null;
.Where(o => o.DateStart >= gtDate)
.Where(o => o.DateEnd <= ltDate);
var data = await query.ToListAsync(token);
var result = data.GroupBy(g => g.IdTelemetry)
.Select(g =>
(
g.Key,
g.Where(o => o.IdCategory == 1).Sum(o => o.DepthEnd - o.DepthStart),
g.Where(o => o.IdCategory == 3).Sum(o => o.DepthEnd - o.DepthStart)
));
return result;
}
if (data.Any())
{
var result = data.GroupBy(g => g.IdTelemetry)
.Select(g =>
(
g.Key,
g.Where(o => o.IdCategory == 1).Sum(o => o.DepthEnd - o.DepthStart),
g.Where(o => o.IdCategory == 3).Sum(o => o.DepthEnd - o.DepthStart)
));
return result;
}
return null;
}
private static IEnumerable<DetectedOperationDrillersStatDto> GetOperationsDrillersStat(IEnumerable<DetectedOperationDto> operations)
{
@ -320,6 +324,7 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
var exportService = new DetectedOperationExportService(db, wellService);
return exportService.ExportAsync(idsWells, token);
}
}
#nullable disable
}

View File

@ -25,6 +25,10 @@ namespace AsbCloudInfrastructure.Services.Subsystems
private readonly IWellService wellService;
private readonly ICrudService<SubsystemDto> subsystemService;
private readonly IDetectedOperationService detectedOperationService;
public const int IdSubsystemAKB = 1;
public const int IdSubsystemMSE = 2;
public const int IdSubsystemSpin = 65536;
public const int IdSubsystemTorque = 65537;
public SubsystemOperationTimeService(IAsbCloudDbContext db, IWellService wellService, ICrudService<SubsystemDto> subsystemService, IDetectedOperationService detectedOperationService)
{
this.db = db;
@ -202,30 +206,19 @@ namespace AsbCloudInfrastructure.Services.Subsystems
var query = db.SubsystemOperationTimes
.Where(o => telemetryIds.Contains(o.IdTelemetry))
.AsNoTracking();
.AsNoTracking();
var beginUTC = DateTime.Today.AddDays(-1).ToUtcDateTimeOffset(firstWell.Timezone.Hours);
var endUTC = DateTime.Today.ToUtcDateTimeOffset(firstWell.Timezone.Hours);
if (gtDate is not null)
{
var beginUTC = gtDate.Value.ToUtcDateTimeOffset(firstWell.Timezone.Hours);
query = query.Where(d => d.DateStart >= beginUTC);
}
else
{
var beginUTC = DateTime.Today.AddDays(-1).ToUtcDateTimeOffset(firstWell.Timezone.Hours);
query = query.Where(o => o.DateStart >= beginUTC );
}
if (ltDate is not null)
{
var endUTC = ltDate.Value.ToUtcDateTimeOffset(firstWell.Timezone.Hours);
query = query.Where(d => d.DateEnd <= endUTC);
}
else
{
var endUTC = DateTime.Today.ToUtcDateTimeOffset(firstWell.Timezone.Hours);
query = query.Where(o => o.DateEnd <= endUTC);
beginUTC = gtDate.Value.ToUtcDateTimeOffset(firstWell.Timezone.Hours);
}
query = query.Where(d => d.DateStart >= beginUTC);
query = query.Where(o => o.DateEnd <= endUTC);
var depthIntervals = await detectedOperationService.GetDepthIntervalAllOperationsAsync(beginUTC, endUTC, token);
var result = new List<SubsystemActiveWellStatDto>();
var subsystemsOperationTime = await query.ToListAsync(token);
@ -238,33 +231,21 @@ namespace AsbCloudInfrastructure.Services.Subsystems
{
var wellStat = new SubsystemActiveWellStatDto()
{
ActiveWell = well,
listSubsystemStat = new List<SubsystemStatDto>()
ActiveWell = well
};
var detectedOperationsRequest = new DetectedOperationRequest()
if (depthIntervals is not null)
{
IdWell = well.Id,
IdsCategories = new List<int>() { 1, 3 },
LtDate = ltDate,
GtDate = gtDate,
};
var detectedOperations = await detectedOperationService.GetOperationsAsync(detectedOperationsRequest, token);
if (detectedOperations is not null && detectedOperations.Any())
{
var depthInterval = GetDepthInterval(detectedOperations);
var groupSubsystem = group.GroupBy(g => g.IdSubsystem);
foreach (var subsystem in groupSubsystem)
{
var dto = subsystem.Select(s => s.Adapt<SubsystemOperationTimeDto>());
var subsystemStat = CalcStat(dto, depthInterval);
wellStat.listSubsystemStat.Concat(subsystemStat);
//wellStat.Saub = subsystemStat.FirstOrDefault(s=>s.IdSubsystem == idSubsystemSaub)
}
var depthInterval = depthIntervals.Where(o => o.Item1 == well.IdTelemetry).Select(o => (o.Item2, o.Item3)).FirstOrDefault();
//var groupSubsystem = group.GroupBy(g => g.IdSubsystem);
var dto = group.Select(s => s.Adapt<SubsystemOperationTimeDto>());
var subsystemStat = CalcStat(dto, depthInterval);
wellStat.SubsystemAKB = subsystemStat.FirstOrDefault(s => s.IdSubsystem == IdSubsystemAKB);
wellStat.SubsystemMSE = subsystemStat.FirstOrDefault(s => s.IdSubsystem == IdSubsystemMSE);
wellStat.SubsystemSpinMaster = subsystemStat.FirstOrDefault(s => s.IdSubsystem == IdSubsystemSpin);
wellStat.SubsystemTorqueMaster = subsystemStat.FirstOrDefault(s => s.IdSubsystem == IdSubsystemTorque);
result.Add(wellStat);
}
}
}
return result;