DD.WellWorkover.Cloud/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorAbstract.cs

72 lines
2.8 KiB
C#
Raw Normal View History

2022-04-22 17:17:38 +05:00
using AsbCloudDb.Model;
namespace AsbCloudInfrastructure.Services.DetectOperations
{
#nullable enable
2022-04-28 15:04:13 +05:00
2022-04-22 17:17:38 +05:00
abstract class DetectorAbstract
{
public int StepLength { get; set; } = 3;
public int FragmentLength { get; set; } = 6;
2022-04-28 15:04:13 +05:00
public int IdCategory { get; }
2022-04-22 17:17:38 +05:00
// TODO: assert MaxDurationSeconds and MinDurationSeconds
public double MaxDurationSeconds { get; } = 31 * 24 * 60 * 60;
public double MinDurationSeconds { get; } = 3;
2022-04-28 15:04:13 +05:00
/// <summary>
/// Конструктор детектора.
/// Словарь с IdCategory в дефолтных данных AsbCloudDbContext для таблицы WellOperationCategory
/// </summary>
/// <param name="IdCategory">ключ названия/описания операции из таблицы WellOperationCategory</param>
public DetectorAbstract(int IdCategory)
2022-04-22 17:17:38 +05:00
{
2022-04-28 15:04:13 +05:00
this.IdCategory = IdCategory;
2022-04-22 17:17:38 +05:00
}
public virtual DetectedOperation? DetectOrDefault(DetectableTelemetry[] telemetry, ref int position)
{
if ((telemetry.Length > position + FragmentLength + StepLength) && DetectStart(telemetry, position))
{
var skip = position + StepLength;
while (telemetry.Length > skip + FragmentLength)
{
if (DetectEnd(telemetry, skip))
{
2022-04-29 15:54:01 +05:00
var dateStart = telemetry[position].DateTime;
var dateEnd = telemetry[skip].DateTime;
var durationSec = (dateEnd - dateStart).TotalSeconds;
if (durationSec < MinDurationSeconds || durationSec > MaxDurationSeconds)
return null;
2022-04-22 17:17:38 +05:00
var result = new DetectedOperation
{
2022-04-28 15:04:13 +05:00
IdCategory = IdCategory,
2022-04-22 17:17:38 +05:00
IdUsersAtStart = telemetry[position].IdUser ?? -1,
2022-04-29 15:54:01 +05:00
DateStart = dateStart,
DateEnd = dateEnd,
DepthStart = telemetry[position].WellDepth ?? -1d,
DepthEnd = telemetry[skip].WellDepth ?? -1d,
2022-04-22 17:17:38 +05:00
};
CalcValue(ref result);
2022-04-22 17:17:38 +05:00
position = skip + FragmentLength;
return result;
}
skip = skip + StepLength;
}
}
return null;
}
protected abstract void CalcValue(ref DetectedOperation result);
2022-04-22 17:17:38 +05:00
protected abstract bool DetectStart(DetectableTelemetry[] telemetry, int position);
protected abstract bool DetectEnd(DetectableTelemetry[] telemetry, int position);
}
#nullable disable
}