forked from ddrilling/AsbCloudServer
71 lines
2.7 KiB
C#
71 lines
2.7 KiB
C#
|
using AsbCloudDb.Model;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace AsbCloudInfrastructure.Services.DetectOperations
|
|||
|
{
|
|||
|
|
|||
|
#nullable enable
|
|||
|
abstract class DetectorAbstract
|
|||
|
{
|
|||
|
/* ## Концепт определения операций
|
|||
|
* Есть словарь детекторов.
|
|||
|
* Определить начальную позицию архива.
|
|||
|
* Пройти детекторами до конца архива.
|
|||
|
* Каждый детектор на небольшому фрагменту определяет начало операции.
|
|||
|
* При нахождении начала ищет конец и смещает положение поиска
|
|||
|
*/
|
|||
|
public int StepLength { get; set; } = 3;
|
|||
|
public int FragmentLength { get; set; } = 6;
|
|||
|
public int IdOperationType { get; }
|
|||
|
public string OperationName { get; }
|
|||
|
|
|||
|
// TODO: assert MaxDurationSeconds and MinDurationSeconds
|
|||
|
public double MaxDurationSeconds { get; } = 31 * 24 * 60 * 60;
|
|||
|
public double MinDurationSeconds { get; } = 3;
|
|||
|
|
|||
|
public DetectorAbstract(int idType, string operationName)
|
|||
|
{
|
|||
|
IdOperationType = idType;
|
|||
|
OperationName = operationName;
|
|||
|
}
|
|||
|
|
|||
|
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))
|
|||
|
{
|
|||
|
var result = new DetectedOperation
|
|||
|
{
|
|||
|
IdType = IdOperationType,
|
|||
|
IdUsersAtStart = telemetry[position].IdUser ?? -1,
|
|||
|
Begin = telemetry[position].DateTime,
|
|||
|
End = telemetry[skip].DateTime,
|
|||
|
BeginWellDepth = telemetry[position].WellDepth ?? -1d,
|
|||
|
EndWellDepth = telemetry[skip].WellDepth ?? -1d,
|
|||
|
};
|
|||
|
position = skip + FragmentLength;
|
|||
|
return result;
|
|||
|
}
|
|||
|
|
|||
|
skip = skip + StepLength;
|
|||
|
}
|
|||
|
}
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
protected abstract bool DetectStart(DetectableTelemetry[] telemetry, int position);
|
|||
|
|
|||
|
protected abstract bool DetectEnd(DetectableTelemetry[] telemetry, int position);
|
|||
|
|
|||
|
}
|
|||
|
#nullable disable
|
|||
|
}
|