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. 49
      server/src/controllers/analytics_controller.ts

49
server/src/controllers/analytics_controller.ts

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

Loading…
Cancel
Save