2023-10-20 11:03:14 +05:00
|
|
|
using System;
|
|
|
|
using System.Linq;
|
|
|
|
using AsbCloudDb.Model;
|
|
|
|
|
|
|
|
namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors;
|
|
|
|
|
2023-11-22 14:47:17 +05:00
|
|
|
public class DetectorDrilling : DetectorAbstract
|
2023-10-20 11:03:14 +05:00
|
|
|
{
|
2023-11-22 14:47:17 +05:00
|
|
|
protected override Func<DetectableTelemetry[], int, int, int> GetIdOperation => DefineDrillingOperation;
|
2023-10-20 11:03:14 +05:00
|
|
|
|
|
|
|
protected override bool DetectBegin(DetectableTelemetry[] telemetry, int position, DetectedOperation? previousOperation)
|
|
|
|
{
|
|
|
|
var point0 = telemetry[position];
|
|
|
|
var delta = point0.WellDepth - point0.BitDepth;
|
|
|
|
if (delta > 0.03d)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (point0.Pressure < 25)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override int DetectEnd(DetectableTelemetry[] telemetry, int position, DetectedOperation? previousOperation)
|
|
|
|
{
|
|
|
|
var point0 = telemetry[position];
|
|
|
|
var delta = point0.WellDepth - point0.BitDepth;
|
|
|
|
|
|
|
|
if (delta > 0.03d)
|
|
|
|
return IdReasonOfEnd_DeltaDepthIsHi;
|
|
|
|
|
|
|
|
if (point0.Pressure < 25)
|
|
|
|
return IdReasonOfEnd_PressureIsLo;
|
|
|
|
|
|
|
|
return IdReasonOfEnd_NotDetected;
|
|
|
|
}
|
2023-11-22 14:47:17 +05:00
|
|
|
|
2023-10-20 11:03:14 +05:00
|
|
|
protected override double CalcValue(DetectableTelemetry[] telemetry, int begin, int end)
|
|
|
|
=> CalcRop(telemetry, begin, end);
|
|
|
|
|
2023-11-22 14:47:17 +05:00
|
|
|
protected override bool IsValidOperationDetectorResult(OperationDetectorResult operationDetectorResult) =>
|
|
|
|
operationDetectorResult.Operation.IdReasonOfEnd is IdReasonOfEnd_DeltaDepthIsHi or IdReasonOfEnd_PressureIsLo &&
|
|
|
|
Math.Abs(operationDetectorResult.Operation.DepthStart - operationDetectorResult.Operation.DepthEnd) > 0.01;
|
|
|
|
|
2023-10-20 11:03:14 +05:00
|
|
|
private static int DefineDrillingOperation(DetectableTelemetry[] telemetry, int begin, int end)
|
|
|
|
{
|
|
|
|
const int idSlideWithOscillation = 12000;
|
|
|
|
|
2023-11-22 14:47:17 +05:00
|
|
|
var telemetryRange = telemetry[begin.. end]
|
|
|
|
.OrderBy(x => x.DateTime).ToList();
|
|
|
|
|
|
|
|
for (var i = telemetryRange.Count - 1; i >= 0 && telemetryRange.Count > 1; i--)
|
|
|
|
{
|
|
|
|
if (Math.Abs(telemetryRange[i].WellDepth - telemetryRange[i - 1].WellDepth) < 0.001d)
|
|
|
|
{
|
|
|
|
telemetryRange.RemoveAt(i);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-10-20 11:03:14 +05:00
|
|
|
var avgRotorSpeed = telemetryRange.Average(t => t.RotorSpeed);
|
2023-11-22 14:47:17 +05:00
|
|
|
|
2023-10-20 11:03:14 +05:00
|
|
|
if (avgRotorSpeed < 10)
|
|
|
|
return WellOperationCategory.IdSlide;
|
2023-11-22 14:47:17 +05:00
|
|
|
|
|
|
|
var despersion = telemetryRange.Average(t => Math.Pow(t.RotorSpeed/avgRotorSpeed - 1, 2));
|
2023-10-20 11:03:14 +05:00
|
|
|
|
|
|
|
return despersion < 0.2d ? WellOperationCategory.IdRotor : idSlideWithOscillation;
|
|
|
|
}
|
|
|
|
}
|