Рефакторинг детекторов

This commit is contained in:
Степанов Дмитрий 2024-02-20 11:16:46 +03:00
parent a3938a2dff
commit aa297e235d
4 changed files with 14 additions and 23 deletions

View File

@ -35,7 +35,7 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
protected const int IdReasonOfEnd_Custom1 = 10_000; protected const int IdReasonOfEnd_Custom1 = 10_000;
public bool TryDetect(int idTelemetry, DetectableTelemetry[] telemetry, int begin, int end, DetectedOperation? previousOperation, public bool TryDetect(int idTelemetry, DetectableTelemetry[] telemetry, int begin, int end, DetectedOperationDto? previousOperation,
out OperationDetectorResult? result) out OperationDetectorResult? result)
{ {
// Проверка соответствия критерию начала операции // Проверка соответствия критерию начала операции
@ -82,9 +82,9 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
protected virtual bool IsValidOperationDetectorResult(OperationDetectorResult operationDetectorResult) protected virtual bool IsValidOperationDetectorResult(OperationDetectorResult operationDetectorResult)
=> operationDetectorResult.Operation.DateEnd - operationDetectorResult.Operation.DateStart > TimeSpan.FromSeconds(3); => operationDetectorResult.Operation.DateEnd - operationDetectorResult.Operation.DateStart > TimeSpan.FromSeconds(3);
protected abstract bool DetectBegin(DetectableTelemetry[] telemetry, int position, DetectedOperation? previousOperation); protected abstract bool DetectBegin(DetectableTelemetry[] telemetry, int position, DetectedOperationDto? previousOperation);
protected virtual int DetectEnd(DetectableTelemetry[] telemetry, int position, DetectedOperation? previousOperation) protected virtual int DetectEnd(DetectableTelemetry[] telemetry, int position, DetectedOperationDto? previousOperation)
=> DetectBegin(telemetry, position, previousOperation) => DetectBegin(telemetry, position, previousOperation)
? IdReasonOfEnd_NotDetected ? IdReasonOfEnd_NotDetected
: IdReasonOfEnd_NotDetectBegin; : IdReasonOfEnd_NotDetectBegin;
@ -110,16 +110,15 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
return result; return result;
} }
private DetectedOperation MakeDetectedOperation(int idTelemetry, DetectableTelemetry[] telemetry, int begin, int end) private DetectedOperationDto MakeDetectedOperation(int idTelemetry, DetectableTelemetry[] telemetry, int begin, int end)
{ {
var pBegin = telemetry[begin]; var pBegin = telemetry[begin];
var pEnd = telemetry[end]; var pEnd = telemetry[end];
var (IdCategory, ExtraData) = GetSpecificInformation(telemetry, begin, end); var (IdCategory, ExtraData) = GetSpecificInformation(telemetry, begin, end);
var operation = new DetectedOperation var operation = new DetectedOperationDto
{ {
IdCategory = IdCategory, IdCategory = IdCategory,
IdTelemetry = idTelemetry, IdTelemetry = idTelemetry,
IdUsersAtStart = pBegin.IdUser ?? -1,
DateStart = pBegin.DateTime, DateStart = pBegin.DateTime,
DateEnd = pEnd.DateTime, DateEnd = pEnd.DateTime,
DepthStart = (double)pBegin.WellDepth, DepthStart = (double)pBegin.WellDepth,

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using AsbCloudApp.Data.DetectedOperation;
using AsbCloudDb.Model; using AsbCloudDb.Model;
namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors; namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors;
@ -12,7 +13,7 @@ public class DetectorDrilling : DetectorAbstract
public const string ExtraDataKeyDispersionOfNormalizedRotorSpeed = "dispersionOfNormalizedRotorSpeed"; public const string ExtraDataKeyDispersionOfNormalizedRotorSpeed = "dispersionOfNormalizedRotorSpeed";
public const string ExtraDataKeyAvgRotorSpeed = "avgRotorSpeed"; public const string ExtraDataKeyAvgRotorSpeed = "avgRotorSpeed";
protected override bool DetectBegin(DetectableTelemetry[] telemetry, int position, DetectedOperation? previousOperation) protected override bool DetectBegin(DetectableTelemetry[] telemetry, int position, DetectedOperationDto? previousOperation)
{ {
var point0 = telemetry[position]; var point0 = telemetry[position];
var delta = point0.WellDepth - point0.BitDepth; var delta = point0.WellDepth - point0.BitDepth;
@ -25,7 +26,7 @@ public class DetectorDrilling : DetectorAbstract
return true; return true;
} }
protected override int DetectEnd(DetectableTelemetry[] telemetry, int position, DetectedOperation? previousOperation) protected override int DetectEnd(DetectableTelemetry[] telemetry, int position, DetectedOperationDto? previousOperation)
{ {
var point0 = telemetry[position]; var point0 = telemetry[position];
var delta = point0.WellDepth - point0.BitDepth; var delta = point0.WellDepth - point0.BitDepth;

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using AsbCloudApp.Data.DetectedOperation;
using AsbCloudDb.Model; using AsbCloudDb.Model;
namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors; namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors;
@ -9,7 +10,7 @@ public class DetectorSlipsTime : DetectorAbstract
protected override double CalcValue(DetectableTelemetry[] telemetry, int begin, int end) protected override double CalcValue(DetectableTelemetry[] telemetry, int begin, int end)
=> CalcDeltaMinutes(telemetry, begin, end); => CalcDeltaMinutes(telemetry, begin, end);
protected override bool DetectBegin(DetectableTelemetry[] telemetry, int position, DetectedOperation? previousOperation) protected override bool DetectBegin(DetectableTelemetry[] telemetry, int position, DetectedOperationDto? previousOperation)
{ {
var point0 = telemetry[position]; var point0 = telemetry[position];
var delta = point0.WellDepth - point0.BitDepth; var delta = point0.WellDepth - point0.BitDepth;

View File

@ -1,5 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using AsbCloudDb.Model; using AsbCloudApp.Data.DetectedOperation;
using AsbCloudInfrastructure.Services.DetectOperations; using AsbCloudInfrastructure.Services.DetectOperations;
using AsbCloudInfrastructure.Services.DetectOperations.Detectors; using AsbCloudInfrastructure.Services.DetectOperations.Detectors;
using Xunit; using Xunit;
@ -10,7 +10,6 @@ public class DetectorDrillingTests : DetectorDrilling
{ {
private const int idSlide = 5002; private const int idSlide = 5002;
private const int idRotor = 5003; private const int idRotor = 5003;
private const int idSlideWithOscillation = 12000;
[Theory] [Theory]
[MemberData(nameof(TelemetryRangeDrillingRotor))] [MemberData(nameof(TelemetryRangeDrillingRotor))]
@ -54,7 +53,7 @@ public class DetectorDrillingTests : DetectorDrilling
//arrange //arrange
var operationDetectorResult = new OperationDetectorResult var operationDetectorResult = new OperationDetectorResult
{ {
Operation = new DetectedOperation Operation = new DetectedOperationDto
{ {
DepthStart = 5000, DepthStart = 5000,
DepthEnd = 6000, DepthEnd = 6000,
@ -76,7 +75,7 @@ public class DetectorDrillingTests : DetectorDrilling
//arrange //arrange
var operationDetectorResult = new OperationDetectorResult var operationDetectorResult = new OperationDetectorResult
{ {
Operation = new DetectedOperation Operation = new DetectedOperationDto
{ {
DepthStart = 5000, DepthStart = 5000,
DepthEnd = 5000, DepthEnd = 5000,
@ -201,7 +200,6 @@ public class DetectorDrillingTests : DetectorDrilling
{ {
new DetectableTelemetry new DetectableTelemetry
{ {
IdUser = 1,
WellDepth = 415.306f, WellDepth = 415.306f,
Pressure = 53.731934f, Pressure = 53.731934f,
HookWeight = 41.049942f, HookWeight = 41.049942f,
@ -211,7 +209,6 @@ public class DetectorDrillingTests : DetectorDrilling
}, },
new DetectableTelemetry new DetectableTelemetry
{ {
IdUser = 1,
WellDepth = 415.311f, WellDepth = 415.311f,
Pressure = 57.660595f, Pressure = 57.660595f,
HookWeight = 40.898712f, HookWeight = 40.898712f,
@ -221,7 +218,6 @@ public class DetectorDrillingTests : DetectorDrilling
}, },
new DetectableTelemetry new DetectableTelemetry
{ {
IdUser = 1,
WellDepth = 415.326f, WellDepth = 415.326f,
Pressure = 59.211086f, Pressure = 59.211086f,
HookWeight = 40.882797f, HookWeight = 40.882797f,
@ -231,7 +227,6 @@ public class DetectorDrillingTests : DetectorDrilling
}, },
new DetectableTelemetry new DetectableTelemetry
{ {
IdUser = 1,
WellDepth = 415.344f, WellDepth = 415.344f,
Pressure = 59.484406f, Pressure = 59.484406f,
HookWeight = 40.91972f, HookWeight = 40.91972f,
@ -241,7 +236,6 @@ public class DetectorDrillingTests : DetectorDrilling
}, },
new DetectableTelemetry new DetectableTelemetry
{ {
IdUser = 1,
WellDepth = 415.364f, WellDepth = 415.364f,
Pressure = 60.739918f, Pressure = 60.739918f,
HookWeight = 40.795666f, HookWeight = 40.795666f,
@ -251,7 +245,6 @@ public class DetectorDrillingTests : DetectorDrilling
}, },
new DetectableTelemetry new DetectableTelemetry
{ {
IdUser = 1,
WellDepth = 415.378f, WellDepth = 415.378f,
Pressure = 62.528984f, Pressure = 62.528984f,
HookWeight = 40.52114f, HookWeight = 40.52114f,
@ -261,7 +254,6 @@ public class DetectorDrillingTests : DetectorDrilling
}, },
new DetectableTelemetry new DetectableTelemetry
{ {
IdUser = 1,
WellDepth = 415.392f, WellDepth = 415.392f,
Pressure = 67.0039f, Pressure = 67.0039f,
HookWeight = 38.878895f, HookWeight = 38.878895f,
@ -271,7 +263,6 @@ public class DetectorDrillingTests : DetectorDrilling
}, },
new DetectableTelemetry new DetectableTelemetry
{ {
IdUser = 1,
WellDepth = 415.392f, WellDepth = 415.392f,
Pressure = 65.72418f, Pressure = 65.72418f,
HookWeight = 42.53173f, HookWeight = 42.53173f,
@ -281,7 +272,6 @@ public class DetectorDrillingTests : DetectorDrilling
}, },
new DetectableTelemetry new DetectableTelemetry
{ {
IdUser = 1,
WellDepth = 415.392f, WellDepth = 415.392f,
Pressure = 56.82195f, Pressure = 56.82195f,
HookWeight = 43.15844f, HookWeight = 43.15844f,