diff --git a/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorAbstract.cs b/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorAbstract.cs
index 0924849a..3da8d5d0 100644
--- a/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorAbstract.cs
+++ b/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorAbstract.cs
@@ -25,16 +25,16 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
this.IdCategory = IdCategory;
}
- public virtual DetectedOperation? DetectOrDefault(DetectableTelemetry[] telemetry, ref int position)
+ public virtual DetectedOperation? DetectOrDefault(DetectableTelemetry[] telemetry, ref int positionStart)
{
- if ((telemetry.Length > position + FragmentLength + StepLength) && DetectStart(telemetry, position))
+ if ((telemetry.Length > positionStart + FragmentLength + StepLength) && DetectStart(telemetry, positionStart))
{
- var skip = position + StepLength;
+ var skip = positionStart + StepLength;
while (telemetry.Length > skip + FragmentLength)
{
if (DetectEnd(telemetry, skip))
{
- var dateStart = telemetry[position].DateTime;
+ var dateStart = telemetry[positionStart].DateTime;
var dateEnd = telemetry[skip].DateTime;
var durationSec = (dateEnd - dateStart).TotalSeconds;
if (durationSec < MinDurationSeconds || durationSec > MaxDurationSeconds)
@@ -43,14 +43,18 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
var result = new DetectedOperation
{
IdCategory = IdCategory,
- IdUsersAtStart = telemetry[position].IdUser ?? -1,
+ IdUsersAtStart = telemetry[positionStart].IdUser ?? -1,
DateStart = dateStart,
DateEnd = dateEnd,
- DepthStart = telemetry[position].WellDepth ?? -1d,
+ DepthStart = telemetry[positionStart].WellDepth ?? -1d,
DepthEnd = telemetry[skip].WellDepth ?? -1d,
+ Value = CalcValue(telemetry, positionStart, skip),
};
- CalcValue(ref result);
- position = skip + FragmentLength;
+
+ if (!IsValid(result))
+ return null;
+
+ positionStart = skip;// + FragmentLength;
return result;
}
@@ -60,12 +64,34 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
return null;
}
- protected abstract void CalcValue(ref DetectedOperation result);
+ ///
+ /// Расчет ключевого параметра
+ ///
+ ///
+ protected abstract double CalcValue(DetectableTelemetry[] telemetry, int positionBegin, int positionEnd);
+ ///
+ /// Определение начала операции
+ ///
+ ///
+ ///
+ ///
protected abstract bool DetectStart(DetectableTelemetry[] telemetry, int position);
+ ///
+ /// Определение окончания операции
+ ///
+ ///
+ ///
+ ///
protected abstract bool DetectEnd(DetectableTelemetry[] telemetry, int position);
+ ///
+ /// Валидация операции
+ ///
+ ///
+ ///
+ protected abstract bool IsValid(DetectedOperation result);
}
#nullable disable
}
diff --git a/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorDrillingBase.cs b/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorDrillingBase.cs
new file mode 100644
index 00000000..258bdd2e
--- /dev/null
+++ b/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorDrillingBase.cs
@@ -0,0 +1,86 @@
+using AsbCloudDb.Model;
+using System.Linq;
+
+namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
+{
+ internal abstract class DetectorDrillingAbstract : DetectorAbstract
+ {
+ /* # РАСЧЕТ minRop
+ * шаг энкодера = 0.006м;
+ * 2 шага за 10 секунд не считается, так как может быть простым шумом;
+ * minRop = 0.006 * 2 / 10 = 0.0012 м/сек
+ * minRop > 4.32 м/ч & minRop < 6.48 м/ч (3 шага за 10 сек);
+ */
+ protected const double minRop = 5.4; //м/час
+ protected const double minRotorSpeed = 5; //об/мин
+ protected const double minPressure = 25;
+ protected const double minDeltaDepth = 0.01;
+
+ public DetectorDrillingAbstract(int IdCategory) : base(IdCategory)
+ {
+ FragmentLength = 12;
+ StepLength = 3;
+ }
+
+ protected override bool DetectStart(DetectableTelemetry[] telemetry, int position)
+ {
+ var firstItem = telemetry[position];
+ var deltaDepth = firstItem.WellDepth - firstItem.BitDepth;
+ if (deltaDepth is not null &&
+ System.Math.Abs((float)deltaDepth) > minDeltaDepth)
+ return false;
+
+ if (firstItem.Pressure < minPressure)
+ return false;
+
+ var fragment = telemetry[position..(position + FragmentLength)];
+
+ var lineBlockPosition = new InterpolationLine(fragment.Select(d => (d.BlockPosition ?? 0d, (d.DateTime - firstItem.DateTime).TotalHours)));
+ if (!lineBlockPosition.IsYDecreases(-minRop))
+ return false;
+
+ var lineWellDepth = new InterpolationLine(fragment.Select(d => ((d.WellDepth - firstItem.WellDepth) ?? 0d, (d.DateTime - firstItem.DateTime).TotalHours)));
+ if (!lineWellDepth.IsYIncreases(minRop))
+ return false;
+
+ if (!ModeCondition(fragment))
+ return false;
+
+ return true;
+ }
+
+ protected override bool DetectEnd(DetectableTelemetry[] telemetry, int position)
+ {
+ var firstItem = telemetry[position];
+ var deltaDepth = firstItem.WellDepth - firstItem.BitDepth;
+ if (deltaDepth is not null &&
+ System.Math.Abs((float)deltaDepth) > minDeltaDepth)
+ return true;
+
+ if (firstItem.Pressure < minPressure)
+ return true;
+
+ var fragment = telemetry[position..(position + FragmentLength)];
+ if (!ModeCondition(fragment))
+ return true;
+
+ return false;
+ }
+
+ protected abstract bool ModeCondition(DetectableTelemetry[] telemetryFragment);
+
+ ///
+ /// Рассчитываем МСП, м/час
+ ///
+ ///
+ protected override double CalcValue(DetectableTelemetry[] telemetry, int positionBegin, int positionEnd)
+ {
+ var pBegin = telemetry[positionBegin];
+ var pEnd = telemetry[positionEnd];
+ var result = (double)(pEnd.WellDepth - pBegin.WellDepth) / (pEnd.DateTime - pBegin.DateTime).TotalHours;
+ return result;
+ }
+ protected override bool IsValid(DetectedOperation result)
+ => result.Value > 0;
+ }
+}
\ No newline at end of file
diff --git a/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorDrillingRotor.cs b/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorDrillingRotor.cs
index 6810a05b..73cf8675 100644
--- a/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorDrillingRotor.cs
+++ b/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorDrillingRotor.cs
@@ -4,57 +4,15 @@ using System.Linq;
namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
{
#nullable enable
- class DetectorDrillingRotor : DetectorAbstract
+ class DetectorDrillingRotor : DetectorDrillingAbstract
{
- const double minRop = 5; //м/час
- const double minRotorSpeed = 5; //об/мин
- const double ticksPerHour = 60 * 60 * 10_000_000d;
- const double minPressure = 25;
- const double minDeltaDepth = 0.02;
+ public DetectorDrillingRotor()
+ : base(2){}
- public DetectorDrillingRotor() : base(2)
+ protected override bool ModeCondition(DetectableTelemetry[] telemetryFragment)
{
- FragmentLength = 15;
- StepLength = 10;
- }
-
- protected override bool DetectStart(DetectableTelemetry[] telemetry, int position)
- {
- var firstItem = telemetry[position];
- var deltaDepth = firstItem.WellDepth - firstItem.BitDepth;
- if (deltaDepth is not null &&
- System.Math.Abs((float)deltaDepth) > minDeltaDepth)
- return false;
-
- if(firstItem.RotorSpeed > minRotorSpeed)
- return false;
-
- if (firstItem.Pressure < minPressure)
- return false;
-
- var fragment = telemetry[position..(position + FragmentLength)];
-
- var lineBlockPosition = new InterpolationLine(fragment.Select(d => (d.BlockPosition ?? 0d, d.DateTime.Ticks / ticksPerHour)));
- if (!lineBlockPosition.IsYDecreases(minRop))
- return false;
-
- var lineWellDepth = new InterpolationLine(fragment.Select(d => (d.WellDepth ?? 0d, d.DateTime.Ticks / ticksPerHour)));
- if (!lineWellDepth.IsYIncreases(minRop))
- return false;
-
- return true;
- }
-
- protected override bool DetectEnd(DetectableTelemetry[] telemetry, int position)
- => !DetectStart(telemetry, position);
-
- ///
- /// Рассчитываем МСП, м/час
- ///
- ///
- protected override void CalcValue(ref DetectedOperation result)
- {
- result.Value = (result.DepthEnd - result.DepthStart) / (result.DateEnd - result.DateStart).TotalHours;
+ var lineRotorSpeed = new InterpolationLine(telemetryFragment.Select(d => (d.RotorSpeed ?? 0d, (d.DateTime - telemetryFragment[0].DateTime).TotalHours)));
+ return lineRotorSpeed.IsAverageYMoreThanBound(minRotorSpeed);
}
}
#nullable disable
diff --git a/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorDrillingSlide.cs b/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorDrillingSlide.cs
index 89f20ae6..d072e5bd 100644
--- a/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorDrillingSlide.cs
+++ b/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorDrillingSlide.cs
@@ -1,59 +1,17 @@
-using AsbCloudDb.Model;
-using System.Linq;
+using System.Linq;
namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
{
#nullable enable
- class DetectorDrillingSlide : DetectorAbstract
+ class DetectorDrillingSlide : DetectorDrillingAbstract
{
- const double minRop = 5; //м/час
- const double minRotorSpeed = 5; //об/мин
- const double ticksPerHour = 60 * 60 * 10_000_000d;
- const double minPressure = 25;
- const double minDeltaDepth = 0.02;
+ public DetectorDrillingSlide()
+ : base(3){}
- public DetectorDrillingSlide() : base(3)
+ protected override bool ModeCondition(DetectableTelemetry[] telemetryFragment)
{
- FragmentLength = 10;
- }
-
- protected override bool DetectStart(DetectableTelemetry[] telemetry, int position)
- {
- var firstItem = telemetry[position];
- var deltaDepth = firstItem.WellDepth - firstItem.BitDepth;
- if (deltaDepth is not null &&
- System.Math.Abs((float)deltaDepth) > minDeltaDepth)
- return false;
-
- if(firstItem.RotorSpeed < minRotorSpeed)
- return false;
-
- if (firstItem.Pressure < minPressure)
- return false;
-
- var fragment = telemetry[position..(position + FragmentLength)];
-
- var lineBlockPosition = new InterpolationLine(fragment.Select(d => (d.BlockPosition ?? 0d, d.DateTime.Ticks / ticksPerHour)));
- if (!lineBlockPosition.IsYDecreases(minRop))
- return false;
-
- var lineWellDepth = new InterpolationLine(fragment.Select(d => (d.WellDepth ?? 0d, d.DateTime.Ticks / ticksPerHour)));
- if (!lineWellDepth.IsYIncreases(minRop))
- return false;
-
- return true;
- }
-
- protected override bool DetectEnd(DetectableTelemetry[] telemetry, int position)
- => !DetectStart(telemetry, position);
-
- ///
- /// Рассчитываем МСП, м/час
- ///
- ///
- protected override void CalcValue(ref DetectedOperation result)
- {
- result.Value = (result.DepthEnd - result.DepthStart) / (result.DateEnd - result.DateStart).TotalHours;
+ var lineRotorSpeed = new InterpolationLine(telemetryFragment.Select(d => (d.RotorSpeed ?? 0d, (d.DateTime - telemetryFragment[0].DateTime).TotalHours)));
+ return lineRotorSpeed.IsAverageYLessThanBound(minRotorSpeed);
}
}
#nullable disable
diff --git a/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorSlipsTime.cs b/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorSlipsTime.cs
index ba8b70c6..870cd7bd 100644
--- a/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorSlipsTime.cs
+++ b/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorSlipsTime.cs
@@ -34,10 +34,17 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
return result;
}
- protected override void CalcValue(ref DetectedOperation result)
+ protected override double CalcValue(DetectableTelemetry[] telemetry, int positionBegin, int positionEnd)
{
- result.Value = result.DurationMinutes;
+ var pBegin = telemetry[positionBegin];
+ var pEnd = telemetry[positionEnd];
+ var result = (pEnd.DateTime - pBegin.DateTime).TotalMinutes;
+ return result;
}
+
+ protected override bool IsValid(DetectedOperation result)
+ => result.Value > 0;
+
}
#nullable disable
}
diff --git a/ConsoleApp1/Program.cs b/ConsoleApp1/Program.cs
index c4f6f029..0e85aa5f 100644
--- a/ConsoleApp1/Program.cs
+++ b/ConsoleApp1/Program.cs
@@ -12,6 +12,26 @@ namespace ConsoleApp1
// use ServiceFactory to make services
static void Main(/*string[] args*/)
{
+ System.Collections.Generic.List<(double, double)> data = new() {
+ (22.52400016784668, 17715023.435277779) ,
+ (22.52400016784668, 17715023.435555555) ,
+ (22.52400016784668, 17715023.435833335) ,
+ (22.52400016784668, 17715023.436111111) ,
+ (22.547000885009766, 17715023.436388887) ,
+ (22.833000183105469, 17715023.436666667) ,
+ (23.063999176025391, 17715023.436944444) ,
+ (23.298999786376953, 17715023.437222224) ,
+ (23.5310001373291, 17715023.4375) ,
+ (23.763999938964844, 17715023.437777776) ,
+ (23.993999481201172, 17715023.438055556) ,
+ (24.229999542236328, 17715023.438333333) ,
+ (24.459999084472656, 17715023.438611113) ,
+ (24.694999694824219, 17715023.438888889) ,
+ (24.926000595092773, 17715023.439166665) ,
+ };
+
+ var il = new AsbCloudInfrastructure.Services.DetectOperations.InterpolationLine(data);
+
Console.WriteLine("hit keyboard to start");
Console.ReadLine();
diff --git a/ConsoleApp1/Properties/launchSettings.json b/ConsoleApp1/Properties/launchSettings.json
deleted file mode 100644
index 33504c94..00000000
--- a/ConsoleApp1/Properties/launchSettings.json
+++ /dev/null
@@ -1,8 +0,0 @@
-{
- "profiles": {
- "WSL": {
- "commandName": "WSL2",
- "distributionName": ""
- }
- }
-}
\ No newline at end of file