forked from ddrilling/AsbCloudServer
Рефакторинг формирования отчёта РТК
This commit is contained in:
parent
ba94db08b0
commit
558f70cf61
@ -5,7 +5,7 @@ namespace AsbCloudApp.Data.ProcessMaps.Report;
|
||||
/// <summary>
|
||||
/// Модель РТК
|
||||
/// </summary>
|
||||
public class WellDrillingProcessMapReportDto
|
||||
public class ProcessMapReportWellDrillingDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Идентификатор скважины
|
||||
@ -64,22 +64,22 @@ public class WellDrillingProcessMapReportDto
|
||||
/// <summary>
|
||||
/// Перепад давления, атм
|
||||
/// </summary>
|
||||
public WellDrillingProcessMapReportParamsDto PressureDiff { get; set; } = new();
|
||||
public ProcessMapReportWellDrillingParamsDto PressureDiff { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Нагрузка, т
|
||||
/// </summary>
|
||||
public WellDrillingProcessMapReportParamsDto AxialLoad { get; set; } = new();
|
||||
public ProcessMapReportWellDrillingParamsDto AxialLoad { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Момент на ВСП, кНхМ
|
||||
/// </summary>
|
||||
public WellDrillingProcessMapReportParamsDto TopDriveTorque { get; set; } = new();
|
||||
public ProcessMapReportWellDrillingParamsDto TopDriveTorque { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Ограничение скорости, м/ч
|
||||
/// </summary>
|
||||
public WellDrillingProcessMapReportParamsDto SpeedLimit { get; set; } = new();
|
||||
public ProcessMapReportWellDrillingParamsDto SpeedLimit { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Процент использования системы АПД план, %
|
@ -3,7 +3,7 @@
|
||||
/// <summary>
|
||||
/// Параметры РТК
|
||||
/// </summary>
|
||||
public class WellDrillingProcessMapReportParamsDto
|
||||
public class ProcessMapReportWellDrillingParamsDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Уставка план
|
@ -6,9 +6,9 @@ using AsbCloudApp.Data.ProcessMaps.Report;
|
||||
namespace AsbCloudApp.Services.ProcessMaps.WellDrillingProcessMap;
|
||||
|
||||
/// <summary>
|
||||
/// Сервис формирования РТК
|
||||
/// Сервис формирования отчёта РТК
|
||||
/// </summary>
|
||||
public interface IWellDrillingProcessMapReportService
|
||||
public interface IProcessMapReportWellDrillingService
|
||||
{
|
||||
/// <summary>
|
||||
/// Получить отчёт РТК по бурению
|
||||
@ -16,5 +16,5 @@ public interface IWellDrillingProcessMapReportService
|
||||
/// <param name="idWell"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<WellDrillingProcessMapReportDto>> GetAsync(int idWell, CancellationToken token);
|
||||
Task<IEnumerable<ProcessMapReportWellDrillingDto>> GetAsync(int idWell, CancellationToken token);
|
||||
}
|
@ -79,9 +79,9 @@ internal class ParamStat
|
||||
previous = current;
|
||||
}
|
||||
|
||||
public WellDrillingProcessMapReportParamsDto MakeParams(double? spPlan)
|
||||
public ProcessMapReportWellDrillingParamsDto MakeParams(double? spPlan)
|
||||
{
|
||||
var result = new WellDrillingProcessMapReportParamsDto
|
||||
var result = new ProcessMapReportWellDrillingParamsDto
|
||||
{
|
||||
SetpointPlan = spPlan,
|
||||
Fact = DivideValByDepth(pvWSum),
|
||||
|
@ -20,13 +20,13 @@ public class WellDrillingProcessMapReportExportService : IProcessMapReportExport
|
||||
const int headerRowsCount = 5;
|
||||
|
||||
private readonly IWellService wellService;
|
||||
private readonly IWellDrillingProcessMapReportService wellDrillingProcessMapReportService;
|
||||
private readonly IProcessMapReportWellDrillingService processMapReportWellDrillingService;
|
||||
|
||||
public WellDrillingProcessMapReportExportService(IWellService wellService,
|
||||
IWellDrillingProcessMapReportService wellDrillingProcessMapReportService)
|
||||
IProcessMapReportWellDrillingService processMapReportWellDrillingService)
|
||||
{
|
||||
this.wellService = wellService;
|
||||
this.wellDrillingProcessMapReportService = wellDrillingProcessMapReportService;
|
||||
this.processMapReportWellDrillingService = processMapReportWellDrillingService;
|
||||
}
|
||||
|
||||
|
||||
@ -40,7 +40,7 @@ public class WellDrillingProcessMapReportExportService : IProcessMapReportExport
|
||||
var stream = GetExcelTemplateStream();
|
||||
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);
|
||||
|
||||
@ -54,7 +54,7 @@ public class WellDrillingProcessMapReportExportService : IProcessMapReportExport
|
||||
}
|
||||
|
||||
private static void FillProcessMapToWorkbook(XLWorkbook workbook,
|
||||
IEnumerable<WellDrillingProcessMapReportDto> data)
|
||||
IEnumerable<ProcessMapReportWellDrillingDto> data)
|
||||
{
|
||||
var sheet = workbook.Worksheets.FirstOrDefault();
|
||||
if (sheet is null)
|
||||
@ -64,7 +64,7 @@ public class WellDrillingProcessMapReportExportService : IProcessMapReportExport
|
||||
}
|
||||
|
||||
private static void FillSheet(IXLWorksheet sheet,
|
||||
IEnumerable<IGrouping<int, WellDrillingProcessMapReportDto>> dataBySections)
|
||||
IEnumerable<IGrouping<int, ProcessMapReportWellDrillingDto>> dataBySections)
|
||||
{
|
||||
var startRow = headerRowsCount + 1;
|
||||
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)
|
||||
{
|
||||
var rowStart = row;
|
||||
@ -96,7 +96,7 @@ public class WellDrillingProcessMapReportExportService : IProcessMapReportExport
|
||||
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 columnDate = firstColumn + 2;
|
||||
@ -120,7 +120,7 @@ public class WellDrillingProcessMapReportExportService : IProcessMapReportExport
|
||||
return row;
|
||||
}
|
||||
|
||||
private static int FillIntervalModeData(IXLWorksheet sheet, WellDrillingProcessMapReportDto modeData,
|
||||
private static int FillIntervalModeData(IXLWorksheet sheet, ProcessMapReportWellDrillingDto modeData,
|
||||
int column, int row)
|
||||
{
|
||||
int columnDeltaDepth = column + 1;
|
||||
@ -156,7 +156,7 @@ public class WellDrillingProcessMapReportExportService : IProcessMapReportExport
|
||||
}
|
||||
|
||||
private static void FillIntervalModeDataParam(IXLWorksheet sheet,
|
||||
WellDrillingProcessMapReportParamsDto dataParam, int column, int row)
|
||||
ProcessMapReportWellDrillingParamsDto dataParam, int column, int row)
|
||||
{
|
||||
const int columnOffsetSpPlan = 0;
|
||||
const int columnOffsetSpFact = 1;
|
||||
@ -181,7 +181,7 @@ public class WellDrillingProcessMapReportExportService : IProcessMapReportExport
|
||||
}
|
||||
|
||||
private static void FillIntervalModeDataSpeed(IXLWorksheet sheet,
|
||||
WellDrillingProcessMapReportParamsDto dataParam, int column, int row)
|
||||
ProcessMapReportWellDrillingParamsDto dataParam, int column, int row)
|
||||
{
|
||||
const int columnOffsetSpPlan = 0;
|
||||
const int columnOffsetSpFact = 1;
|
||||
|
@ -14,25 +14,25 @@ using 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 IWellDrillingProcessMapRepository wellDrillingProcessMapRepository;
|
||||
private readonly IProcessMapPlanRepository<ProcessMapPlanWellDrillingDto> processMapPlanWellDrillingRepository;
|
||||
private readonly ITelemetryDataSaubService telemetryDataSaubService;
|
||||
private readonly IWellOperationRepository wellOperationRepository;
|
||||
|
||||
public WellDrillingProcessMapReportService(IWellService wellService,
|
||||
IWellDrillingProcessMapRepository wellDrillingProcessMapRepository,
|
||||
IProcessMapPlanRepository<ProcessMapPlanWellDrillingDto> processMapPlanWellDrillingRepository,
|
||||
ITelemetryDataSaubService telemetryDataSaubService,
|
||||
IWellOperationRepository wellOperationRepository)
|
||||
{
|
||||
this.wellService = wellService;
|
||||
this.wellDrillingProcessMapRepository = wellDrillingProcessMapRepository;
|
||||
this.processMapPlanWellDrillingRepository = processMapPlanWellDrillingRepository;
|
||||
this.telemetryDataSaubService = telemetryDataSaubService;
|
||||
this.wellOperationRepository = wellOperationRepository;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<WellDrillingProcessMapReportDto>> GetAsync(int idWell,
|
||||
public async Task<IEnumerable<ProcessMapReportWellDrillingDto>> GetAsync(int idWell,
|
||||
CancellationToken token)
|
||||
{
|
||||
var well = await wellService.GetOrDefaultAsync(idWell, token)
|
||||
@ -41,34 +41,34 @@ public class WellDrillingProcessMapReportService : IWellDrillingProcessMapReport
|
||||
if (!well.IdTelemetry.HasValue)
|
||||
throw new ArgumentInvalidException(nameof(idWell), $"Скважина с Id: {idWell} не имеет телеметрии");
|
||||
|
||||
var wellDrillingProcessMaps = await wellDrillingProcessMapRepository.GetByIdWellAsync(idWell, token);
|
||||
var processMapPlanWellDrillings = await processMapPlanWellDrillingRepository.GetByIdWellAsync(idWell, token);
|
||||
|
||||
if (!wellDrillingProcessMaps.Any())
|
||||
return Enumerable.Empty<WellDrillingProcessMapReportDto>();
|
||||
if (!processMapPlanWellDrillings.Any())
|
||||
return Enumerable.Empty<ProcessMapReportWellDrillingDto>();
|
||||
|
||||
var telemetryDataStat =
|
||||
(await telemetryDataSaubService.GetTelemetryDataStatAsync(well.IdTelemetry.Value, token)).ToArray();
|
||||
|
||||
if (!telemetryDataStat.Any())
|
||||
return Enumerable.Empty<WellDrillingProcessMapReportDto>();
|
||||
return Enumerable.Empty<ProcessMapReportWellDrillingDto>();
|
||||
|
||||
var result = CalcByIntervals(wellDrillingProcessMaps, telemetryDataStat);
|
||||
var result = CalcByIntervals(processMapPlanWellDrillings, telemetryDataStat);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private IEnumerable<WellDrillingProcessMapReportDto> CalcByIntervals(
|
||||
IEnumerable<WellDrillingProcessMapDto> wellDrillingProcessMaps,
|
||||
private IEnumerable<ProcessMapReportWellDrillingDto> CalcByIntervals(
|
||||
IEnumerable<ProcessMapPlanWellDrillingDto> processMapPlanWellDrillings,
|
||||
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 =
|
||||
Array.FindIndex(telemetryDataStat, t => t.WellDepthMin >= processMapIntervals.First().DepthStart);
|
||||
if (telemetryIndexStart < 0)
|
||||
return Enumerable.Empty<WellDrillingProcessMapReportDto>();
|
||||
return Enumerable.Empty<ProcessMapReportWellDrillingDto>();
|
||||
|
||||
IDictionary<int, string> sectionTypes = wellOperationRepository
|
||||
.GetSectionTypes()
|
||||
@ -76,10 +76,10 @@ public class WellDrillingProcessMapReportService : IWellDrillingProcessMapReport
|
||||
|
||||
foreach (var interval in processMapIntervals)
|
||||
{
|
||||
var processMapPlanInterval = wellDrillingProcessMaps
|
||||
var processMapPlanWellDrillingInterval = processMapPlanWellDrillings
|
||||
.Where(p => p.DepthStart <= interval.DepthEnd && p.DepthEnd >= interval.DepthStart);
|
||||
|
||||
if (!processMapPlanInterval.Any())
|
||||
if (!processMapPlanWellDrillingInterval.Any())
|
||||
continue;
|
||||
|
||||
var telemetryIndexEnd = Array.FindIndex(telemetryDataStat, telemetryIndexStart,
|
||||
@ -89,8 +89,8 @@ public class WellDrillingProcessMapReportService : IWellDrillingProcessMapReport
|
||||
var telemetryDataInterval =
|
||||
telemetryDataStat.AsSpan(telemetryIndexStart, telemetryIndexEnd - telemetryIndexStart);
|
||||
|
||||
IEnumerable<WellDrillingProcessMapReportDto> subIntervalsResult =
|
||||
CalcSubIntervals(interval, processMapPlanInterval, telemetryDataInterval, sectionTypes);
|
||||
IEnumerable<ProcessMapReportWellDrillingDto> subIntervalsResult =
|
||||
CalcSubIntervals(interval, processMapPlanWellDrillingInterval, telemetryDataInterval, sectionTypes);
|
||||
|
||||
result.AddRange(subIntervalsResult);
|
||||
telemetryIndexStart = telemetryIndexEnd;
|
||||
@ -100,12 +100,12 @@ public class WellDrillingProcessMapReportService : IWellDrillingProcessMapReport
|
||||
}
|
||||
|
||||
private static IEnumerable<(double DepthStart, double DepthEnd)> CalcDepthIntervals(
|
||||
IEnumerable<WellDrillingProcessMapDto> wellDrillingProcessMaps)
|
||||
IEnumerable<ProcessMapPlanWellDrillingDto> processMapPlanWellDrillings)
|
||||
{
|
||||
if (!wellDrillingProcessMaps.Any())
|
||||
if (!processMapPlanWellDrillings.Any())
|
||||
yield break;
|
||||
|
||||
var intervalStarts = wellDrillingProcessMaps
|
||||
var intervalStarts = processMapPlanWellDrillings
|
||||
.OrderBy(i => i.DepthStart)
|
||||
.Select(p => p.DepthStart)
|
||||
.Distinct()
|
||||
@ -114,20 +114,20 @@ public class WellDrillingProcessMapReportService : IWellDrillingProcessMapReport
|
||||
for (var i = 1; i < intervalStarts.Length; 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,
|
||||
IEnumerable<WellDrillingProcessMapDto> wellDrillingProcessMapInterval,
|
||||
IEnumerable<ProcessMapPlanWellDrillingDto> processMapPlanWellDrillingInterval,
|
||||
Span<TelemetryDataSaubStatDto> telemetryDataInterval,
|
||||
IDictionary<int, string> sectionTypes)
|
||||
{
|
||||
var telemetryDataIntervalLength = telemetryDataInterval.Length;
|
||||
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 subInterval = interval;
|
||||
|
||||
@ -140,7 +140,7 @@ public class WellDrillingProcessMapReportService : IWellDrillingProcessMapReport
|
||||
|
||||
if (!telemetryRowSpan.IsEmpty)
|
||||
{
|
||||
var intervalReportRow = CalcSubIntervalReportRow(subInterval, wellDrillingProcessMapInterval,
|
||||
var intervalReportRow = CalcSubIntervalReportRow(subInterval, processMapPlanWellDrillingInterval,
|
||||
telemetryRowSpan, sectionTypes);
|
||||
result.Add(intervalReportRow);
|
||||
}
|
||||
@ -151,24 +151,24 @@ public class WellDrillingProcessMapReportService : IWellDrillingProcessMapReport
|
||||
}
|
||||
|
||||
subInterval.DepthEnd = interval.DepthEnd;
|
||||
var intervalReportRowLast = CalcSubIntervalReportRow(subInterval, wellDrillingProcessMapInterval,
|
||||
var intervalReportRowLast = CalcSubIntervalReportRow(subInterval, processMapPlanWellDrillingInterval,
|
||||
telemetryDataInterval[telemetryIndexStart..telemetryDataIntervalLength], sectionTypes);
|
||||
result.Add(intervalReportRowLast);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static WellDrillingProcessMapReportDto CalcSubIntervalReportRow(
|
||||
private static ProcessMapReportWellDrillingDto CalcSubIntervalReportRow(
|
||||
(double DepthStart, double DepthEnd) subInterval,
|
||||
IEnumerable<WellDrillingProcessMapDto> wellDrillingProcessMaps,
|
||||
IEnumerable<ProcessMapPlanWellDrillingDto> processMapPlanWellDrillings,
|
||||
Span<TelemetryDataSaubStatDto> telemetryRowSpan,
|
||||
IDictionary<int, string> sectionTypes)
|
||||
{
|
||||
var telemetryStat = new TelemetryStat(telemetryRowSpan);
|
||||
var processMapByMode = wellDrillingProcessMaps.FirstOrDefault(p => p.IdMode == telemetryStat.IdMode);
|
||||
var processMapFirst = wellDrillingProcessMaps.First();
|
||||
var processMapByMode = processMapPlanWellDrillings.FirstOrDefault(p => p.IdMode == telemetryStat.IdMode);
|
||||
var processMapFirst = processMapPlanWellDrillings.First();
|
||||
var idWellSectionType = processMapByMode?.IdWellSectionType ?? processMapFirst.IdWellSectionType;
|
||||
|
||||
var result = new WellDrillingProcessMapReportDto
|
||||
var result = new ProcessMapReportWellDrillingDto
|
||||
{
|
||||
IdWell = processMapByMode?.IdWell ?? processMapFirst.IdWell,
|
||||
IdWellSectionType = idWellSectionType,
|
||||
|
Loading…
Reference in New Issue
Block a user