Правки по результатам:

- правки алгоритмов от Димы З.
- ревью от Димы С
This commit is contained in:
Olga Nemt 2024-03-18 13:34:31 +05:00
parent ee22d1c487
commit cfb31fcbed
5 changed files with 53 additions and 61 deletions

View File

@ -4,8 +4,19 @@ namespace AsbCloudInfrastructure.Services.DetectOperations;
public class DetectableTelemetry public class DetectableTelemetry
{ {
/// <summary>
/// Дата начала
/// </summary>
public DateTimeOffset DateTime { get; set; } public DateTimeOffset DateTime { get; set; }
/// <summary>
/// Режим
/// </summary>
public int Mode { get; set; } public int Mode { get; set; }
/// <summary>
/// Ключ пользователя
/// </summary>
public int? IdUser { get; set; } public int? IdUser { get; set; }
/// <summary> /// <summary>

View File

@ -28,12 +28,12 @@ public class DetectedOperationService : IDetectedOperationService
new DetectorSlipsTime(), new DetectorSlipsTime(),
new DetectorFlashing(), new DetectorFlashing(),
}; };
public DetectedOperationService( public DetectedOperationService(
IDetectedOperationRepository operationRepository, IDetectedOperationRepository operationRepository,
IWellOperationCategoryRepository wellOperationCategoryRepository, IWellOperationCategoryRepository wellOperationCategoryRepository,
IWellService wellService, IWellService wellService,
IRepositoryWellRelated<OperationValueDto> operationValueRepository, IRepositoryWellRelated<OperationValueDto> operationValueRepository,
IScheduleRepository scheduleRepository, IScheduleRepository scheduleRepository,
ITelemetryDataSaubService telemetryDataSaubService) ITelemetryDataSaubService telemetryDataSaubService)
{ {
@ -87,9 +87,9 @@ public class DetectedOperationService : IDetectedOperationService
if (well?.IdTelemetry is null) if (well?.IdTelemetry is null)
return Enumerable.Empty<WellOperationCategoryDto>(); return Enumerable.Empty<WellOperationCategoryDto>();
var request = new DetectedOperationByTelemetryRequest() var request = new DetectedOperationByTelemetryRequest()
{ {
IdTelemetry = well.IdTelemetry.Value IdTelemetry = well.IdTelemetry.Value
}; };
var operations = await operationRepository.Get(request, token); var operations = await operationRepository.Get(request, token);
@ -112,7 +112,7 @@ public class DetectedOperationService : IDetectedOperationService
if (!operations.Any()) if (!operations.Any())
return Enumerable.Empty<DetectedOperationStatDto>(); return Enumerable.Empty<DetectedOperationStatDto>();
var dtos = operations var dtos = operations
.GroupBy(o => (o.IdCategory, o.OperationCategory.Name)) .GroupBy(o => (o.IdCategory, o.OperationCategory.Name))
.OrderBy(g => g.Key) .OrderBy(g => g.Key)
@ -136,58 +136,58 @@ public class DetectedOperationService : IDetectedOperationService
public async Task<IEnumerable<DetectedOperationDto>> DetectOperationsAsync(int idTelemetry, DateTimeOffset? beginDate, CancellationToken token) public async Task<IEnumerable<DetectedOperationDto>> DetectOperationsAsync(int idTelemetry, DateTimeOffset? beginDate, CancellationToken token)
{ {
const int take = 4 * 86_400; const int take = 4 * 86_400;
var detectedOperations = new List<DetectedOperationDto>(); var detectedOperations = new List<DetectedOperationDto>();
DetectedOperationDto? lastDetectedOperation = null; DetectedOperationDto? lastDetectedOperation = null;
const int minOperationLength = 5; const int minOperationLength = 5;
const int maxDetectorsInterpolationFrameLength = 30; const int maxDetectorsInterpolationFrameLength = 30;
const int gap = maxDetectorsInterpolationFrameLength + minOperationLength; const int gap = maxDetectorsInterpolationFrameLength + minOperationLength;
while (true) while (true)
{ {
var request = new TelemetryDataRequest var request = new TelemetryDataRequest
{ {
GeDate = beginDate, GeDate = beginDate,
Take = take, Take = take,
Order = 0 Order = 0
}; };
var detectableTelemetries = (await telemetryDataSaubService.GetByTelemetryAsync(idTelemetry, request, token)) var detectableTelemetries = (await telemetryDataSaubService.GetByTelemetryAsync(idTelemetry, request, token))
.Where(t => t.BlockPosition >= 0) .Where(t => t.BlockPosition >= 0)
.Select(t => new DetectableTelemetry .Select(t => new DetectableTelemetry
{ {
DateTime = t.DateTime, DateTime = t.DateTime,
IdUser = t.IdUser, IdUser = t.IdUser,
Mode = t.Mode, Mode = t.Mode,
WellDepth = t.WellDepth, WellDepth = t.WellDepth,
Pressure = t.Pressure, Pressure = t.Pressure,
HookWeight = t.HookWeight, HookWeight = t.HookWeight,
BlockPosition = t.BlockPosition, BlockPosition = t.BlockPosition,
BitDepth = t.BitDepth, BitDepth = t.BitDepth,
RotorSpeed = t.RotorSpeed, RotorSpeed = t.RotorSpeed,
AxialLoad = t.AxialLoad, AxialLoad = t.AxialLoad,
}).ToArray(); }).ToArray();
if (detectableTelemetries.Length <= gap) if (detectableTelemetries.Length <= gap)
break; break;
var isDetected = false; var isDetected = false;
var positionBegin = 0; var positionBegin = 0;
var positionEnd = detectableTelemetries.Length - gap; var positionEnd = detectableTelemetries.Length - gap;
while (positionEnd > positionBegin) while (positionEnd > positionBegin)
{ {
foreach (var detector in detectors) foreach (var detector in detectors)
{ {
if (!detector.TryDetect(idTelemetry, detectableTelemetries, positionBegin, positionEnd, lastDetectedOperation, out var result)) if (!detector.TryDetect(idTelemetry, detectableTelemetries, positionBegin, positionEnd, lastDetectedOperation, out var result))
continue; continue;
detectedOperations.Add(result!.Operation); detectedOperations.Add(result!.Operation);
lastDetectedOperation = result.Operation; lastDetectedOperation = result.Operation;
isDetected = true; isDetected = true;
positionBegin = result.TelemetryEnd; positionBegin = result.TelemetryEnd;
break; break;
} }
positionBegin += 1; positionBegin += 1;
} }
@ -264,7 +264,7 @@ public class DetectedOperationService : IDetectedOperationService
dto.OperationValue = operationValues.FirstOrDefault(v => v.IdOperationCategory == dto.IdCategory dto.OperationValue = operationValues.FirstOrDefault(v => v.IdOperationCategory == dto.IdCategory
&& v.DepthStart <= dto.DepthStart && v.DepthStart <= dto.DepthStart
&& v.DepthEnd > dto.DepthStart); && v.DepthEnd > dto.DepthStart);
var dateStart = dto.DateStart; var dateStart = dto.DateStart;
var timeStart = new TimeDto(dateStart); var timeStart = new TimeDto(dateStart);
var driller = schedules.FirstOrDefault(s => var driller = schedules.FirstOrDefault(s =>

View File

@ -19,14 +19,14 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
{ {
var currentPoint = telemetry[position]; var currentPoint = telemetry[position];
if (currentPoint.Pressure <= 10) if (currentPoint.Pressure < 10)
return false; return false;
var delta = currentPoint.WellDepth - currentPoint.BitDepth; var delta = currentPoint.WellDepth - currentPoint.BitDepth;
if (delta < 0.03d) if (delta < 0.03d)
return false; return false;
if (currentPoint.RotorSpeed > 10.5) if (currentPoint.RotorSpeed > 8)
return false; return false;
var nextIndexPoint = telemetry.Length <= position ? position : position + 1; var nextIndexPoint = telemetry.Length <= position ? position : position + 1;
@ -34,7 +34,7 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
if (Math.Abs(currentPoint.WellDepth - nextPoint.WellDepth) > 0) if (Math.Abs(currentPoint.WellDepth - nextPoint.WellDepth) > 0)
return false; return false;
if (currentPoint.BitDepth <= 150) if (currentPoint.BitDepth < 150)
return false; return false;
return true; return true;
@ -49,7 +49,7 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
return IdReasonOfEnd_PressureIsLo; return IdReasonOfEnd_PressureIsLo;
if ((currentPoint.WellDepth - currentPoint.BitDepth) < 0.03d) if ((currentPoint.WellDepth - currentPoint.BitDepth) < 0.03d)
return IdReasonOfEnd_DeltaWellDepthAndBithDepthIsLo; return IdReasonOfEnd_DeltaWellDepthAndBithDepthIsLo;
if (currentPoint.RotorSpeed > 10.5) if (currentPoint.RotorSpeed > 8)
return IdReasonOfEnd_RotorSpeedIsHi; return IdReasonOfEnd_RotorSpeedIsHi;
if (currentPoint.BitDepth < 150) if (currentPoint.BitDepth < 150)
return IdReasonOfEnd_BithDepthIsLo; return IdReasonOfEnd_BithDepthIsLo;

View File

@ -5,26 +5,22 @@
Промывка операция, во время которой давление условно постоянное, а вращение колонны отсутствует, талевый блок при этом может быть как в движении, так и статичным. Промывка операция, во время которой давление условно постоянное, а вращение колонны отсутствует, талевый блок при этом может быть как в движении, так и статичным.
Промывка определяется как время между: Промывка определяется как время между:
- окончанием операции бурения или выходом на режим буровых насосов - окончанием операции бурения или выходом на режим буровых насосов (рост давления)
- началом операции проработки/шаблонировки перед наращиванием или остановкой буровых насосов - началом операции проработки/шаблонировки перед наращиванием или остановкой буровых насосов (снижение давления).
## Метод определения ## Метод определения
Признак начала операции = Признак начала операции =
( давление > 10 атм ) И ( давление >= 10 атм ) И
( обороты ротора <= 10.5 об/мин) И ( обороты ротора <= 8 об/мин) И
( расстояние от долота до забоя >= 0.03 м) И ( расстояние от долота до забоя >= 0.03 м) И
( глубина забоя не изменяется) И ( глубина забоя не изменяется) И
( глубина долота > 150 м) И ( глубина долота >= 150 м);
( положение блока не меняется) ИЛИ
( положение блока уменьшается) ИЛИ
( положение блока увеличивается --> дальше смотрим: если после остановки блока обороты ротора <= 10.5 об/мин);
Признак окончания операции = Признак окончания операции =
( давление < 10 атм ) ИЛИ ( давление < 10 атм ) ИЛИ
( расстояние от долота до забоя < 0.03 м ) ИЛИ ( расстояние от долота до забоя < 0.03 м ) ИЛИ
( обороты ротора > 10.5 об/мин) ИЛИ ( обороты ротора > 8 об/мин) ИЛИ
( положение блока увеличивается --> дальше смотрим: если после остановки блока обороты ротора > 10.5 об/мин) ИЛИ
( глубина долота < 150 м); ( глубина долота < 150 м);

View File

@ -20,16 +20,11 @@ public class DetectorFlashingTests : DetectorFlashing
Pressure = 21, Pressure = 21,
WellDepth = 152, WellDepth = 152,
BitDepth = 151, BitDepth = 151,
RotorSpeed = 9, RotorSpeed = 8,
DateTime = System.DateTimeOffset.Now DateTime = System.DateTimeOffset.Now
}; };
/// <summary>
/// Тестирование операций, попадающей под автоопределение операции промывки, при этом
/// - найден признак начала операции
/// - не найден признак окончания операции
/// </summary>
[Fact] [Fact]
public void DetectOperation_find_startOperation_notFind_endOperation() public void DetectOperation_find_startOperation_notFind_endOperation()
{ {
@ -50,9 +45,6 @@ public class DetectorFlashingTests : DetectorFlashing
Assert.Equal(IdReasonOfEnd_NotDetected, result.Operation.ExtraData["IdReasonOfEnd"]); Assert.Equal(IdReasonOfEnd_NotDetected, result.Operation.ExtraData["IdReasonOfEnd"]);
} }
/// <summary>
/// Операция, у которой глубина долота = 150м, не является промывкой
/// </summary>
[Fact] [Fact]
public void DetectOperation_with_BitDepth_LE_150_is_fail() public void DetectOperation_with_BitDepth_LE_150_is_fail()
{ {
@ -70,13 +62,12 @@ public class DetectorFlashingTests : DetectorFlashing
//assert //assert
Assert.False(isDetectOperation); Assert.False(isDetectOperation);
Assert.Null(result); Assert.NotNull(result);
Assert.Equal(WellOperationCategory.IdFlashing, result.Operation.IdCategory);
Assert.Equal(IdReasonOfEnd_NotDetected, result.Operation.ExtraData["IdReasonOfEnd"]);
} }
/// <summary>
/// Операция, у которой меняется глубина забоя, не является промывкой
/// </summary>
[Fact] [Fact]
public void DetectOperation_with_DeltaWellDepth_NotEqual_0_is_fail() public void DetectOperation_with_DeltaWellDepth_NotEqual_0_is_fail()
{ {
@ -95,12 +86,8 @@ public class DetectorFlashingTests : DetectorFlashing
Assert.Null(result); Assert.Null(result);
} }
/// <summary>
/// Найдены начальная и конечная операции промывки,
/// Признак окончания операции - снижение давления менее 10 атм
/// </summary>
[Fact] [Fact]
public void DetectOperations_Begin_And_End_by_Pressure_Less_20_is_success() public void DetectOperations_Begin_And_End_by_Pressure_Less_10_is_success()
{ {
//arrange //arrange
var point0 = telemetry.Copy(); var point0 = telemetry.Copy();
@ -120,6 +107,4 @@ public class DetectorFlashingTests : DetectorFlashing
Assert.Equal(WellOperationCategory.IdFlashing, result.Operation.IdCategory); Assert.Equal(WellOperationCategory.IdFlashing, result.Operation.IdCategory);
Assert.Equal(IdReasonOfEnd_PressureIsLo, result.Operation.ExtraData["IdReasonOfEnd"]); Assert.Equal(IdReasonOfEnd_PressureIsLo, result.Operation.ExtraData["IdReasonOfEnd"]);
} }
} }