From 3176e89236fac6c921721febae5d75c32c30f408 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D1=82=D0=B5=D0=BF=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=94?= =?UTF-8?q?=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9?= Date: Fri, 1 Mar 2024 07:32:02 +0300 Subject: [PATCH 1/7] =?UTF-8?q?=D0=9D=D0=BE=D0=B2=D1=8B=D0=B9=20=D0=B0?= =?UTF-8?q?=D0=BB=D0=B3=D0=BE=D1=80=D0=B8=D1=82=D0=BC=20=D1=83=D0=B4=D0=B5?= =?UTF-8?q?=D1=80=D0=B6=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=B2=20=D0=BA=D0=BB?= =?UTF-8?q?=D0=B8=D0=BD=D1=8C=D1=8F=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DetectedOperation/DetectedOperationDto.cs | 8 ++- .../DetectOperations/DetectableTelemetry.cs | 3 +- .../DetectedOperationExportService.cs | 11 ++-- .../Detectors/DetectorAbstract.cs | 26 +++----- .../Detectors/DetectorSlipsTime.cs | 59 +++++++++++++++---- .../Specifications/Удержание в клиньях.md | 27 ++++++--- 6 files changed, 88 insertions(+), 46 deletions(-) diff --git a/AsbCloudApp/Data/DetectedOperation/DetectedOperationDto.cs b/AsbCloudApp/Data/DetectedOperation/DetectedOperationDto.cs index e81a45fb..ce433aff 100644 --- a/AsbCloudApp/Data/DetectedOperation/DetectedOperationDto.cs +++ b/AsbCloudApp/Data/DetectedOperation/DetectedOperationDto.cs @@ -77,7 +77,13 @@ public class DetectedOperationDto: IId /// [Required] public WellOperationCategoryDto OperationCategory { get; set; } = null!; - + + /// + /// Положение долота на момент окончания операции + /// + [Required] + public float BitDepth { get; set; } + /// /// Ключевой параметр операции /// diff --git a/AsbCloudInfrastructure/Services/DetectOperations/DetectableTelemetry.cs b/AsbCloudInfrastructure/Services/DetectOperations/DetectableTelemetry.cs index 9c72c4e8..aeb18fe2 100644 --- a/AsbCloudInfrastructure/Services/DetectOperations/DetectableTelemetry.cs +++ b/AsbCloudInfrastructure/Services/DetectOperations/DetectableTelemetry.cs @@ -13,4 +13,5 @@ public class DetectableTelemetry public float BlockPosition { get; set; } public float BitDepth { get; set; } public float RotorSpeed { get; set; } -} + public float AxialLoad { get; set; } +} \ No newline at end of file diff --git a/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationExportService.cs b/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationExportService.cs index 3ba4350a..fd33c32a 100644 --- a/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationExportService.cs +++ b/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationExportService.cs @@ -118,13 +118,14 @@ public class DetectedOperationExportService for (int i = 0; i < operations.Count; i++) { var current = operations[i]; - var dateStart = current.DateStart.ToRemoteDateTime(well.Timezone.Hours); - var dateEnd = current.DateEnd.ToRemoteDateTime(well.Timezone.Hours); + var dateStart = current.DateStart.DateTime; + var dateEnd = current.DateEnd.DateTime; var row = sheet.Row(5 + i + headerRowsCount); var categoryName = GetCategoryName(wellOperationCategories, current); + row.Cell(columnDateStart).SetCellValue(dateStart); row.Cell(columnOperationName).SetCellValue(categoryName); row.Cell(columnDateEnd).SetCellValue(dateEnd); row.Cell(columnDuration).SetCellValue((dateEnd - dateStart).TotalMinutes); @@ -143,9 +144,7 @@ public class DetectedOperationExportService query.Add("end", dateStart.AddSeconds(1800 * 0.9).ToString("yyyy-MM-ddTHH:mm:ss.fff")); query.Add("range", "1800"); - row.Cell(columnDateStart).SetCellValue(dateStart); - - var link = $"{host}/well/{well.Id}/telemetry/monitoring{query}"; + var link = $"{host}/well/{well.Id}/telemetry/monitoring{query}"; row.Cell(columnDateStart).SetHyperlink(link); var deltaDepth = i > 0 && i + 1 < operations.Count @@ -180,6 +179,8 @@ public class DetectedOperationExportService 1 => "Не определено начало операции", 101 => "Разница глубин забоя и положением долота", 300 => "Низкое давление", + 301 => "Высокое давление", + 700 => "Изменение глубины долота и осевая нагрузка < веса на крюке", _ => idReasonOfEnd.ToString($"Причина № {idReasonOfEnd}"), }; diff --git a/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorAbstract.cs b/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorAbstract.cs index 6c5b99de..ec05be39 100644 --- a/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorAbstract.cs +++ b/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorAbstract.cs @@ -1,5 +1,4 @@ -using AsbCloudDb.Model; -using System; +using System; using System.Collections.Generic; using AsbCloudApp.Data.DetectedOperation; @@ -7,8 +6,6 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors { public abstract class DetectorAbstract { - private readonly int stepLength = 3; - protected const int IdReasonOfEnd_NotDetected = 0; protected const int IdReasonOfEnd_NotDetectBegin = 1; @@ -33,7 +30,7 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors protected const int IdReasonOfEnd_Drilling = 600; - protected const int IdReasonOfEnd_Custom1 = 10_000; + protected const int IdReasonOfEnd_ChangeBithDepthAndAxiloadLessHookWeight = 700; public bool TryDetect(int idTelemetry, DetectableTelemetry[] telemetry, int begin, int end, DetectedOperationDto? previousOperation, out OperationDetectorResult? result) @@ -44,9 +41,10 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors // Поиск окончания соответствия критерию int idReasonOfEnd = 0; var positionEnd = begin; + while (positionEnd < end) { - positionEnd += stepLength; + positionEnd += 1; if (positionEnd > end) break; @@ -55,15 +53,9 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors if (idReasonOfEnd != IdReasonOfEnd_NotDetected) break; } - + var (Begin, End) = RefineEdges(telemetry, begin, positionEnd); - - if (!IsValidTelemetryRange(telemetry, Begin, End)) - { - result = null; - return false; - } - + result = MakeOperationDetectorResult(idTelemetry, telemetry, Begin, End, idReasonOfEnd); return IsValidOperationDetectorResult(result); @@ -72,10 +64,7 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors result = null; return false; } - - protected virtual bool IsValidTelemetryRange(DetectableTelemetry[] telemetry, int begin, int end) - => end - begin > 1; - + protected virtual (int Begin, int End) RefineEdges(DetectableTelemetry[] telemetry, int begin, int end) => (begin, end); @@ -125,6 +114,7 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors DepthStart = (double)pBegin.WellDepth, DepthEnd = (double)pEnd.WellDepth, ExtraData = ExtraData, + BitDepth = pEnd.BitDepth, Value = CalcValue(telemetry, begin, end), EnabledSubsystems = DetectEnabledSubsystems(telemetry, begin, end, ExtraData) }; diff --git a/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorSlipsTime.cs b/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorSlipsTime.cs index 9388918d..4d06365a 100644 --- a/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorSlipsTime.cs +++ b/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorSlipsTime.cs @@ -12,29 +12,64 @@ public class DetectorSlipsTime : DetectorAbstract protected override bool DetectBegin(DetectableTelemetry[] telemetry, int position, DetectedOperationDto? previousOperation) { - var point0 = telemetry[position]; - var delta = point0.WellDepth - point0.BitDepth; - if (delta > 2.5d) + var currentPoint = telemetry[position]; + var delta = Math.Abs(currentPoint.WellDepth - currentPoint.BitDepth); + + if (delta < 0.1d) return false; - if (point0.Pressure > 15) + if (currentPoint.Pressure > 20) return false; - if (point0.BlockPosition > 8) + var nextIndexPoint = telemetry.Length <= position ? position : position + 1; + + var nextPoint = telemetry[nextIndexPoint]; + var deltaBitDepth = Math.Abs(currentPoint.BitDepth - nextPoint.BitDepth); + var deltaBlockPosition = Math.Abs(currentPoint.BlockPosition - nextPoint.BlockPosition); + + if (deltaBitDepth > 0.001d) return false; - if (point0.HookWeight > 20) + if (deltaBlockPosition < 0.001d) return false; return true; } - protected override (int IdCategory, IDictionary ExtraData) GetSpecificInformation(DetectableTelemetry[] telemetry, int begin, int end) - { + protected override int DetectEnd(DetectableTelemetry[] telemetry, int position, DetectedOperationDto? previousOperation) + { + var currentPoint = telemetry[position]; + + if (currentPoint.Pressure > 20) + return IdReasonOfEnd_PressureIsHi; + + var prevPointIndex = position <= 0 ? 0 : position - 1; + + var prevPoint = telemetry[prevPointIndex]; + + var deltaBitDepth = Math.Abs(currentPoint.BitDepth - prevPoint.BitDepth); + + if (deltaBitDepth > 0.001d && currentPoint.AxialLoad < currentPoint.HookWeight) + return IdReasonOfEnd_ChangeBithDepthAndAxiloadLessHookWeight; + + return IdReasonOfEnd_NotDetected; + } + + protected override (int IdCategory, IDictionary ExtraData) GetSpecificInformation(DetectableTelemetry[] telemetry, + int begin, + int end) + { return (WellOperationCategory.IdSlipsTime, new Dictionary()); - } + } - protected override bool IsValidOperationDetectorResult(OperationDetectorResult operationDetectorResult) => - Math.Abs(operationDetectorResult.Operation.DepthStart - operationDetectorResult.Operation.DepthEnd) > 0.01; -} + protected override bool IsValidOperationDetectorResult(OperationDetectorResult operationDetectorResult) + { + if (Math.Abs((operationDetectorResult.Operation.DateStart - operationDetectorResult.Operation.DateEnd).TotalMinutes) > 30) + return false; + if (operationDetectorResult.Operation.BitDepth <= 150d) + return false; + + return true; + } +} \ No newline at end of file diff --git a/AsbCloudInfrastructure/Services/DetectOperations/Specifications/Удержание в клиньях.md b/AsbCloudInfrastructure/Services/DetectOperations/Specifications/Удержание в клиньях.md index fee75476..eda6b993 100644 --- a/AsbCloudInfrastructure/Services/DetectOperations/Specifications/Удержание в клиньях.md +++ b/AsbCloudInfrastructure/Services/DetectOperations/Specifications/Удержание в клиньях.md @@ -3,19 +3,28 @@ Наращивание бурильного инструмента – операция, во время которой после добуривания очередной трубы/ свечи циркуляция выключается, инструмент разгружается в клиньях (остается только вес крюкоблока и ВСП), происходит развинчивание трубы от верхнего силового привода, берется очередная труба/ свеча, свинчивается с инструментом в клиньях, свинчивается с верхним силовым приводом, происходит подъем инструмента, вес на крюке увеличивается. Далее включается циркуляция и происходит механическое бурение. - Наращивается определяется как время между: -- разгрузкой инструмента на клинья (остается только вес крюкоблока и ВСП). При этом давление менее 15 атм. В случае давления более 15 атм считать началом операции как снижение давления менее 15 атм и началом движения талевого блока вверх. -- снятие инструмента с клиньев (вес увеличивается более, чем на 1т). При этом движение талевого блока происходит вверх. +Наращивание определяется как время между: +- началом разгрузки инструмента на клинья (остается только вес крюкоблока и ВСП). При этом расстояние от долота до забоя в диапазоне от 0.1 до 3м., давление менее 20 атм. В случае Если происходит движение блока без изменения глубины долота—-> идем назад и ищем падение давления ниже 20атм. +- снятие инструмента с клиньев (вес увеличивается более, чем на 1т). При этом движение талевого блока происходит вверх ИЛИ увеличение давления больше 20 атм. + ## Метод определения Признак начала операции = - ( расстояние от долота до забоя < 2.5м ) И - ( положение талевого блока < 8 ) И - ( вес на крюке < 20 тонн ) И - ( давление < 15 атм ); + ( Расстояние от долота до забоя > 0.1 м) И + ( давление < 20атм) И + ( движение блока без изменения глубины долота) И + ( глубина долота > 150 м); + + Признак окончания операции = + ( давление > 20атм) ИЛИ + ( время продолжительности > 30 мин) ИЛИ + ( глубина долота < 150 м) ИЛИ + ( изменение глубины долота) И + ( осевая нагрузка < веса на крюке); - Признак окончания операции = НЕ выполняется признак начала операции; ## Ключевой параметр -Продолжительность операции. \ No newline at end of file +Продолжительность операции. + +Предел времени операции 30 минут, всё что больше 30 минут это уже не наращивание - а НПВ. \ No newline at end of file From 47e9c9f2cd042fdb5a19c709ba7db84772524d83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D1=82=D0=B5=D0=BF=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=94?= =?UTF-8?q?=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9?= Date: Fri, 1 Mar 2024 07:33:39 +0300 Subject: [PATCH 2/7] =?UTF-8?q?=D0=A2=D0=B5=D1=81=D1=82=D1=8B=20=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2=D0=BE=D0=B3=D0=BE=20=D0=B0=D0=BB=D0=B3=D0=BE=D1=80?= =?UTF-8?q?=D0=B8=D1=82=D0=BC=D0=B0=20"=D0=A3=D0=B4=D0=B5=D1=80=D0=B6?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=B2=20=D0=BA=D0=BB=D0=B8=D0=BD?= =?UTF-8?q?=D1=8C=D1=8F=D1=85"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Builders/DetectableTelemetryBuilder.cs | 69 +++++++++++ .../Detectors/DetectorSlipsTimeTests.cs | 109 ++++++++++++++++++ 2 files changed, 178 insertions(+) create mode 100644 AsbCloudWebApi.Tests/Builders/DetectableTelemetryBuilder.cs create mode 100644 AsbCloudWebApi.Tests/Services/DetectedOperations/Detectors/DetectorSlipsTimeTests.cs diff --git a/AsbCloudWebApi.Tests/Builders/DetectableTelemetryBuilder.cs b/AsbCloudWebApi.Tests/Builders/DetectableTelemetryBuilder.cs new file mode 100644 index 00000000..f0acdc09 --- /dev/null +++ b/AsbCloudWebApi.Tests/Builders/DetectableTelemetryBuilder.cs @@ -0,0 +1,69 @@ +using System; +using AsbCloudInfrastructure.Services.DetectOperations; + +namespace AsbCloudWebApi.Tests.Builders; + +public class DetectableTelemetryBuilder +{ + private DateTimeOffset dateTime = DateTimeOffset.UtcNow; + private float wellDepth = 300; + private float pressure = 15; + private float hookWeight = 20; + private float blockPosition = 20; + private float bitDepth = 151; + private float axialLoad = 19; + + public DetectableTelemetryBuilder WithDateTime(DateTimeOffset newDateTime) + { + dateTime = newDateTime; + return this; + } + + public DetectableTelemetryBuilder WithWellDepth(float newWllDepth) + { + wellDepth = newWllDepth; + return this; + } + + public DetectableTelemetryBuilder WithPressure(float newPressure) + { + pressure = newPressure; + return this; + } + + public DetectableTelemetryBuilder WithHookWeight(float newHookWeight) + { + hookWeight = newHookWeight; + return this; + } + + public DetectableTelemetryBuilder WithBlockPosition(float newBlockPosition) + { + blockPosition = newBlockPosition; + return this; + } + + public DetectableTelemetryBuilder WithBitDepth(float newBitDepth) + { + bitDepth = newBitDepth; + return this; + } + + public DetectableTelemetryBuilder WithAxialLoad(float newAxialLoad) + { + axialLoad = newAxialLoad; + return this; + } + + public DetectableTelemetry Build() => + new() + { + DateTime = dateTime, + WellDepth = wellDepth, + Pressure = pressure, + HookWeight = hookWeight, + BlockPosition = blockPosition, + BitDepth = bitDepth, + AxialLoad = axialLoad + }; +} \ No newline at end of file diff --git a/AsbCloudWebApi.Tests/Services/DetectedOperations/Detectors/DetectorSlipsTimeTests.cs b/AsbCloudWebApi.Tests/Services/DetectedOperations/Detectors/DetectorSlipsTimeTests.cs new file mode 100644 index 00000000..ac8c373c --- /dev/null +++ b/AsbCloudWebApi.Tests/Services/DetectedOperations/Detectors/DetectorSlipsTimeTests.cs @@ -0,0 +1,109 @@ +using System; +using AsbCloudInfrastructure.Services.DetectOperations.Detectors; +using AsbCloudWebApi.Tests.Builders; +using Xunit; + +namespace AsbCloudWebApi.Tests.Services.DetectedOperations.Detectors; + +public class DetectorSlipsTimeTests +{ + private const int IdSlipsTime = 5011; + + private readonly DetectableTelemetryBuilder telemetryBuilder = new(); + + private readonly DetectorSlipsTime sut = new(); + + [Fact] + public void DetectOperation_by_change_block_position_and_axial_load_less_hook_weight_is_success() + { + //arrange + var point0 = telemetryBuilder + .Build(); + + var point1 = telemetryBuilder + .WithBlockPosition(21) + .Build(); + + var telemetries = new[] { point0, point1 }; + + //act + var isDetectOperation = sut.TryDetect(0, telemetries, 0, telemetries.Length - 1, null, out var result); + + //assert + Assert.True(isDetectOperation); + Assert.NotNull(result); + Assert.Equal(IdSlipsTime, result.Operation.IdCategory); + } + + [Fact] + public void DetectOperation_by_high_pressure_is_success() + { + //arrange + var point0 = telemetryBuilder + .Build(); + + var point1 = telemetryBuilder + .WithBlockPosition(21) + .WithAxialLoad(30) + .WithHookWeight(20) + .WithPressure(23) + .Build(); + + var telemetries = new[] { point0, point1 }; + + //act + var isDetectOperation = sut.TryDetect(0, telemetries, 0, telemetries.Length - 1, null, out var result); + + //assert + Assert.True(isDetectOperation); + Assert.NotNull(result); + Assert.Equal(IdSlipsTime, result.Operation.IdCategory); + } + + [Fact] + public void ValidateOperation_with_well_depth_before_150_meters_is_invalid() + { + //arrange + var point0 = telemetryBuilder + .WithBitDepth(149) + .Build(); + + var point1 = telemetryBuilder + .WithBitDepth(149) + .WithBlockPosition(21) + .Build(); + + var telemetries = new[] { point0, point1 }; + + //act + var isDetectOperation = sut.TryDetect(0, telemetries, 0, telemetries.Length - 1, null, out var result); + + //assert + Assert.False(isDetectOperation); + Assert.NotNull(result); + Assert.Equal(IdSlipsTime, result.Operation.IdCategory); + } + + [Fact] + public void ValidateOperation_with_duration_more_30_minutes_is_invalid() + { + //arrange + var point0 = telemetryBuilder + .Build(); + + var point1 = telemetryBuilder + .WithDateTime(DateTimeOffset.UtcNow.AddMinutes(30)) + .WithBlockPosition(21) + .Build(); + + var telemetries = new[] { point0, point1 }; + + //act + var isDetectOperation = sut.TryDetect(0, telemetries, 0, telemetries.Length - 1, null, out var result); + + //assert + Assert.False(isDetectOperation); + Assert.NotNull(result); + Assert.Equal(IdSlipsTime, result.Operation.IdCategory); + } +} \ No newline at end of file From 4af7868430fc3514f90ad6c2f7f5bcdc82176367 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D1=82=D0=B5=D0=BF=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=94?= =?UTF-8?q?=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9?= Date: Fri, 1 Mar 2024 07:41:55 +0300 Subject: [PATCH 3/7] fix naming test --- .../DetectedOperations/Detectors/DetectorSlipsTimeTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AsbCloudWebApi.Tests/Services/DetectedOperations/Detectors/DetectorSlipsTimeTests.cs b/AsbCloudWebApi.Tests/Services/DetectedOperations/Detectors/DetectorSlipsTimeTests.cs index ac8c373c..947161ac 100644 --- a/AsbCloudWebApi.Tests/Services/DetectedOperations/Detectors/DetectorSlipsTimeTests.cs +++ b/AsbCloudWebApi.Tests/Services/DetectedOperations/Detectors/DetectorSlipsTimeTests.cs @@ -61,7 +61,7 @@ public class DetectorSlipsTimeTests } [Fact] - public void ValidateOperation_with_well_depth_before_150_meters_is_invalid() + public void ValidateOperation_with_bit_depth_before_150_meters_is_invalid() { //arrange var point0 = telemetryBuilder From 93f22c5b5b39d5d6054c309946219457709a8c3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D1=82=D0=B5=D0=BF=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=94?= =?UTF-8?q?=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9?= Date: Fri, 1 Mar 2024 07:59:26 +0300 Subject: [PATCH 4/7] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D1=83=D1=81=D0=BB=D0=BE=D0=B2=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=B2=20=D0=B0=D0=BB=D0=B3=D0=BE=D1=80=D0=B8=D1=82=D0=BC=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DetectedOperation/DetectedOperationDto.cs | 8 +------ .../Detectors/DetectorAbstract.cs | 1 - .../Detectors/DetectorSlipsTime.cs | 15 ++++-------- .../Specifications/Удержание в клиньях.md | 6 ++--- .../Detectors/DetectorSlipsTimeTests.cs | 24 ------------------- 5 files changed, 8 insertions(+), 46 deletions(-) diff --git a/AsbCloudApp/Data/DetectedOperation/DetectedOperationDto.cs b/AsbCloudApp/Data/DetectedOperation/DetectedOperationDto.cs index ce433aff..e81a45fb 100644 --- a/AsbCloudApp/Data/DetectedOperation/DetectedOperationDto.cs +++ b/AsbCloudApp/Data/DetectedOperation/DetectedOperationDto.cs @@ -77,13 +77,7 @@ public class DetectedOperationDto: IId /// [Required] public WellOperationCategoryDto OperationCategory { get; set; } = null!; - - /// - /// Положение долота на момент окончания операции - /// - [Required] - public float BitDepth { get; set; } - + /// /// Ключевой параметр операции /// diff --git a/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorAbstract.cs b/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorAbstract.cs index ec05be39..559e1dc4 100644 --- a/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorAbstract.cs +++ b/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorAbstract.cs @@ -114,7 +114,6 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors DepthStart = (double)pBegin.WellDepth, DepthEnd = (double)pEnd.WellDepth, ExtraData = ExtraData, - BitDepth = pEnd.BitDepth, Value = CalcValue(telemetry, begin, end), EnabledSubsystems = DetectEnabledSubsystems(telemetry, begin, end, ExtraData) }; diff --git a/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorSlipsTime.cs b/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorSlipsTime.cs index 4d06365a..315583f6 100644 --- a/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorSlipsTime.cs +++ b/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorSlipsTime.cs @@ -15,6 +15,9 @@ public class DetectorSlipsTime : DetectorAbstract var currentPoint = telemetry[position]; var delta = Math.Abs(currentPoint.WellDepth - currentPoint.BitDepth); + if (currentPoint.BitDepth < 150) + return false; + if (delta < 0.1d) return false; @@ -62,14 +65,6 @@ public class DetectorSlipsTime : DetectorAbstract return (WellOperationCategory.IdSlipsTime, new Dictionary()); } - protected override bool IsValidOperationDetectorResult(OperationDetectorResult operationDetectorResult) - { - if (Math.Abs((operationDetectorResult.Operation.DateStart - operationDetectorResult.Operation.DateEnd).TotalMinutes) > 30) - return false; - - if (operationDetectorResult.Operation.BitDepth <= 150d) - return false; - - return true; - } + protected override bool IsValidOperationDetectorResult(OperationDetectorResult operationDetectorResult) => + Math.Abs((operationDetectorResult.Operation.DateStart - operationDetectorResult.Operation.DateEnd).TotalMinutes) < 30; } \ No newline at end of file diff --git a/AsbCloudInfrastructure/Services/DetectOperations/Specifications/Удержание в клиньях.md b/AsbCloudInfrastructure/Services/DetectOperations/Specifications/Удержание в клиньях.md index eda6b993..c3bcab51 100644 --- a/AsbCloudInfrastructure/Services/DetectOperations/Specifications/Удержание в клиньях.md +++ b/AsbCloudInfrastructure/Services/DetectOperations/Specifications/Удержание в клиньях.md @@ -16,14 +16,12 @@ ( движение блока без изменения глубины долота) И ( глубина долота > 150 м); - Признак окончания операции = + Признак окончания операции = ( давление > 20атм) ИЛИ - ( время продолжительности > 30 мин) ИЛИ - ( глубина долота < 150 м) ИЛИ + ( время продолжительности > 30 мин) ИЛИ ( изменение глубины долота) И ( осевая нагрузка < веса на крюке); - ## Ключевой параметр Продолжительность операции. diff --git a/AsbCloudWebApi.Tests/Services/DetectedOperations/Detectors/DetectorSlipsTimeTests.cs b/AsbCloudWebApi.Tests/Services/DetectedOperations/Detectors/DetectorSlipsTimeTests.cs index 947161ac..86c1b3ae 100644 --- a/AsbCloudWebApi.Tests/Services/DetectedOperations/Detectors/DetectorSlipsTimeTests.cs +++ b/AsbCloudWebApi.Tests/Services/DetectedOperations/Detectors/DetectorSlipsTimeTests.cs @@ -60,30 +60,6 @@ public class DetectorSlipsTimeTests Assert.Equal(IdSlipsTime, result.Operation.IdCategory); } - [Fact] - public void ValidateOperation_with_bit_depth_before_150_meters_is_invalid() - { - //arrange - var point0 = telemetryBuilder - .WithBitDepth(149) - .Build(); - - var point1 = telemetryBuilder - .WithBitDepth(149) - .WithBlockPosition(21) - .Build(); - - var telemetries = new[] { point0, point1 }; - - //act - var isDetectOperation = sut.TryDetect(0, telemetries, 0, telemetries.Length - 1, null, out var result); - - //assert - Assert.False(isDetectOperation); - Assert.NotNull(result); - Assert.Equal(IdSlipsTime, result.Operation.IdCategory); - } - [Fact] public void ValidateOperation_with_duration_more_30_minutes_is_invalid() { From 9ba05d6650cc64d8e40b1b71bec02ada05c61338 Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Fri, 1 Mar 2024 10:35:43 +0500 Subject: [PATCH 5/7] DetectorSlipsTime.DetectBegin reorder conditions --- .../DetectOperations/Detectors/DetectorSlipsTime.cs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorSlipsTime.cs b/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorSlipsTime.cs index 315583f6..a9996a1b 100644 --- a/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorSlipsTime.cs +++ b/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorSlipsTime.cs @@ -13,26 +13,23 @@ public class DetectorSlipsTime : DetectorAbstract protected override bool DetectBegin(DetectableTelemetry[] telemetry, int position, DetectedOperationDto? previousOperation) { var currentPoint = telemetry[position]; - var delta = Math.Abs(currentPoint.WellDepth - currentPoint.BitDepth); - if (currentPoint.BitDepth < 150) return false; - if (delta < 0.1d) - return false; - if (currentPoint.Pressure > 20) return false; - var nextIndexPoint = telemetry.Length <= position ? position : position + 1; + var delta = currentPoint.WellDepth - currentPoint.BitDepth; + if (delta < 0.1d) + return false; + var nextIndexPoint = telemetry.Length <= position ? position : position + 1; var nextPoint = telemetry[nextIndexPoint]; var deltaBitDepth = Math.Abs(currentPoint.BitDepth - nextPoint.BitDepth); - var deltaBlockPosition = Math.Abs(currentPoint.BlockPosition - nextPoint.BlockPosition); - if (deltaBitDepth > 0.001d) return false; + var deltaBlockPosition = Math.Abs(currentPoint.BlockPosition - nextPoint.BlockPosition); if (deltaBlockPosition < 0.001d) return false; From e4a5ca69fb0a71ea588b168d1db2db3f2dd312e5 Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Fri, 1 Mar 2024 11:06:37 +0500 Subject: [PATCH 6/7] DetectedOperationService.DetectOperationsAsync() Add AxialLoad to select --- .../Services/DetectOperations/DetectedOperationService.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationService.cs b/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationService.cs index 06415870..b53b1cd0 100644 --- a/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationService.cs +++ b/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationService.cs @@ -164,6 +164,7 @@ public class DetectedOperationService : IDetectedOperationService BlockPosition = t.BlockPosition, BitDepth = t.BitDepth, RotorSpeed = t.RotorSpeed, + AxialLoad = t.AxialLoad, }).ToArray(); if (detectableTelemetries.Length < gap) From fb6126260fedda01766500ffa3369ca51687ace2 Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Fri, 1 Mar 2024 11:07:19 +0500 Subject: [PATCH 7/7] Replace DetectableTelemetryBuilder by CommonExtensions.Copy() --- .../Builders/DetectableTelemetryBuilder.cs | 69 ------------------- AsbCloudWebApi.Tests/CommonExtensions.cs | 19 +++++ .../Detectors/DetectorSlipsTimeTests.cs | 47 ++++++------- 3 files changed, 43 insertions(+), 92 deletions(-) delete mode 100644 AsbCloudWebApi.Tests/Builders/DetectableTelemetryBuilder.cs create mode 100644 AsbCloudWebApi.Tests/CommonExtensions.cs diff --git a/AsbCloudWebApi.Tests/Builders/DetectableTelemetryBuilder.cs b/AsbCloudWebApi.Tests/Builders/DetectableTelemetryBuilder.cs deleted file mode 100644 index f0acdc09..00000000 --- a/AsbCloudWebApi.Tests/Builders/DetectableTelemetryBuilder.cs +++ /dev/null @@ -1,69 +0,0 @@ -using System; -using AsbCloudInfrastructure.Services.DetectOperations; - -namespace AsbCloudWebApi.Tests.Builders; - -public class DetectableTelemetryBuilder -{ - private DateTimeOffset dateTime = DateTimeOffset.UtcNow; - private float wellDepth = 300; - private float pressure = 15; - private float hookWeight = 20; - private float blockPosition = 20; - private float bitDepth = 151; - private float axialLoad = 19; - - public DetectableTelemetryBuilder WithDateTime(DateTimeOffset newDateTime) - { - dateTime = newDateTime; - return this; - } - - public DetectableTelemetryBuilder WithWellDepth(float newWllDepth) - { - wellDepth = newWllDepth; - return this; - } - - public DetectableTelemetryBuilder WithPressure(float newPressure) - { - pressure = newPressure; - return this; - } - - public DetectableTelemetryBuilder WithHookWeight(float newHookWeight) - { - hookWeight = newHookWeight; - return this; - } - - public DetectableTelemetryBuilder WithBlockPosition(float newBlockPosition) - { - blockPosition = newBlockPosition; - return this; - } - - public DetectableTelemetryBuilder WithBitDepth(float newBitDepth) - { - bitDepth = newBitDepth; - return this; - } - - public DetectableTelemetryBuilder WithAxialLoad(float newAxialLoad) - { - axialLoad = newAxialLoad; - return this; - } - - public DetectableTelemetry Build() => - new() - { - DateTime = dateTime, - WellDepth = wellDepth, - Pressure = pressure, - HookWeight = hookWeight, - BlockPosition = blockPosition, - BitDepth = bitDepth, - AxialLoad = axialLoad - }; -} \ No newline at end of file diff --git a/AsbCloudWebApi.Tests/CommonExtensions.cs b/AsbCloudWebApi.Tests/CommonExtensions.cs new file mode 100644 index 00000000..ac32b59f --- /dev/null +++ b/AsbCloudWebApi.Tests/CommonExtensions.cs @@ -0,0 +1,19 @@ +using Mapster; +using System; + +namespace AsbCloudWebApi.Tests; + +public static class CommonExtensions +{ + public static T Copy(this T obj) + { + var copy = obj.Adapt(); + return copy; + } + + public static T Mutate(this T obj, Action mutation) + { + var copy = obj.Copy(); + return copy; + } +} diff --git a/AsbCloudWebApi.Tests/Services/DetectedOperations/Detectors/DetectorSlipsTimeTests.cs b/AsbCloudWebApi.Tests/Services/DetectedOperations/Detectors/DetectorSlipsTimeTests.cs index 86c1b3ae..30d8da83 100644 --- a/AsbCloudWebApi.Tests/Services/DetectedOperations/Detectors/DetectorSlipsTimeTests.cs +++ b/AsbCloudWebApi.Tests/Services/DetectedOperations/Detectors/DetectorSlipsTimeTests.cs @@ -1,6 +1,6 @@ using System; +using AsbCloudInfrastructure.Services.DetectOperations; using AsbCloudInfrastructure.Services.DetectOperations.Detectors; -using AsbCloudWebApi.Tests.Builders; using Xunit; namespace AsbCloudWebApi.Tests.Services.DetectedOperations.Detectors; @@ -9,7 +9,14 @@ public class DetectorSlipsTimeTests { private const int IdSlipsTime = 5011; - private readonly DetectableTelemetryBuilder telemetryBuilder = new(); + private readonly DetectableTelemetry telemetry = new() { + WellDepth = 300, + Pressure = 15, + HookWeight = 20, + BlockPosition = 20, + BitDepth = 151, + AxialLoad = 19, + }; private readonly DetectorSlipsTime sut = new(); @@ -17,12 +24,10 @@ public class DetectorSlipsTimeTests public void DetectOperation_by_change_block_position_and_axial_load_less_hook_weight_is_success() { //arrange - var point0 = telemetryBuilder - .Build(); + var point0 = telemetry.Copy(); - var point1 = telemetryBuilder - .WithBlockPosition(21) - .Build(); + var point1 = telemetry.Copy(); + point1.BlockPosition = 21; var telemetries = new[] { point0, point1 }; @@ -38,16 +43,14 @@ public class DetectorSlipsTimeTests [Fact] public void DetectOperation_by_high_pressure_is_success() { - //arrange - var point0 = telemetryBuilder - .Build(); + //arrange + var point0 = telemetry.Copy(); - var point1 = telemetryBuilder - .WithBlockPosition(21) - .WithAxialLoad(30) - .WithHookWeight(20) - .WithPressure(23) - .Build(); + var point1 = telemetry.Copy(); + point1.BlockPosition = 21; + point1.AxialLoad = 30; + point1.HookWeight = 20; + point1.Pressure = 23; var telemetries = new[] { point0, point1 }; @@ -63,14 +66,12 @@ public class DetectorSlipsTimeTests [Fact] public void ValidateOperation_with_duration_more_30_minutes_is_invalid() { - //arrange - var point0 = telemetryBuilder - .Build(); + //arrange + var point0 = telemetry.Copy(); - var point1 = telemetryBuilder - .WithDateTime(DateTimeOffset.UtcNow.AddMinutes(30)) - .WithBlockPosition(21) - .Build(); + var point1 = telemetry.Copy(); + point1.BlockPosition = 21; + point1.DateTime = DateTimeOffset.UtcNow.AddMinutes(30); var telemetries = new[] { point0, point1 };