2023-10-20 11:03:14 +05:00
|
|
|
using System;
|
|
|
|
using System.Linq;
|
|
|
|
using AsbCloudDb.Model;
|
|
|
|
|
|
|
|
namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors;
|
|
|
|
|
2023-11-15 09:33:26 +05:00
|
|
|
internal class DetectorDrilling : DetectorAbstract
|
2023-10-20 11:03:14 +05:00
|
|
|
{
|
|
|
|
public override Func<DetectableTelemetry[], int, int, int> GetIdOperation => DefineDrillingOperation;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (point0.RotorSpeed < 5)
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool IsValid(DetectableTelemetry[] telemetry, int begin, int end)
|
|
|
|
=> IsValidByWellDepthIncreasing(telemetry, begin, end);
|
|
|
|
|
|
|
|
protected override double CalcValue(DetectableTelemetry[] telemetry, int begin, int end)
|
|
|
|
=> CalcRop(telemetry, begin, end);
|
|
|
|
|
|
|
|
private static int DefineDrillingOperation(DetectableTelemetry[] telemetry, int begin, int end)
|
|
|
|
{
|
|
|
|
const int idSlideWithOscillation = 12000;
|
|
|
|
|
|
|
|
var telemetryRange = telemetry[begin.. end];
|
|
|
|
|
|
|
|
var avgRotorSpeed = telemetryRange.Average(t => t.RotorSpeed);
|
|
|
|
|
|
|
|
if (avgRotorSpeed < 10)
|
|
|
|
return WellOperationCategory.IdSlide;
|
|
|
|
|
|
|
|
var despersion = telemetryRange
|
|
|
|
.Average(t => Math.Pow((t.RotorSpeed - avgRotorSpeed) / avgRotorSpeed, 2));
|
|
|
|
|
|
|
|
return despersion < 0.2d ? WellOperationCategory.IdRotor : idSlideWithOscillation;
|
|
|
|
}
|
|
|
|
}
|