diff --git a/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationService.cs b/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationService.cs index b53b1cd0..86c9aea0 100644 --- a/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationService.cs +++ b/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationService.cs @@ -25,7 +25,8 @@ public class DetectedOperationService : IDetectedOperationService private static readonly DetectorAbstract[] detectors = { new DetectorDrilling(), - new DetectorSlipsTime() + new DetectorSlipsTime(), + new DetectorFlashing(), }; public DetectedOperationService( @@ -167,13 +168,13 @@ public class DetectedOperationService : IDetectedOperationService AxialLoad = t.AxialLoad, }).ToArray(); - if (detectableTelemetries.Length < gap) + if (detectableTelemetries.Length <= gap) break; var isDetected = false; var positionBegin = 0; var positionEnd = detectableTelemetries.Length - gap; - while (positionEnd > positionBegin) + while (positionEnd > positionBegin) { foreach (var detector in detectors) { diff --git a/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorAbstract.cs b/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorAbstract.cs index 559e1dc4..44b47554 100644 --- a/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorAbstract.cs +++ b/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorAbstract.cs @@ -32,6 +32,10 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors protected const int IdReasonOfEnd_ChangeBithDepthAndAxiloadLessHookWeight = 700; + protected const int IdReasonOfEnd_DeltaWellDepthAndBithDepthIsLo = 800; + + protected const int IdReasonOfEnd_BithDepthIsLo = 900; + public bool TryDetect(int idTelemetry, DetectableTelemetry[] telemetry, int begin, int end, DetectedOperationDto? previousOperation, out OperationDetectorResult? result) { diff --git a/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorFlashing.cs b/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorFlashing.cs index 2e73e65a..0718d447 100644 --- a/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorFlashing.cs +++ b/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorFlashing.cs @@ -9,7 +9,7 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors /// /// Промывка /// - internal class DetectorFlashing : DetectorAbstract + public class DetectorFlashing : DetectorAbstract { protected override double CalcValue(DetectableTelemetry[] telemetry, int begin, int end) @@ -19,7 +19,7 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors { var currentPoint = telemetry[position]; - if (currentPoint.Pressure <= 20) + if (currentPoint.Pressure <= 10) return false; var delta = currentPoint.WellDepth - currentPoint.BitDepth; @@ -34,7 +34,7 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors if (Math.Abs(currentPoint.WellDepth - nextPoint.WellDepth) > 0) return false; - if (currentPoint.WellDepth <= 150) + if (currentPoint.BitDepth <= 150) return false; return true; @@ -45,14 +45,14 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors { var currentPoint = telemetry[position]; - if (currentPoint.Pressure < 20) + if (currentPoint.Pressure < 10) return IdReasonOfEnd_PressureIsLo; if ((currentPoint.WellDepth - currentPoint.BitDepth) < 0.03d) - return 0; + return IdReasonOfEnd_DeltaWellDepthAndBithDepthIsLo; if (currentPoint.RotorSpeed >= 10) return IdReasonOfEnd_RotorSpeedIsHi; if (currentPoint.BitDepth < 150) - return 0; + return IdReasonOfEnd_BithDepthIsLo; return IdReasonOfEnd_NotDetected; } diff --git a/AsbCloudInfrastructure/Services/DetectOperations/Specifications/Промывка.md b/AsbCloudInfrastructure/Services/DetectOperations/Specifications/Промывка.md index c4ca9bac..0dd385fd 100644 --- a/AsbCloudInfrastructure/Services/DetectOperations/Specifications/Промывка.md +++ b/AsbCloudInfrastructure/Services/DetectOperations/Specifications/Промывка.md @@ -11,9 +11,9 @@ ## Метод определения Признак начала операции = - ( давление > 20 атм ) И - ( расстояние от долота до забоя >= 0.03 м) И + ( давление > 10 атм ) И ( обороты ротора < 10 об/мин) И + ( расстояние от долота до забоя >= 0.03 м) И ( глубина забоя не изменяется) И ( глубина долота > 150 м) И ( положение блока не меняется) ИЛИ @@ -21,12 +21,12 @@ ( положение блока увеличивается --> дальше смотрим: если после остановки блока обороты ротора < 10 об/мин); Признак окончания операции = - ( давление < 20 атм ) ИЛИ + ( давление < 10 атм ) ИЛИ ( расстояние от долота до забоя < 0.03 м ) ИЛИ - ( обороты ротора >= 10 об/мин) ИЛИ - ( глубина долота < 150 м) ИЛИ - (положение блока увеличивается --> дальше смотрим: если после остановки блока обороты ротора >= 10 об/мин); + ( обороты ротора >= 10 об/мин) ИЛИ + ( положение блока увеличивается --> дальше смотрим: если после остановки блока обороты ротора >= 10 об/мин) ИЛИ + ( глубина долота < 150 м); ## Ключевой параметр -Продолжительность операции. \ No newline at end of file +Продолжительность операции. diff --git a/AsbCloudInfrastructure/Services/DetectOperations/WorkOperationDetection.cs b/AsbCloudInfrastructure/Services/DetectOperations/WorkOperationDetection.cs index f562e744..d001471e 100644 --- a/AsbCloudInfrastructure/Services/DetectOperations/WorkOperationDetection.cs +++ b/AsbCloudInfrastructure/Services/DetectOperations/WorkOperationDetection.cs @@ -44,7 +44,7 @@ public class WorkOperationDetection: Work var beginDate = lastDetectedDates.TryGetValue(telemetryId, out var date) ? date : (DateTimeOffset?)null; - onProgressCallback($"Start detecting telemetry: {telemetryId} from {beginDate}", i++ / telemetryIds.Length); + onProgressCallback($"Start detecting telemetry: {telemetryId} from {beginDate}", i / telemetryIds.Length); var detectedOperations = await detectedOperationService.DetectOperationsAsync(telemetryId, beginDate, token); if (detectedOperations.Any()) diff --git a/AsbCloudWebApi.Tests/Services/DetectedOperations/Detectors/DetectorFlashingTests.cs b/AsbCloudWebApi.Tests/Services/DetectedOperations/Detectors/DetectorFlashingTests.cs new file mode 100644 index 00000000..f93edd8f --- /dev/null +++ b/AsbCloudWebApi.Tests/Services/DetectedOperations/Detectors/DetectorFlashingTests.cs @@ -0,0 +1,128 @@ +using System.Collections.Generic; +using System.Linq; +using AsbCloudApp.Data.DetectedOperation; +using AsbCloudDb.Model; +using AsbCloudInfrastructure.Services.DetectOperations; +using AsbCloudInfrastructure.Services.DetectOperations.Detectors; +using Xunit; + +namespace AsbCloudWebApi.Tests.Services.DetectedOperations.Detectors; + +/// +/// "" +/// +public class DetectorFlashingTests : DetectorFlashing +{ + private readonly DetectorFlashing detector = new(); + + /// + /// , + /// + private readonly DetectableTelemetry telemetry = new() + { + Pressure = 21, + WellDepth = 152, + BitDepth = 151, + RotorSpeed = 9, + DateTime = System.DateTimeOffset.Now + }; + + + /// + /// , , + /// - + /// - + /// + [Fact] + public void DetectOperation_find_startOperation_notFind_endOperation() + { + //arrange + var point0 = telemetry.Copy(); + var point1 = telemetry.Copy(); + point1.DateTime = System.DateTimeOffset.Now.AddMinutes(5); + + var telemetries = new[] { point0, point1 }; + + //act + var isDetectOperation = detector.TryDetect(0, telemetries, 0, telemetries.Length - 1, null, out var result); + + //assert + Assert.True(isDetectOperation); + Assert.NotNull(result); + Assert.Equal(WellOperationCategory.IdFlashing, result.Operation.IdCategory); + Assert.Equal(IdReasonOfEnd_NotDetected, result.Operation.ExtraData["IdReasonOfEnd"]); + } + + /// + /// , = 150, + /// + [Fact] + public void DetectOperation_with_BitDepth_LE_150_is_fail() + { + //arrange + var point0 = telemetry.Copy(); + point0.BitDepth = 150; + + var point1 = telemetry.Copy(); + + var telemetries = new[] { point0, point1 }; + + //act + + var isDetectOperation = detector.TryDetect(0, telemetries, 0, telemetries.Length - 1, null, out var result); + + //assert + Assert.False(isDetectOperation); + Assert.Null(result); + } + + + /// + /// , , + /// + [Fact] + public void DetectOperation_with_DeltaWellDepth_NotEqual_0_is_fail() + { + //arrange + var point0 = telemetry.Copy(); + var point1 = telemetry.Copy(); + point1.WellDepth = point0.WellDepth + 10; + + var telemetries = new[] { point0, point1 }; + + //act + var isDetectOperation = detector.TryDetect(0, telemetries, 0, telemetries.Length - 1, null, out var result); + + //assert + Assert.False(isDetectOperation); + Assert.Null(result); + } + + /// + /// , + /// - 10 + /// + [Fact] + public void DetectOperations_Begin_And_End_by_Pressure_Less_20_is_success() + { + //arrange + var point0 = telemetry.Copy(); + var point1 = telemetry.Copy(); + point1.Pressure = 9; + point1.BitDepth = 140.0001f; + point1.RotorSpeed = 10; + + var telemetries = new[] { point0, point1 }; + + //act + var isDetectOperation = detector.TryDetect(0, telemetries, 0, telemetries.Length - 1, null, out var result); + + //assert + Assert.False(isDetectOperation); + Assert.NotNull(result); + Assert.Equal(WellOperationCategory.IdFlashing, result.Operation.IdCategory); + Assert.Equal(IdReasonOfEnd_PressureIsLo, result.Operation.ExtraData["IdReasonOfEnd"]); + } + + +} \ No newline at end of file