Экспорт автоопределённых операций

This commit is contained in:
Степанов Дмитрий 2024-07-25 16:53:48 +03:00
parent acfe9ab000
commit ae79426973
2 changed files with 174 additions and 165 deletions

View File

@ -14,6 +14,7 @@ using AsbCloudApp.Exceptions;
using AsbCloudApp.Services;
using AsbCloudApp.Data;
using AsbCloudApp.Data.WellOperation;
using AsbCloudApp.Requests;
using AsbCloudInfrastructure.Services.DetectOperations.Detectors;
namespace AsbCloudInfrastructure.Services.DetectOperations;
@ -22,7 +23,7 @@ public class DetectedOperationExportService
{
private readonly IWellService wellService;
private readonly IWellOperationCategoryRepository wellOperationCategoryRepository;
private readonly IDetectedOperationService detectedOperationService;
private readonly IDetectedOperationRepository detectedOperationRepository;
private const int headerRowsCount = 1;
private const string cellDepositName = "B1";
@ -43,11 +44,11 @@ public class DetectedOperationExportService
public DetectedOperationExportService(IWellService wellService,
IWellOperationCategoryRepository wellOperationCategoryRepository,
IDetectedOperationService detectedOperationService)
IDetectedOperationRepository detectedOperationRepository)
{
this.wellService = wellService;
this.wellOperationCategoryRepository = wellOperationCategoryRepository;
this.detectedOperationService = detectedOperationService;
this.detectedOperationRepository = detectedOperationRepository;
}
/// <summary>
@ -68,12 +69,19 @@ public class DetectedOperationExportService
if (!well.IdTelemetry.HasValue)
throw new ArgumentInvalidException(nameof(idWell), $"Well {idWell} has no telemetry");
var operations = await detectedOperationService.DetectOperationsAsync(well.IdTelemetry.Value, DateTime.UnixEpoch, token);
var request = new DetectedOperationByTelemetryRequest
{
IdTelemetry = well.IdTelemetry.Value
};
var operations = await detectedOperationRepository.Get(request, token);
return await GenerateExcelFileStreamAsync(well, host, operations, token);
}
private async Task<Stream> GenerateExcelFileStreamAsync(WellDto well, string host, IEnumerable<DetectedOperationDto> operationDetectorResults,
private async Task<Stream> GenerateExcelFileStreamAsync(WellDto well,
string host,
IEnumerable<DetectedOperationDto> operationDetectorResults,
CancellationToken cancellationToken)
{
using var excelTemplateStream = await GetExcelTemplateStreamAsync(cancellationToken);
@ -167,14 +175,15 @@ public class DetectedOperationExportService
var category = wellOperationCategories.FirstOrDefault(o => o.Id == current.IdCategory);
if(category is not null)
if (category is not null)
return category.Name;
return $"Операция №{idCategory}";
}
private static string GetIdReasonOfEnd(int idReasonOfEnd)
=> idReasonOfEnd switch {
=> idReasonOfEnd switch
{
0 => "Не определена",
1 => "Не определено начало операции",
101 => "Разница глубин забоя и положением долота",
@ -182,7 +191,6 @@ public class DetectedOperationExportService
301 => "Высокое давление",
700 => "Изменение глубины долота и осевая нагрузка < веса на крюке",
_ => idReasonOfEnd.ToString($"Причина № {idReasonOfEnd}"),
};
private async Task<Stream> GetExcelTemplateStreamAsync(CancellationToken cancellationToken)
@ -211,7 +219,8 @@ public class DetectedOperationExportService
if (operation.ExtraData.TryGetValue(DetectorDrilling.ExtraDataKeyAvgRotorSpeed, out object? oAvgRotorSpeed))
comment += $"Средняя скорость оборотов ротора: {oAvgRotorSpeed}\r\n";
if (operation.ExtraData.TryGetValue(DetectorDrilling.ExtraDataKeyDispersionOfNormalizedRotorSpeed, out object? oDispersionOfNormalizedRotorSpeed))
if (operation.ExtraData.TryGetValue(DetectorDrilling.ExtraDataKeyDispersionOfNormalizedRotorSpeed,
out object? oDispersionOfNormalizedRotorSpeed))
comment += $"Дисперсия нормированных оборотов ротора: {oDispersionOfNormalizedRotorSpeed}";
return comment;