|
|
@ -106,6 +106,7 @@ async function runTask(task: AnalyticsTask): Promise<TaskResult> { |
|
|
|
async function query(analyticUnit: AnalyticUnit.AnalyticUnit, detector: AnalyticUnit.DetectorType) { |
|
|
|
async function query(analyticUnit: AnalyticUnit.AnalyticUnit, detector: AnalyticUnit.DetectorType) { |
|
|
|
let range; |
|
|
|
let range; |
|
|
|
if(detector === AnalyticUnit.DetectorType.PATTERN) { |
|
|
|
if(detector === AnalyticUnit.DetectorType.PATTERN) { |
|
|
|
|
|
|
|
// TODO: find labeled OR deleted segments to generate timerange
|
|
|
|
const segments = await Segment.findMany(analyticUnit.id, { labeled: true }); |
|
|
|
const segments = await Segment.findMany(analyticUnit.id, { labeled: 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'); |
|
|
@ -387,14 +388,10 @@ export async function updateSegments( |
|
|
|
segmentsToInsert: Segment.Segment[], |
|
|
|
segmentsToInsert: Segment.Segment[], |
|
|
|
removedIds: Segment.SegmentId[] |
|
|
|
removedIds: Segment.SegmentId[] |
|
|
|
) { |
|
|
|
) { |
|
|
|
let [addedIds, removed] = await Promise.all([ |
|
|
|
await Segment.removeSegments(removedIds); |
|
|
|
Segment.insertSegments(segmentsToInsert), |
|
|
|
const addedIds = await Segment.insertSegments(segmentsToInsert); |
|
|
|
Segment.setSegmentsDeleted(removedIds) |
|
|
|
|
|
|
|
]); |
|
|
|
|
|
|
|
removed = removed.map(s => s._id); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
runFirstLearning(id); |
|
|
|
return { addedIds }; |
|
|
|
return { addedIds, removed }; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export async function updateThreshold( |
|
|
|
export async function updateThreshold( |
|
|
@ -407,7 +404,7 @@ export async function updateThreshold( |
|
|
|
runFirstLearning(id); |
|
|
|
runFirstLearning(id); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async function runFirstLearning(id: AnalyticUnit.AnalyticUnitId) { |
|
|
|
export async function runFirstLearning(id: AnalyticUnit.AnalyticUnitId) { |
|
|
|
// TODO: move setting status somehow "inside" learning
|
|
|
|
// TODO: move setting status somehow "inside" learning
|
|
|
|
await AnalyticUnit.setStatus(id, AnalyticUnit.AnalyticUnitStatus.PENDING); |
|
|
|
await AnalyticUnit.setStatus(id, AnalyticUnit.AnalyticUnitStatus.PENDING); |
|
|
|
runLearning(id) |
|
|
|
runLearning(id) |
|
|
|