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