|
|
@ -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); |
|
|
|
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(); |
|
|
|
const now = Date.now(); |
|
|
|
return { |
|
|
|
return { |
|
|
|
from: now - 5 * SECONDS_IN_MINUTE * 1000, |
|
|
|
from: now - 5 * SECONDS_IN_MINUTE * 1000, |
|
|
|
to: now |
|
|
|
to: now |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
return getQueryRangeForLearningBySegments(segments); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
default: |
|
|
|
throw new Error(`Cannot get query range for detector type ${detectorType}`); |
|
|
|
throw new Error(`Cannot get query range for detector type ${detectorType}`); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async function query( |
|
|
|
async function query( |
|
|
|