Browse Source

AnomalyDetector: Need at least 1 labeled segment #667 (#668)

pull/1/head
Alexandr Velikiy 6 years ago committed by rozetko
parent
commit
317a6a9572
  1. 27
      server/src/controllers/analytics_controller.ts

27
server/src/controllers/analytics_controller.ts

@ -120,27 +120,38 @@ async function getQueryRange(
analyticUnitId: AnalyticUnit.AnalyticUnitId,
detectorType: AnalyticUnit.DetectorType
): Promise<TimeRange> {
if(
detectorType === AnalyticUnit.DetectorType.PATTERN ||
detectorType === AnalyticUnit.DetectorType.ANOMALY
) {
const segments = await Segment.findMany(analyticUnitId, { $or: { labeled: true, deleted: true } });
let segments: Segment.Segment[];
switch(detectorType) {
case AnalyticUnit.DetectorType.PATTERN:
segments = await Segment.findMany(analyticUnitId, { $or: { labeled: true, deleted: true } });
if(segments.length === 0) {
throw new Error('Need at least 1 labeled segment');
}
return getQueryRangeForLearningBySegments(segments);
}
if(detectorType === AnalyticUnit.DetectorType.THRESHOLD) {
case AnalyticUnit.DetectorType.THRESHOLD:
const now = Date.now();
return {
from: now - 5 * SECONDS_IN_MINUTE * 1000,
to: now
};
case AnalyticUnit.DetectorType.ANOMALY:
segments = await Segment.findMany(analyticUnitId, { $or: { labeled: true, deleted: true } });
if(segments.length === 0) {
const now = Date.now();
return {
from: now - 5 * SECONDS_IN_MINUTE * 1000,
to: now
};
}
else {
return getQueryRangeForLearningBySegments(segments);
}
default:
throw new Error(`Cannot get query range for detector type ${detectorType}`);
}
}
async function query(

Loading…
Cancel
Save