2024-07-04 11:02:45 +05:00
|
|
|
|
using System;
|
2024-02-20 13:22:58 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
2022-08-04 15:06:17 +05:00
|
|
|
|
using AsbCloudApp.Data.DetectedOperation;
|
2024-02-08 11:38:25 +05:00
|
|
|
|
using AsbCloudApp.Repositories;
|
2022-04-28 15:04:13 +05:00
|
|
|
|
using AsbCloudApp.Requests;
|
|
|
|
|
using AsbCloudApp.Services;
|
|
|
|
|
using AsbCloudDb.Model;
|
|
|
|
|
using Mapster;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2024-03-22 09:29:01 +05:00
|
|
|
|
using AsbCloudApp.Data.WellOperation;
|
2024-04-08 09:26:24 +05:00
|
|
|
|
using AsbCloudApp.Exceptions;
|
2024-02-20 13:22:58 +05:00
|
|
|
|
using AsbCloudInfrastructure.Services.DetectOperations.Detectors;
|
2022-04-28 15:04:13 +05:00
|
|
|
|
|
2024-02-08 11:38:25 +05:00
|
|
|
|
namespace AsbCloudInfrastructure.Services.DetectOperations;
|
2023-04-18 16:22:53 +05:00
|
|
|
|
|
2024-02-08 11:38:25 +05:00
|
|
|
|
public class DetectedOperationService : IDetectedOperationService
|
|
|
|
|
{
|
|
|
|
|
private readonly IDetectedOperationRepository operationRepository;
|
|
|
|
|
private readonly IWellOperationCategoryRepository wellOperationCategoryRepository;
|
|
|
|
|
private readonly IWellService wellService;
|
2024-04-01 11:44:03 +05:00
|
|
|
|
private readonly ITelemetryService telemetryService;
|
2024-02-20 13:22:58 +05:00
|
|
|
|
private readonly IRepositoryWellRelated<OperationValueDto> operationValueRepository;
|
|
|
|
|
private readonly IScheduleRepository scheduleRepository;
|
|
|
|
|
private readonly ITelemetryDataSaubService telemetryDataSaubService;
|
|
|
|
|
|
|
|
|
|
private static readonly DetectorAbstract[] detectors = {
|
|
|
|
|
new DetectorDrilling(),
|
2024-03-15 14:51:13 +05:00
|
|
|
|
new DetectorSlipsTime(),
|
|
|
|
|
new DetectorFlashing(),
|
2024-04-01 09:30:40 +05:00
|
|
|
|
new DetectorConditioning(),
|
2024-02-20 13:22:58 +05:00
|
|
|
|
};
|
2024-07-24 15:19:13 +05:00
|
|
|
|
|
2024-02-08 11:38:25 +05:00
|
|
|
|
public DetectedOperationService(
|
|
|
|
|
IDetectedOperationRepository operationRepository,
|
|
|
|
|
IWellOperationCategoryRepository wellOperationCategoryRepository,
|
|
|
|
|
IWellService wellService,
|
2024-04-01 11:44:03 +05:00
|
|
|
|
ITelemetryService telemetryService,
|
2024-03-18 13:34:31 +05:00
|
|
|
|
IRepositoryWellRelated<OperationValueDto> operationValueRepository,
|
2024-02-20 13:22:58 +05:00
|
|
|
|
IScheduleRepository scheduleRepository,
|
|
|
|
|
ITelemetryDataSaubService telemetryDataSaubService)
|
2022-04-28 15:04:13 +05:00
|
|
|
|
{
|
2024-02-08 11:38:25 +05:00
|
|
|
|
this.operationRepository = operationRepository;
|
|
|
|
|
this.wellOperationCategoryRepository = wellOperationCategoryRepository;
|
|
|
|
|
this.wellService = wellService;
|
2024-04-01 11:44:03 +05:00
|
|
|
|
this.telemetryService = telemetryService;
|
2024-02-20 13:22:58 +05:00
|
|
|
|
this.operationValueRepository = operationValueRepository;
|
|
|
|
|
this.scheduleRepository = scheduleRepository;
|
|
|
|
|
this.telemetryDataSaubService = telemetryDataSaubService;
|
2024-02-08 11:38:25 +05:00
|
|
|
|
}
|
2022-08-04 15:06:17 +05:00
|
|
|
|
|
2024-02-08 11:38:25 +05:00
|
|
|
|
public async Task<DetectedOperationListDto> GetAsync(DetectedOperationByWellRequest request, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var dtos = await GetOperationsAsync(request, token);
|
|
|
|
|
if (dtos?.Any() != true)
|
|
|
|
|
return new DetectedOperationListDto();
|
2022-08-04 15:06:17 +05:00
|
|
|
|
|
2024-02-08 11:38:25 +05:00
|
|
|
|
var stats = GetOperationsDrillersStat(dtos);
|
|
|
|
|
var result = new DetectedOperationListDto
|
2022-04-28 15:04:13 +05:00
|
|
|
|
{
|
2024-02-08 11:38:25 +05:00
|
|
|
|
Operations = dtos,
|
|
|
|
|
Stats = stats
|
|
|
|
|
};
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2022-08-04 15:06:17 +05:00
|
|
|
|
|
2024-02-08 11:38:25 +05:00
|
|
|
|
public async Task<IEnumerable<DetectedOperationWithDrillerDto>> GetOperationsAsync(DetectedOperationByWellRequest request, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var well = await wellService.GetOrDefaultAsync(request.IdWell, token);
|
|
|
|
|
if (well?.IdTelemetry is null)
|
|
|
|
|
return Enumerable.Empty<DetectedOperationWithDrillerDto>();
|
2022-04-28 15:04:13 +05:00
|
|
|
|
|
2024-02-08 11:38:25 +05:00
|
|
|
|
var requestByTelemetry = new DetectedOperationByTelemetryRequest(well.IdTelemetry.Value, request);
|
|
|
|
|
var data = await operationRepository.Get(requestByTelemetry, token);
|
2022-06-15 14:57:37 +05:00
|
|
|
|
|
2024-02-20 13:22:58 +05:00
|
|
|
|
var operationValues = await operationValueRepository.GetByIdWellAsync(request.IdWell, token);
|
|
|
|
|
var schedules = await scheduleRepository.GetByIdWellAsync(request.IdWell, token);
|
2024-02-08 11:38:25 +05:00
|
|
|
|
var dtos = data.Select(o => Convert(o, operationValues, schedules));
|
|
|
|
|
return dtos;
|
|
|
|
|
}
|
2022-11-03 13:30:16 +05:00
|
|
|
|
|
2024-04-08 09:26:24 +05:00
|
|
|
|
public async Task<int> InsertRangeManualAsync(int idEditor, int idWell, IEnumerable<DetectedOperationDto> dtos, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var idTelemetry = await GetIdTelemetryByWell(idWell, token);
|
|
|
|
|
|
|
|
|
|
foreach (var dto in dtos)
|
|
|
|
|
{
|
|
|
|
|
dto.IdEditor = idEditor;
|
|
|
|
|
dto.IdTelemetry = idTelemetry;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return await operationRepository.InsertRangeAsync(dtos, token);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<int> UpdateRangeManualAsync(int idEditor, int idWell, IEnumerable<DetectedOperationDto> dtos, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var idTelemetry = await GetIdTelemetryByWell(idWell, token);
|
|
|
|
|
|
|
|
|
|
foreach (var dto in dtos)
|
|
|
|
|
{
|
|
|
|
|
dto.IdEditor = idEditor;
|
|
|
|
|
dto.IdTelemetry = idTelemetry;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return await operationRepository.UpdateRangeAsync(dtos, token);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task<int> GetIdTelemetryByWell(int idWell, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var well = await wellService.GetOrDefaultAsync(idWell, token) ??
|
|
|
|
|
throw new ArgumentInvalidException(nameof(idWell), "Well doesn`t exist");
|
|
|
|
|
|
|
|
|
|
var idTelemetry = well.IdTelemetry ??
|
|
|
|
|
throw new ArgumentInvalidException(nameof(idWell), "У скважины отсутствует телеметрия");
|
|
|
|
|
|
|
|
|
|
return idTelemetry;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-08 11:38:25 +05:00
|
|
|
|
public async Task<IEnumerable<WellOperationCategoryDto>> GetCategoriesAsync(int? idWell, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
if(idWell is null)
|
2022-08-04 15:06:17 +05:00
|
|
|
|
{
|
2024-02-08 11:38:25 +05:00
|
|
|
|
return wellOperationCategoryRepository.Get(false);
|
2022-08-04 15:06:17 +05:00
|
|
|
|
}
|
2024-02-08 11:38:25 +05:00
|
|
|
|
else
|
2022-08-04 15:06:17 +05:00
|
|
|
|
{
|
2024-02-08 11:38:25 +05:00
|
|
|
|
var well = await wellService.GetOrDefaultAsync((int )idWell, token);
|
|
|
|
|
if (well?.IdTelemetry is null)
|
|
|
|
|
return Enumerable.Empty<WellOperationCategoryDto>();
|
2022-08-04 15:06:17 +05:00
|
|
|
|
|
2024-03-18 13:34:31 +05:00
|
|
|
|
var request = new DetectedOperationByTelemetryRequest()
|
|
|
|
|
{
|
|
|
|
|
IdTelemetry = well.IdTelemetry.Value
|
2024-02-08 11:38:25 +05:00
|
|
|
|
};
|
2022-08-04 15:06:17 +05:00
|
|
|
|
|
2024-02-08 11:38:25 +05:00
|
|
|
|
var operations = await operationRepository.Get(request, token);
|
|
|
|
|
var categories = operations
|
|
|
|
|
.Select(o => o.OperationCategory)
|
|
|
|
|
.Distinct();
|
|
|
|
|
return categories;
|
2022-04-28 15:04:13 +05:00
|
|
|
|
}
|
2024-02-08 11:38:25 +05:00
|
|
|
|
}
|
2022-04-28 15:04:13 +05:00
|
|
|
|
|
2024-04-22 17:31:27 +05:00
|
|
|
|
[Obsolete]
|
2024-02-08 11:38:25 +05:00
|
|
|
|
public async Task<IEnumerable<DetectedOperationStatDto>> GetOperationsStatAsync(DetectedOperationByWellRequest request, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var well = await wellService.GetOrDefaultAsync(request.IdWell, token);
|
|
|
|
|
if (well?.IdTelemetry is null || well.Timezone is null)
|
|
|
|
|
return Enumerable.Empty<DetectedOperationStatDto>();
|
2022-08-04 15:06:17 +05:00
|
|
|
|
|
2024-02-08 11:38:25 +05:00
|
|
|
|
var requestByTelemetry = new DetectedOperationByTelemetryRequest(well.IdTelemetry.Value, request);
|
2022-04-28 15:04:13 +05:00
|
|
|
|
|
2024-02-08 11:38:25 +05:00
|
|
|
|
var operations = await operationRepository.Get(requestByTelemetry, token);
|
2022-06-14 15:35:31 +05:00
|
|
|
|
|
2024-02-08 11:38:25 +05:00
|
|
|
|
if (!operations.Any())
|
|
|
|
|
return Enumerable.Empty<DetectedOperationStatDto>();
|
2024-03-18 13:34:31 +05:00
|
|
|
|
|
2024-02-08 11:38:25 +05:00
|
|
|
|
var dtos = operations
|
|
|
|
|
.GroupBy(o => (o.IdCategory, o.OperationCategory.Name))
|
|
|
|
|
.OrderBy(g => g.Key)
|
|
|
|
|
.Select(g => new DetectedOperationStatDto
|
2022-04-28 15:04:13 +05:00
|
|
|
|
{
|
2024-02-08 11:38:25 +05:00
|
|
|
|
IdCategory = g.Key.IdCategory,
|
|
|
|
|
Category = g.Key.Name,
|
|
|
|
|
Count = g.Count(),
|
|
|
|
|
MinutesAverage = g.Average(o => o.DurationMinutes),
|
|
|
|
|
MinutesMin = g.Min(o => o.DurationMinutes),
|
|
|
|
|
MinutesMax = g.Max(o => o.DurationMinutes),
|
|
|
|
|
MinutesTotal = g.Sum(o => o.DurationMinutes),
|
|
|
|
|
ValueAverage = g.Average(o => o.Value),
|
|
|
|
|
ValueMax = g.Max(o => o.Value),
|
|
|
|
|
ValueMin = g.Min(o => o.Value),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return dtos;
|
|
|
|
|
}
|
2022-04-28 15:04:13 +05:00
|
|
|
|
|
2024-07-24 15:19:13 +05:00
|
|
|
|
public async Task<(DateTimeOffset LastDate, IEnumerable<DetectedOperationDto> Items)> DetectOperationsAsync(int idTelemetry,
|
|
|
|
|
TelemetryDataRequest request,
|
|
|
|
|
DetectedOperationDto? lastDetectedOperation,
|
|
|
|
|
CancellationToken token)
|
2024-02-20 13:22:58 +05:00
|
|
|
|
{
|
|
|
|
|
const int minOperationLength = 5;
|
|
|
|
|
const int maxDetectorsInterpolationFrameLength = 30;
|
|
|
|
|
const int gap = maxDetectorsInterpolationFrameLength + minOperationLength;
|
2024-07-24 15:19:13 +05:00
|
|
|
|
|
|
|
|
|
var telemetries = await telemetryDataSaubService.GetByTelemetryAsync(idTelemetry, request, token);
|
|
|
|
|
|
|
|
|
|
var count = telemetries.Count();
|
|
|
|
|
|
|
|
|
|
if (count == 0)
|
|
|
|
|
throw new InvalidOperationException("InvalidOperation_EmptyTelemetries");
|
|
|
|
|
|
2024-04-01 11:44:03 +05:00
|
|
|
|
var timezone = telemetryService.GetTimezone(idTelemetry);
|
2024-03-18 13:34:31 +05:00
|
|
|
|
|
2024-07-24 15:19:13 +05:00
|
|
|
|
if (telemetries.Count() <= gap)
|
2024-02-20 13:22:58 +05:00
|
|
|
|
{
|
2024-07-24 15:19:13 +05:00
|
|
|
|
var lastTelemetry = telemetries.Last();
|
|
|
|
|
var lastDateTelemetry = new DateTimeOffset(lastTelemetry.DateTime, timezone.Offset);
|
|
|
|
|
return (lastDateTelemetry, Enumerable.Empty<DetectedOperationDto>());
|
|
|
|
|
}
|
2024-03-18 13:34:31 +05:00
|
|
|
|
|
2024-07-24 15:19:13 +05:00
|
|
|
|
var detectedOperations = new List<DetectedOperationDto>();
|
2024-02-20 13:22:58 +05:00
|
|
|
|
|
2024-07-26 16:20:46 +05:00
|
|
|
|
var detectableTelemetries = telemetries
|
|
|
|
|
.Where(t => t.BlockPosition >= 0)
|
|
|
|
|
.Select(t => new DetectableTelemetry
|
|
|
|
|
{
|
|
|
|
|
DateTime = new DateTimeOffset(t.DateTime, timezone.Offset),
|
|
|
|
|
IdUser = t.IdUser,
|
|
|
|
|
Mode = t.Mode,
|
|
|
|
|
WellDepth = t.WellDepth,
|
|
|
|
|
Pressure = t.Pressure,
|
|
|
|
|
HookWeight = t.HookWeight,
|
|
|
|
|
BlockPosition = t.BlockPosition,
|
|
|
|
|
BitDepth = t.BitDepth,
|
|
|
|
|
RotorSpeed = t.RotorSpeed,
|
|
|
|
|
AxialLoad = t.AxialLoad,
|
|
|
|
|
}).ToArray();
|
2024-07-24 15:19:13 +05:00
|
|
|
|
|
|
|
|
|
var positionBegin = 0;
|
|
|
|
|
var positionEnd = detectableTelemetries.Length - gap;
|
|
|
|
|
|
|
|
|
|
while (positionEnd > positionBegin)
|
|
|
|
|
{
|
|
|
|
|
foreach (var detector in detectors)
|
2024-02-20 13:22:58 +05:00
|
|
|
|
{
|
2024-07-24 15:19:13 +05:00
|
|
|
|
if (!detector.TryDetect(idTelemetry, detectableTelemetries, positionBegin, positionEnd, lastDetectedOperation,
|
|
|
|
|
out var result))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
detectedOperations.Add(result!.Operation);
|
|
|
|
|
lastDetectedOperation = result.Operation;
|
|
|
|
|
positionBegin = result.TelemetryEnd;
|
|
|
|
|
break;
|
2024-02-20 13:22:58 +05:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-26 15:11:03 +05:00
|
|
|
|
var skip = 1;
|
|
|
|
|
|
|
|
|
|
while (IsChangingTelemetryInterval(detectableTelemetries[positionBegin], detectableTelemetries[positionBegin + skip]))
|
|
|
|
|
skip++;
|
|
|
|
|
|
|
|
|
|
positionBegin += skip;
|
2024-02-20 13:22:58 +05:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-25 14:49:53 +05:00
|
|
|
|
return (detectableTelemetries[positionBegin].DateTime, detectedOperations);
|
2024-02-20 13:22:58 +05:00
|
|
|
|
}
|
|
|
|
|
|
2024-02-08 11:38:25 +05:00
|
|
|
|
public async Task<int> DeleteAsync(DetectedOperationByWellRequest request, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var well = await wellService.GetOrDefaultAsync(request.IdWell, token);
|
|
|
|
|
if (well?.IdTelemetry is null || well.Timezone is null)
|
|
|
|
|
return 0;
|
2022-04-28 15:04:13 +05:00
|
|
|
|
|
2024-02-08 11:38:25 +05:00
|
|
|
|
var requestByTelemetry = new DetectedOperationByTelemetryRequest(well.IdTelemetry.Value, request);
|
2024-04-08 09:26:24 +05:00
|
|
|
|
var result = await operationRepository.DeleteAsync(requestByTelemetry, token);
|
2024-02-08 11:38:25 +05:00
|
|
|
|
return result;
|
|
|
|
|
}
|
2022-04-28 15:04:13 +05:00
|
|
|
|
|
2024-07-26 15:11:03 +05:00
|
|
|
|
private static bool IsChangingTelemetryInterval(DetectableTelemetry telemetryBegin, DetectableTelemetry telemetryEnd)
|
|
|
|
|
{
|
|
|
|
|
return telemetryBegin.Mode == telemetryEnd.Mode &&
|
|
|
|
|
EqualParameter(telemetryBegin.WellDepth, telemetryEnd.WellDepth, 0.01f) &&
|
|
|
|
|
EqualParameter(telemetryBegin.Pressure, telemetryEnd.Pressure, 0.1f) &&
|
|
|
|
|
EqualParameter(telemetryBegin.HookWeight, telemetryEnd.HookWeight, 0.1f) &&
|
|
|
|
|
EqualParameter(telemetryBegin.BlockPosition, telemetryEnd.BlockPosition, 0.01f) &&
|
|
|
|
|
EqualParameter(telemetryBegin.BitDepth, telemetryEnd.BitDepth, 0.01f) &&
|
|
|
|
|
EqualParameter(telemetryBegin.RotorSpeed, telemetryEnd.RotorSpeed, 0.01f) &&
|
|
|
|
|
EqualParameter(telemetryBegin.AxialLoad, telemetryEnd.AxialLoad, 0.1f);
|
|
|
|
|
|
|
|
|
|
bool EqualParameter(float value, float origin, float tolerance) =>
|
|
|
|
|
value <= origin + tolerance && value >= origin - tolerance;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-08 11:38:25 +05:00
|
|
|
|
private static IEnumerable<DetectedOperationDrillersStatDto> GetOperationsDrillersStat(IEnumerable<DetectedOperationWithDrillerDto> operations)
|
|
|
|
|
{
|
|
|
|
|
var groups = operations.GroupBy(o => o.Driller);
|
2023-12-05 10:56:49 +05:00
|
|
|
|
|
2024-02-08 11:38:25 +05:00
|
|
|
|
var stats = new List<DetectedOperationDrillersStatDto>(groups.Count());
|
|
|
|
|
foreach (var group in groups)
|
2023-12-05 10:56:49 +05:00
|
|
|
|
{
|
2024-02-08 11:38:25 +05:00
|
|
|
|
var itemsWithTarget = group.Where(i => i.OperationValue is not null);
|
|
|
|
|
var stat = new DetectedOperationDrillersStatDto
|
|
|
|
|
{
|
|
|
|
|
Driller = group.Key,
|
|
|
|
|
AverageValue = group.Sum(e => e.Value) / group.Count(),
|
|
|
|
|
Count = group.Count(),
|
|
|
|
|
};
|
|
|
|
|
if (itemsWithTarget.Any())
|
2022-04-28 15:04:13 +05:00
|
|
|
|
{
|
2024-02-08 11:38:25 +05:00
|
|
|
|
var itemsOutOfTarget = itemsWithTarget.Where(o => !IsTargetOk(o));
|
|
|
|
|
stat.AverageTargetValue = itemsWithTarget.Average(e => e.OperationValue?.TargetValue);
|
|
|
|
|
stat.Efficiency = 100d * itemsOutOfTarget.Count() / itemsWithTarget.Count();
|
|
|
|
|
stat.Loss = itemsOutOfTarget.Sum(DeltaToTarget);
|
2022-04-28 15:04:13 +05:00
|
|
|
|
}
|
|
|
|
|
|
2024-02-08 11:38:25 +05:00
|
|
|
|
stats.Add(stat);
|
2022-04-28 15:04:13 +05:00
|
|
|
|
}
|
2024-02-08 11:38:25 +05:00
|
|
|
|
return stats;
|
|
|
|
|
}
|
2022-04-28 15:04:13 +05:00
|
|
|
|
|
2024-02-08 11:38:25 +05:00
|
|
|
|
private static bool IsTargetOk(DetectedOperationWithDrillerDto op)
|
|
|
|
|
{
|
|
|
|
|
return (op.IdCategory) switch
|
2022-04-28 15:04:13 +05:00
|
|
|
|
{
|
2024-02-08 11:38:25 +05:00
|
|
|
|
WellOperationCategory.IdRotor => op.Value > op.OperationValue?.TargetValue,
|
|
|
|
|
WellOperationCategory.IdSlide => op.Value > op.OperationValue?.TargetValue,
|
|
|
|
|
WellOperationCategory.IdSlipsTime => op.Value > op.OperationValue?.TargetValue,
|
|
|
|
|
_ => op.Value > op.OperationValue?.TargetValue,
|
|
|
|
|
};
|
|
|
|
|
}
|
2022-04-28 15:04:13 +05:00
|
|
|
|
|
2024-02-08 11:38:25 +05:00
|
|
|
|
private static double DeltaToTarget(DetectedOperationWithDrillerDto op)
|
|
|
|
|
{
|
|
|
|
|
return (op.IdCategory) switch
|
2022-04-28 15:04:13 +05:00
|
|
|
|
{
|
2024-02-08 11:38:25 +05:00
|
|
|
|
WellOperationCategory.IdRotor => 0,
|
|
|
|
|
WellOperationCategory.IdSlide => 0,
|
|
|
|
|
WellOperationCategory.IdSlipsTime => op.Value - op.OperationValue?.TargetValue??0,
|
|
|
|
|
_ => 0,
|
|
|
|
|
};
|
2022-04-28 15:04:13 +05:00
|
|
|
|
}
|
2023-04-18 16:22:53 +05:00
|
|
|
|
|
2024-02-08 11:38:25 +05:00
|
|
|
|
|
|
|
|
|
private static DetectedOperationWithDrillerDto Convert(DetectedOperationDto operation, IEnumerable<OperationValueDto> operationValues, IEnumerable<ScheduleDto> schedules)
|
|
|
|
|
{
|
|
|
|
|
var dto = operation.Adapt<DetectedOperationWithDrillerDto>();
|
|
|
|
|
dto.OperationValue = operationValues.FirstOrDefault(v => v.IdOperationCategory == dto.IdCategory
|
|
|
|
|
&& v.DepthStart <= dto.DepthStart
|
|
|
|
|
&& v.DepthEnd > dto.DepthStart);
|
|
|
|
|
|
2024-03-22 17:15:11 +05:00
|
|
|
|
var dateStart = dto.DateStart.ToUniversalTime();
|
2024-02-08 11:38:25 +05:00
|
|
|
|
var timeStart = new TimeDto(dateStart);
|
|
|
|
|
var driller = schedules.FirstOrDefault(s =>
|
|
|
|
|
s.DrillStart <= dateStart &&
|
|
|
|
|
s.DrillEnd > dateStart && (
|
|
|
|
|
s.ShiftStart > s.ShiftEnd
|
|
|
|
|
) ^ (s.ShiftStart <= timeStart &&
|
|
|
|
|
s.ShiftEnd > timeStart
|
|
|
|
|
))
|
|
|
|
|
?.Driller;
|
|
|
|
|
dto.Driller = driller;
|
|
|
|
|
|
|
|
|
|
return dto;
|
|
|
|
|
}
|
2022-04-28 15:04:13 +05:00
|
|
|
|
}
|