2023-04-03 14:59:59 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
|
|
|
|
using AsbCloudApp.Data.ProcessMap;
|
|
|
|
|
using AsbCloudApp.Data.SAUB;
|
|
|
|
|
using AsbCloudApp.Exceptions;
|
|
|
|
|
using AsbCloudApp.Repositories;
|
|
|
|
|
using AsbCloudApp.Requests;
|
2022-12-14 08:41:19 +05:00
|
|
|
|
using AsbCloudApp.Services;
|
2023-04-03 14:59:59 +05:00
|
|
|
|
using AsbCloudApp.Services.Subsystems;
|
|
|
|
|
using AsbCloudDb.Model;
|
|
|
|
|
using AsbCloudApp.Data.Subsystems;
|
|
|
|
|
using System;
|
2022-12-14 08:41:19 +05:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace AsbCloudInfrastructure.Services.ProcessMap
|
|
|
|
|
{
|
2022-12-27 14:30:52 +05:00
|
|
|
|
#nullable enable
|
2023-04-03 14:59:59 +05:00
|
|
|
|
public partial class ProcessMapReportService : IProcessMapReportService
|
2022-12-14 08:41:19 +05:00
|
|
|
|
{
|
2023-04-03 14:59:59 +05:00
|
|
|
|
private readonly IWellService wellService;
|
|
|
|
|
private readonly IWellOperationRepository wellOperationRepository;
|
|
|
|
|
private readonly IProcessMapPlanRepository processMapPlanRepository;
|
|
|
|
|
private readonly ITelemetryDataSaubService telemetryDataSaubService;
|
|
|
|
|
private readonly ILimitingParameterRepository limitingParameterRepository;
|
|
|
|
|
private readonly ISubsystemOperationTimeService subsystemOperationTimeService;
|
|
|
|
|
|
|
|
|
|
public ProcessMapReportService(
|
|
|
|
|
IWellService wellService,
|
|
|
|
|
IWellOperationRepository wellOperationService,
|
|
|
|
|
IProcessMapPlanRepository processMapPlanRepository,
|
|
|
|
|
ITelemetryDataSaubService telemetryDataSaubService,
|
|
|
|
|
ILimitingParameterRepository limitingParameterRepository,
|
|
|
|
|
ISubsystemOperationTimeService subsystemOperationTimeService)
|
2022-12-14 08:41:19 +05:00
|
|
|
|
{
|
2023-04-03 14:59:59 +05:00
|
|
|
|
this.wellService = wellService;
|
|
|
|
|
this.wellOperationRepository = wellOperationService;
|
|
|
|
|
this.processMapPlanRepository = processMapPlanRepository;
|
|
|
|
|
this.telemetryDataSaubService = telemetryDataSaubService;
|
|
|
|
|
this.limitingParameterRepository = limitingParameterRepository;
|
|
|
|
|
this.subsystemOperationTimeService = subsystemOperationTimeService;
|
2023-01-17 08:56:07 +05:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-03 14:59:59 +05:00
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
public async Task<IEnumerable<ProcessMapReportDto>> GetProcessMapAsync(int idWell, CancellationToken token)
|
2023-01-17 08:56:07 +05:00
|
|
|
|
{
|
2023-04-03 14:59:59 +05:00
|
|
|
|
var well = wellService.GetOrDefault(idWell)
|
|
|
|
|
?? throw new ArgumentInvalidException("idWell not found", nameof(idWell));
|
2023-01-17 08:56:07 +05:00
|
|
|
|
|
2023-04-03 14:59:59 +05:00
|
|
|
|
var idTelemetry = well.IdTelemetry
|
|
|
|
|
?? throw new ArgumentInvalidException("telemetry by well not found", nameof(idWell));
|
2023-02-06 13:13:23 +05:00
|
|
|
|
|
2023-04-03 14:59:59 +05:00
|
|
|
|
var processMapPlan = await processMapPlanRepository.GetByIdWellAsync(idWell, token);
|
2023-01-17 08:56:07 +05:00
|
|
|
|
|
2023-04-03 14:59:59 +05:00
|
|
|
|
if(!processMapPlan.Any())
|
|
|
|
|
return Enumerable.Empty<ProcessMapReportDto>();
|
2023-01-17 08:56:07 +05:00
|
|
|
|
|
2023-04-03 14:59:59 +05:00
|
|
|
|
var telemetryDataStat = await telemetryDataSaubService.GetTelemetryDataStatAsync(idTelemetry, token);
|
2023-01-17 08:56:07 +05:00
|
|
|
|
|
2023-04-03 14:59:59 +05:00
|
|
|
|
var result = CalcByIntervals(processMapPlan, telemetryDataStat);
|
2023-01-17 08:56:07 +05:00
|
|
|
|
|
2023-04-03 14:59:59 +05:00
|
|
|
|
return result;
|
2023-01-17 08:56:07 +05:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-03 14:59:59 +05:00
|
|
|
|
private IEnumerable<ProcessMapReportDto> CalcByIntervals(IEnumerable<ProcessMapPlanDto> processMapPlan, IEnumerable<TelemetryDataSaubStatDto> telemetryDataStat)
|
2023-01-17 08:56:07 +05:00
|
|
|
|
{
|
2023-04-03 14:59:59 +05:00
|
|
|
|
var result = new List<ProcessMapReportDto>(processMapPlan.Count() * 4);
|
|
|
|
|
var intervals = GetProcessMapIntervals(processMapPlan);
|
2023-01-17 08:56:07 +05:00
|
|
|
|
|
2023-04-03 14:59:59 +05:00
|
|
|
|
return result;
|
2023-01-17 08:56:07 +05:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-03 14:59:59 +05:00
|
|
|
|
private IEnumerable<(double, double)> GetProcessMapIntervals(IEnumerable<ProcessMapPlanDto> processMapPlan)
|
2023-01-17 08:56:07 +05:00
|
|
|
|
{
|
2023-04-03 14:59:59 +05:00
|
|
|
|
|
|
|
|
|
return Enumerable.Empty<(double, double)>();
|
2022-12-14 08:41:19 +05:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-03 14:59:59 +05:00
|
|
|
|
private static DateTime GetInterpolatedDate(WellOperationDto operation, double depth)
|
2022-12-14 08:41:19 +05:00
|
|
|
|
{
|
2023-04-03 14:59:59 +05:00
|
|
|
|
var ratio = (depth - operation.DepthStart) / (operation.DepthEnd - operation.DepthStart);
|
|
|
|
|
var deltaHours = operation.DurationHours * ratio;
|
|
|
|
|
var interpolatedDate = operation.DateStart + TimeSpan.FromHours(deltaHours);
|
|
|
|
|
return interpolatedDate;
|
2022-12-27 14:30:52 +05:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-03 14:59:59 +05:00
|
|
|
|
private static IEnumerable<(double min, double max)> SplitByIntervals(double min, double max)
|
2022-12-27 14:30:52 +05:00
|
|
|
|
{
|
2023-04-03 14:59:59 +05:00
|
|
|
|
const double step = 100;
|
|
|
|
|
var iMin = min;
|
|
|
|
|
var iMax = (1 + (int)(min / step)) * step;
|
|
|
|
|
for (; iMax < max; iMax += step)
|
|
|
|
|
{
|
|
|
|
|
yield return (iMin, iMax);
|
|
|
|
|
iMin = iMax;
|
|
|
|
|
}
|
|
|
|
|
yield return (iMin, max);
|
2022-12-14 08:41:19 +05:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-12-27 14:30:52 +05:00
|
|
|
|
#nullable disable
|
2023-04-03 14:59:59 +05:00
|
|
|
|
}
|