forked from ddrilling/AsbCloudServer
slow detection
This commit is contained in:
parent
d0386b0182
commit
9ab41cd24e
@ -19,15 +19,14 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
|
|||||||
public int StepLength { get => stepLength; set => stepLength = value; }
|
public int StepLength { get => stepLength; set => stepLength = value; }
|
||||||
|
|
||||||
public FragmentDetector(
|
public FragmentDetector(
|
||||||
Func<DetectableTelemetry[], int, bool> detectStart,
|
Func<DetectableTelemetry[], int, bool> detectStart,
|
||||||
IFragmentDetector detector,
|
IFragmentDetector detector,
|
||||||
params IFragmentDetector[] detectors)
|
params IFragmentDetector[] detectors)
|
||||||
{
|
{
|
||||||
this.detectStart = detectStart;
|
this.detectStart = detectStart;
|
||||||
this.detectors = JoinDetectors(detector, detectors);
|
this.detectors = JoinDetectors(detector, detectors);
|
||||||
detectEnd = (f, i) => !detectStart(f,i);
|
detectEnd = (f, i) => !detectStart(f, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
public FragmentDetector(
|
public FragmentDetector(
|
||||||
Func<DetectableTelemetry[], int, bool> detectStart,
|
Func<DetectableTelemetry[], int, bool> detectStart,
|
||||||
Func<DetectableTelemetry[], int, bool> detectEnd,
|
Func<DetectableTelemetry[], int, bool> detectEnd,
|
||||||
@ -92,49 +91,36 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
|
|||||||
return detect;
|
return detect;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IFragmentDetector AddChildDetector(params IFragmentDetector[] detectors)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public IDetector AddOperationDetector(IOperationDetector operation)
|
|
||||||
{
|
|
||||||
detectors = new IOperationDetector[] { operation};
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool TryDetect(int idTelemetry, DetectableTelemetry[] telemetryFragment, out IEnumerable<DetectedOperation> operations)
|
public bool TryDetect(int idTelemetry, DetectableTelemetry[] telemetryFragment, out IEnumerable<DetectedOperation> operations)
|
||||||
{
|
{
|
||||||
var positionStart = 0;
|
var positionStart = 0;
|
||||||
var operationsList = new List<DetectedOperation>();
|
var operationsList = new List<DetectedOperation>();
|
||||||
// поиск начала соответствия критерию
|
// проверка соответствия критерию начала операции
|
||||||
while (telemetryFragment.Length > positionStart + FragmentLength + stepLength)
|
if (detectStart(telemetryFragment, positionStart))
|
||||||
{
|
{
|
||||||
if (detectStart(telemetryFragment, positionStart))
|
// Поиск окончания соответствия критерию
|
||||||
|
var positionEnd = positionStart + stepLength;
|
||||||
|
while (telemetryFragment.Length > positionEnd + FragmentLength)
|
||||||
{
|
{
|
||||||
// Поиск окончания соответствия критерию
|
if (detectEnd(telemetryFragment, positionEnd))
|
||||||
var positionEnd = positionStart + stepLength;
|
|
||||||
while (telemetryFragment.Length > positionEnd + FragmentLength)
|
|
||||||
{
|
{
|
||||||
if (detectEnd(telemetryFragment, positionEnd))
|
var innerFragment = telemetryFragment[positionStart..positionEnd];
|
||||||
{
|
var detectorEnumerator = detectors.GetEnumerator();
|
||||||
var innerFragment = telemetryFragment[positionStart..positionEnd];
|
while (detectorEnumerator.MoveNext())
|
||||||
var detectorEnumerator = detectors.GetEnumerator();
|
if (detectorEnumerator.Current.TryDetect(idTelemetry, innerFragment, out IEnumerable<DetectedOperation> result))
|
||||||
while(detectorEnumerator.MoveNext())
|
operationsList.AddRange(result);
|
||||||
if (detectorEnumerator.Current.TryDetect(idTelemetry, innerFragment, out IEnumerable<DetectedOperation> result))
|
|
||||||
operationsList.AddRange(result);
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
positionEnd += stepLength;
|
|
||||||
}
|
}
|
||||||
positionStart = positionEnd;
|
positionEnd += stepLength;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
positionStart += stepLength;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
operations = Enumerable.Empty<DetectedOperation>();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
operations = operationsList;
|
operations = operationsList;
|
||||||
return operationsList.Any();
|
return operationsList.Any();
|
||||||
}
|
}
|
||||||
|
@ -13,5 +13,5 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
|
|||||||
{ }
|
{ }
|
||||||
|
|
||||||
internal interface IFragmentDetector: IDetector
|
internal interface IFragmentDetector: IDetector
|
||||||
{ }
|
{ }
|
||||||
}
|
}
|
@ -136,7 +136,7 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
|
|||||||
})
|
})
|
||||||
.OrderBy(d => d.DateTime);
|
.OrderBy(d => d.DateTime);
|
||||||
|
|
||||||
var take = 4 * 86_400;// 4 дня
|
var take = 4 * 86_400; // 4 дня
|
||||||
var startDate = begin;
|
var startDate = begin;
|
||||||
var detectedOperations = new List<DetectedOperation>(8);
|
var detectedOperations = new List<DetectedOperation>(8);
|
||||||
|
|
||||||
@ -151,23 +151,36 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
var isDetected = false;
|
var isDetected = false;
|
||||||
|
var positionStart = 0;
|
||||||
foreach (var detector in detectors)
|
while (data.Length > positionStart + minFragmentLength + minStepLength)
|
||||||
{
|
{
|
||||||
if (detector is FragmentDetector fragmentDetector)
|
var telemetryFragment = data[positionStart..];
|
||||||
|
var isDetected1 = false;
|
||||||
|
foreach (var detector in detectors)
|
||||||
{
|
{
|
||||||
var minLengthToDetect = fragmentDetector.StepLength + fragmentDetector.FragmentLength;
|
if (detector is FragmentDetector fragmentDetector)
|
||||||
if (data.Length < minLengthToDetect)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (fragmentDetector.TryDetect(idTelemetry, data, out IEnumerable<DetectedOperation> operations))
|
|
||||||
{
|
{
|
||||||
isDetected = true;
|
var minLengthToDetect = fragmentDetector.StepLength + fragmentDetector.FragmentLength;
|
||||||
detectedOperations.AddRange(operations);
|
if (telemetryFragment.Length < minLengthToDetect)
|
||||||
startDate = operations.Last().DateEnd;
|
continue;
|
||||||
break;
|
|
||||||
|
if (fragmentDetector.TryDetect(idTelemetry, data, out IEnumerable<DetectedOperation> operations))
|
||||||
|
{
|
||||||
|
isDetected = true;
|
||||||
|
isDetected1 = true;
|
||||||
|
detectedOperations.AddRange(operations);
|
||||||
|
startDate = operations.Last().DateEnd;
|
||||||
|
positionStart = 0;
|
||||||
|
data = data
|
||||||
|
.Where(d => d.DateTime > startDate)
|
||||||
|
.ToArray();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isDetected1)
|
||||||
|
positionStart += minStepLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isDetected)
|
if (!isDetected)
|
||||||
|
Loading…
Reference in New Issue
Block a user