Рефакторинг формирования отчёта РТК

This commit is contained in:
Степанов Дмитрий 2023-10-12 15:26:37 +05:00
parent ba94db08b0
commit 558f70cf61
6 changed files with 56 additions and 56 deletions

View File

@ -5,7 +5,7 @@ namespace AsbCloudApp.Data.ProcessMaps.Report;
/// <summary> /// <summary>
/// Модель РТК /// Модель РТК
/// </summary> /// </summary>
public class WellDrillingProcessMapReportDto public class ProcessMapReportWellDrillingDto
{ {
/// <summary> /// <summary>
/// Идентификатор скважины /// Идентификатор скважины
@ -64,22 +64,22 @@ public class WellDrillingProcessMapReportDto
/// <summary> /// <summary>
/// Перепад давления, атм /// Перепад давления, атм
/// </summary> /// </summary>
public WellDrillingProcessMapReportParamsDto PressureDiff { get; set; } = new(); public ProcessMapReportWellDrillingParamsDto PressureDiff { get; set; } = new();
/// <summary> /// <summary>
/// Нагрузка, т /// Нагрузка, т
/// </summary> /// </summary>
public WellDrillingProcessMapReportParamsDto AxialLoad { get; set; } = new(); public ProcessMapReportWellDrillingParamsDto AxialLoad { get; set; } = new();
/// <summary> /// <summary>
/// Момент на ВСП, кНхМ /// Момент на ВСП, кНхМ
/// </summary> /// </summary>
public WellDrillingProcessMapReportParamsDto TopDriveTorque { get; set; } = new(); public ProcessMapReportWellDrillingParamsDto TopDriveTorque { get; set; } = new();
/// <summary> /// <summary>
/// Ограничение скорости, м/ч /// Ограничение скорости, м/ч
/// </summary> /// </summary>
public WellDrillingProcessMapReportParamsDto SpeedLimit { get; set; } = new(); public ProcessMapReportWellDrillingParamsDto SpeedLimit { get; set; } = new();
/// <summary> /// <summary>
/// Процент использования системы АПД план, % /// Процент использования системы АПД план, %

View File

@ -3,7 +3,7 @@
/// <summary> /// <summary>
/// Параметры РТК /// Параметры РТК
/// </summary> /// </summary>
public class WellDrillingProcessMapReportParamsDto public class ProcessMapReportWellDrillingParamsDto
{ {
/// <summary> /// <summary>
/// Уставка план /// Уставка план

View File

@ -6,9 +6,9 @@ using AsbCloudApp.Data.ProcessMaps.Report;
namespace AsbCloudApp.Services.ProcessMaps.WellDrillingProcessMap; namespace AsbCloudApp.Services.ProcessMaps.WellDrillingProcessMap;
/// <summary> /// <summary>
/// Сервис формирования РТК /// Сервис формирования отчёта РТК
/// </summary> /// </summary>
public interface IWellDrillingProcessMapReportService public interface IProcessMapReportWellDrillingService
{ {
/// <summary> /// <summary>
/// Получить отчёт РТК по бурению /// Получить отчёт РТК по бурению
@ -16,5 +16,5 @@ public interface IWellDrillingProcessMapReportService
/// <param name="idWell"></param> /// <param name="idWell"></param>
/// <param name="token"></param> /// <param name="token"></param>
/// <returns></returns> /// <returns></returns>
Task<IEnumerable<WellDrillingProcessMapReportDto>> GetAsync(int idWell, CancellationToken token); Task<IEnumerable<ProcessMapReportWellDrillingDto>> GetAsync(int idWell, CancellationToken token);
} }

View File

@ -79,9 +79,9 @@ internal class ParamStat
previous = current; previous = current;
} }
public WellDrillingProcessMapReportParamsDto MakeParams(double? spPlan) public ProcessMapReportWellDrillingParamsDto MakeParams(double? spPlan)
{ {
var result = new WellDrillingProcessMapReportParamsDto var result = new ProcessMapReportWellDrillingParamsDto
{ {
SetpointPlan = spPlan, SetpointPlan = spPlan,
Fact = DivideValByDepth(pvWSum), Fact = DivideValByDepth(pvWSum),

View File

@ -20,13 +20,13 @@ public class WellDrillingProcessMapReportExportService : IProcessMapReportExport
const int headerRowsCount = 5; const int headerRowsCount = 5;
private readonly IWellService wellService; private readonly IWellService wellService;
private readonly IWellDrillingProcessMapReportService wellDrillingProcessMapReportService; private readonly IProcessMapReportWellDrillingService processMapReportWellDrillingService;
public WellDrillingProcessMapReportExportService(IWellService wellService, public WellDrillingProcessMapReportExportService(IWellService wellService,
IWellDrillingProcessMapReportService wellDrillingProcessMapReportService) IProcessMapReportWellDrillingService processMapReportWellDrillingService)
{ {
this.wellService = wellService; this.wellService = wellService;
this.wellDrillingProcessMapReportService = wellDrillingProcessMapReportService; this.processMapReportWellDrillingService = processMapReportWellDrillingService;
} }
@ -40,7 +40,7 @@ public class WellDrillingProcessMapReportExportService : IProcessMapReportExport
var stream = GetExcelTemplateStream(); var stream = GetExcelTemplateStream();
using var workbook = new XLWorkbook(stream, XLEventTracking.Disabled); using var workbook = new XLWorkbook(stream, XLEventTracking.Disabled);
var data = await wellDrillingProcessMapReportService.GetAsync(idWell, cancellationToken); var data = await processMapReportWellDrillingService.GetAsync(idWell, cancellationToken);
FillProcessMapToWorkbook(workbook, data); FillProcessMapToWorkbook(workbook, data);
@ -54,7 +54,7 @@ public class WellDrillingProcessMapReportExportService : IProcessMapReportExport
} }
private static void FillProcessMapToWorkbook(XLWorkbook workbook, private static void FillProcessMapToWorkbook(XLWorkbook workbook,
IEnumerable<WellDrillingProcessMapReportDto> data) IEnumerable<ProcessMapReportWellDrillingDto> data)
{ {
var sheet = workbook.Worksheets.FirstOrDefault(); var sheet = workbook.Worksheets.FirstOrDefault();
if (sheet is null) if (sheet is null)
@ -64,7 +64,7 @@ public class WellDrillingProcessMapReportExportService : IProcessMapReportExport
} }
private static void FillSheet(IXLWorksheet sheet, private static void FillSheet(IXLWorksheet sheet,
IEnumerable<IGrouping<int, WellDrillingProcessMapReportDto>> dataBySections) IEnumerable<IGrouping<int, ProcessMapReportWellDrillingDto>> dataBySections)
{ {
var startRow = headerRowsCount + 1; var startRow = headerRowsCount + 1;
foreach (var sectionData in dataBySections) foreach (var sectionData in dataBySections)
@ -74,7 +74,7 @@ public class WellDrillingProcessMapReportExportService : IProcessMapReportExport
} }
} }
private static int FillSection(IXLWorksheet sheet, IGrouping<int, WellDrillingProcessMapReportDto> sectionData, private static int FillSection(IXLWorksheet sheet, IGrouping<int, ProcessMapReportWellDrillingDto> sectionData,
int row) int row)
{ {
var rowStart = row; var rowStart = row;
@ -96,7 +96,7 @@ public class WellDrillingProcessMapReportExportService : IProcessMapReportExport
return row; return row;
} }
private static int FillIntervalData(IXLWorksheet sheet, WellDrillingProcessMapReportDto interval, int row) private static int FillIntervalData(IXLWorksheet sheet, ProcessMapReportWellDrillingDto interval, int row)
{ {
const int columnDepth = firstColumn + 1; const int columnDepth = firstColumn + 1;
const int columnDate = firstColumn + 2; const int columnDate = firstColumn + 2;
@ -120,7 +120,7 @@ public class WellDrillingProcessMapReportExportService : IProcessMapReportExport
return row; return row;
} }
private static int FillIntervalModeData(IXLWorksheet sheet, WellDrillingProcessMapReportDto modeData, private static int FillIntervalModeData(IXLWorksheet sheet, ProcessMapReportWellDrillingDto modeData,
int column, int row) int column, int row)
{ {
int columnDeltaDepth = column + 1; int columnDeltaDepth = column + 1;
@ -156,7 +156,7 @@ public class WellDrillingProcessMapReportExportService : IProcessMapReportExport
} }
private static void FillIntervalModeDataParam(IXLWorksheet sheet, private static void FillIntervalModeDataParam(IXLWorksheet sheet,
WellDrillingProcessMapReportParamsDto dataParam, int column, int row) ProcessMapReportWellDrillingParamsDto dataParam, int column, int row)
{ {
const int columnOffsetSpPlan = 0; const int columnOffsetSpPlan = 0;
const int columnOffsetSpFact = 1; const int columnOffsetSpFact = 1;
@ -181,7 +181,7 @@ public class WellDrillingProcessMapReportExportService : IProcessMapReportExport
} }
private static void FillIntervalModeDataSpeed(IXLWorksheet sheet, private static void FillIntervalModeDataSpeed(IXLWorksheet sheet,
WellDrillingProcessMapReportParamsDto dataParam, int column, int row) ProcessMapReportWellDrillingParamsDto dataParam, int column, int row)
{ {
const int columnOffsetSpPlan = 0; const int columnOffsetSpPlan = 0;
const int columnOffsetSpFact = 1; const int columnOffsetSpFact = 1;

View File

@ -14,25 +14,25 @@ using AsbCloudInfrastructure.Services.ProcessMaps.WellDrillingProcessMap.Report.
namespace AsbCloudInfrastructure.Services.ProcessMaps.WellDrillingProcessMap.Report; namespace AsbCloudInfrastructure.Services.ProcessMaps.WellDrillingProcessMap.Report;
public class WellDrillingProcessMapReportService : IWellDrillingProcessMapReportService public class WellDrillingProcessMapReportService : IProcessMapReportWellDrillingService
{ {
private readonly IWellService wellService; private readonly IWellService wellService;
private readonly IWellDrillingProcessMapRepository wellDrillingProcessMapRepository; private readonly IProcessMapPlanRepository<ProcessMapPlanWellDrillingDto> processMapPlanWellDrillingRepository;
private readonly ITelemetryDataSaubService telemetryDataSaubService; private readonly ITelemetryDataSaubService telemetryDataSaubService;
private readonly IWellOperationRepository wellOperationRepository; private readonly IWellOperationRepository wellOperationRepository;
public WellDrillingProcessMapReportService(IWellService wellService, public WellDrillingProcessMapReportService(IWellService wellService,
IWellDrillingProcessMapRepository wellDrillingProcessMapRepository, IProcessMapPlanRepository<ProcessMapPlanWellDrillingDto> processMapPlanWellDrillingRepository,
ITelemetryDataSaubService telemetryDataSaubService, ITelemetryDataSaubService telemetryDataSaubService,
IWellOperationRepository wellOperationRepository) IWellOperationRepository wellOperationRepository)
{ {
this.wellService = wellService; this.wellService = wellService;
this.wellDrillingProcessMapRepository = wellDrillingProcessMapRepository; this.processMapPlanWellDrillingRepository = processMapPlanWellDrillingRepository;
this.telemetryDataSaubService = telemetryDataSaubService; this.telemetryDataSaubService = telemetryDataSaubService;
this.wellOperationRepository = wellOperationRepository; this.wellOperationRepository = wellOperationRepository;
} }
public async Task<IEnumerable<WellDrillingProcessMapReportDto>> GetAsync(int idWell, public async Task<IEnumerable<ProcessMapReportWellDrillingDto>> GetAsync(int idWell,
CancellationToken token) CancellationToken token)
{ {
var well = await wellService.GetOrDefaultAsync(idWell, token) var well = await wellService.GetOrDefaultAsync(idWell, token)
@ -41,34 +41,34 @@ public class WellDrillingProcessMapReportService : IWellDrillingProcessMapReport
if (!well.IdTelemetry.HasValue) if (!well.IdTelemetry.HasValue)
throw new ArgumentInvalidException(nameof(idWell), $"Скважина с Id: {idWell} не имеет телеметрии"); throw new ArgumentInvalidException(nameof(idWell), $"Скважина с Id: {idWell} не имеет телеметрии");
var wellDrillingProcessMaps = await wellDrillingProcessMapRepository.GetByIdWellAsync(idWell, token); var processMapPlanWellDrillings = await processMapPlanWellDrillingRepository.GetByIdWellAsync(idWell, token);
if (!wellDrillingProcessMaps.Any()) if (!processMapPlanWellDrillings.Any())
return Enumerable.Empty<WellDrillingProcessMapReportDto>(); return Enumerable.Empty<ProcessMapReportWellDrillingDto>();
var telemetryDataStat = var telemetryDataStat =
(await telemetryDataSaubService.GetTelemetryDataStatAsync(well.IdTelemetry.Value, token)).ToArray(); (await telemetryDataSaubService.GetTelemetryDataStatAsync(well.IdTelemetry.Value, token)).ToArray();
if (!telemetryDataStat.Any()) if (!telemetryDataStat.Any())
return Enumerable.Empty<WellDrillingProcessMapReportDto>(); return Enumerable.Empty<ProcessMapReportWellDrillingDto>();
var result = CalcByIntervals(wellDrillingProcessMaps, telemetryDataStat); var result = CalcByIntervals(processMapPlanWellDrillings, telemetryDataStat);
return result; return result;
} }
private IEnumerable<WellDrillingProcessMapReportDto> CalcByIntervals( private IEnumerable<ProcessMapReportWellDrillingDto> CalcByIntervals(
IEnumerable<WellDrillingProcessMapDto> wellDrillingProcessMaps, IEnumerable<ProcessMapPlanWellDrillingDto> processMapPlanWellDrillings,
TelemetryDataSaubStatDto[] telemetryDataStat) TelemetryDataSaubStatDto[] telemetryDataStat)
{ {
var processMapIntervals = CalcDepthIntervals(wellDrillingProcessMaps); var processMapIntervals = CalcDepthIntervals(processMapPlanWellDrillings);
var result = new List<WellDrillingProcessMapReportDto>(processMapIntervals.Count() * 4); var result = new List<ProcessMapReportWellDrillingDto>(processMapIntervals.Count() * 4);
var telemetryIndexStart = var telemetryIndexStart =
Array.FindIndex(telemetryDataStat, t => t.WellDepthMin >= processMapIntervals.First().DepthStart); Array.FindIndex(telemetryDataStat, t => t.WellDepthMin >= processMapIntervals.First().DepthStart);
if (telemetryIndexStart < 0) if (telemetryIndexStart < 0)
return Enumerable.Empty<WellDrillingProcessMapReportDto>(); return Enumerable.Empty<ProcessMapReportWellDrillingDto>();
IDictionary<int, string> sectionTypes = wellOperationRepository IDictionary<int, string> sectionTypes = wellOperationRepository
.GetSectionTypes() .GetSectionTypes()
@ -76,10 +76,10 @@ public class WellDrillingProcessMapReportService : IWellDrillingProcessMapReport
foreach (var interval in processMapIntervals) foreach (var interval in processMapIntervals)
{ {
var processMapPlanInterval = wellDrillingProcessMaps var processMapPlanWellDrillingInterval = processMapPlanWellDrillings
.Where(p => p.DepthStart <= interval.DepthEnd && p.DepthEnd >= interval.DepthStart); .Where(p => p.DepthStart <= interval.DepthEnd && p.DepthEnd >= interval.DepthStart);
if (!processMapPlanInterval.Any()) if (!processMapPlanWellDrillingInterval.Any())
continue; continue;
var telemetryIndexEnd = Array.FindIndex(telemetryDataStat, telemetryIndexStart, var telemetryIndexEnd = Array.FindIndex(telemetryDataStat, telemetryIndexStart,
@ -89,8 +89,8 @@ public class WellDrillingProcessMapReportService : IWellDrillingProcessMapReport
var telemetryDataInterval = var telemetryDataInterval =
telemetryDataStat.AsSpan(telemetryIndexStart, telemetryIndexEnd - telemetryIndexStart); telemetryDataStat.AsSpan(telemetryIndexStart, telemetryIndexEnd - telemetryIndexStart);
IEnumerable<WellDrillingProcessMapReportDto> subIntervalsResult = IEnumerable<ProcessMapReportWellDrillingDto> subIntervalsResult =
CalcSubIntervals(interval, processMapPlanInterval, telemetryDataInterval, sectionTypes); CalcSubIntervals(interval, processMapPlanWellDrillingInterval, telemetryDataInterval, sectionTypes);
result.AddRange(subIntervalsResult); result.AddRange(subIntervalsResult);
telemetryIndexStart = telemetryIndexEnd; telemetryIndexStart = telemetryIndexEnd;
@ -100,12 +100,12 @@ public class WellDrillingProcessMapReportService : IWellDrillingProcessMapReport
} }
private static IEnumerable<(double DepthStart, double DepthEnd)> CalcDepthIntervals( private static IEnumerable<(double DepthStart, double DepthEnd)> CalcDepthIntervals(
IEnumerable<WellDrillingProcessMapDto> wellDrillingProcessMaps) IEnumerable<ProcessMapPlanWellDrillingDto> processMapPlanWellDrillings)
{ {
if (!wellDrillingProcessMaps.Any()) if (!processMapPlanWellDrillings.Any())
yield break; yield break;
var intervalStarts = wellDrillingProcessMaps var intervalStarts = processMapPlanWellDrillings
.OrderBy(i => i.DepthStart) .OrderBy(i => i.DepthStart)
.Select(p => p.DepthStart) .Select(p => p.DepthStart)
.Distinct() .Distinct()
@ -114,20 +114,20 @@ public class WellDrillingProcessMapReportService : IWellDrillingProcessMapReport
for (var i = 1; i < intervalStarts.Length; i++) for (var i = 1; i < intervalStarts.Length; i++)
yield return (intervalStarts[i - 1], intervalStarts[i]); yield return (intervalStarts[i - 1], intervalStarts[i]);
yield return (intervalStarts[^1], wellDrillingProcessMaps.Max(p => p.DepthEnd)); yield return (intervalStarts[^1], processMapPlanWellDrillings.Max(p => p.DepthEnd));
} }
private static IEnumerable<WellDrillingProcessMapReportDto> CalcSubIntervals( private static IEnumerable<ProcessMapReportWellDrillingDto> CalcSubIntervals(
(double DepthStart, double DepthEnd) interval, (double DepthStart, double DepthEnd) interval,
IEnumerable<WellDrillingProcessMapDto> wellDrillingProcessMapInterval, IEnumerable<ProcessMapPlanWellDrillingDto> processMapPlanWellDrillingInterval,
Span<TelemetryDataSaubStatDto> telemetryDataInterval, Span<TelemetryDataSaubStatDto> telemetryDataInterval,
IDictionary<int, string> sectionTypes) IDictionary<int, string> sectionTypes)
{ {
var telemetryDataIntervalLength = telemetryDataInterval.Length; var telemetryDataIntervalLength = telemetryDataInterval.Length;
if (telemetryDataInterval.Length == 0) if (telemetryDataInterval.Length == 0)
return Enumerable.Empty<WellDrillingProcessMapReportDto>(); return Enumerable.Empty<ProcessMapReportWellDrillingDto>();
var result = new List<WellDrillingProcessMapReportDto>(); var result = new List<ProcessMapReportWellDrillingDto>();
var telemetryIndexStart = 0; var telemetryIndexStart = 0;
var subInterval = interval; var subInterval = interval;
@ -140,7 +140,7 @@ public class WellDrillingProcessMapReportService : IWellDrillingProcessMapReport
if (!telemetryRowSpan.IsEmpty) if (!telemetryRowSpan.IsEmpty)
{ {
var intervalReportRow = CalcSubIntervalReportRow(subInterval, wellDrillingProcessMapInterval, var intervalReportRow = CalcSubIntervalReportRow(subInterval, processMapPlanWellDrillingInterval,
telemetryRowSpan, sectionTypes); telemetryRowSpan, sectionTypes);
result.Add(intervalReportRow); result.Add(intervalReportRow);
} }
@ -151,24 +151,24 @@ public class WellDrillingProcessMapReportService : IWellDrillingProcessMapReport
} }
subInterval.DepthEnd = interval.DepthEnd; subInterval.DepthEnd = interval.DepthEnd;
var intervalReportRowLast = CalcSubIntervalReportRow(subInterval, wellDrillingProcessMapInterval, var intervalReportRowLast = CalcSubIntervalReportRow(subInterval, processMapPlanWellDrillingInterval,
telemetryDataInterval[telemetryIndexStart..telemetryDataIntervalLength], sectionTypes); telemetryDataInterval[telemetryIndexStart..telemetryDataIntervalLength], sectionTypes);
result.Add(intervalReportRowLast); result.Add(intervalReportRowLast);
return result; return result;
} }
private static WellDrillingProcessMapReportDto CalcSubIntervalReportRow( private static ProcessMapReportWellDrillingDto CalcSubIntervalReportRow(
(double DepthStart, double DepthEnd) subInterval, (double DepthStart, double DepthEnd) subInterval,
IEnumerable<WellDrillingProcessMapDto> wellDrillingProcessMaps, IEnumerable<ProcessMapPlanWellDrillingDto> processMapPlanWellDrillings,
Span<TelemetryDataSaubStatDto> telemetryRowSpan, Span<TelemetryDataSaubStatDto> telemetryRowSpan,
IDictionary<int, string> sectionTypes) IDictionary<int, string> sectionTypes)
{ {
var telemetryStat = new TelemetryStat(telemetryRowSpan); var telemetryStat = new TelemetryStat(telemetryRowSpan);
var processMapByMode = wellDrillingProcessMaps.FirstOrDefault(p => p.IdMode == telemetryStat.IdMode); var processMapByMode = processMapPlanWellDrillings.FirstOrDefault(p => p.IdMode == telemetryStat.IdMode);
var processMapFirst = wellDrillingProcessMaps.First(); var processMapFirst = processMapPlanWellDrillings.First();
var idWellSectionType = processMapByMode?.IdWellSectionType ?? processMapFirst.IdWellSectionType; var idWellSectionType = processMapByMode?.IdWellSectionType ?? processMapFirst.IdWellSectionType;
var result = new WellDrillingProcessMapReportDto var result = new ProcessMapReportWellDrillingDto
{ {
IdWell = processMapByMode?.IdWell ?? processMapFirst.IdWell, IdWell = processMapByMode?.IdWell ?? processMapFirst.IdWell,
IdWellSectionType = idWellSectionType, IdWellSectionType = idWellSectionType,