|
|
@ -51,7 +51,7 @@ async function onMessage(message: AnalyticsMessage) { |
|
|
|
methodResolved = true; |
|
|
|
methodResolved = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(message.method === AnalyticsMessageMethod.PREDICT) { |
|
|
|
if(message.method === AnalyticsMessageMethod.DETECT) { |
|
|
|
onPredict(message.payload); |
|
|
|
onPredict(message.payload); |
|
|
|
methodResolved = true; |
|
|
|
methodResolved = true; |
|
|
|
} |
|
|
|
} |
|
|
@ -159,7 +159,7 @@ export async function runPredict(id: AnalyticUnit.AnalyticUnitId) { |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
let unit = await AnalyticUnit.findById(id); |
|
|
|
let unit = await AnalyticUnit.findById(id); |
|
|
|
previousLastPredictionTime = unit.lastPredictionTime; |
|
|
|
previousLastPredictionTime = unit.lastDetectionTime; |
|
|
|
let pattern = unit.type; |
|
|
|
let pattern = unit.type; |
|
|
|
|
|
|
|
|
|
|
|
let segments = await Segment.findMany(id, { labeled: true }); |
|
|
|
let segments = await Segment.findMany(id, { labeled: true }); |
|
|
@ -183,8 +183,8 @@ export async function runPredict(id: AnalyticUnit.AnalyticUnitId) { |
|
|
|
} |
|
|
|
} |
|
|
|
let task = new AnalyticsTask( |
|
|
|
let task = new AnalyticsTask( |
|
|
|
id, |
|
|
|
id, |
|
|
|
AnalyticsTaskType.PREDICT, |
|
|
|
AnalyticsTaskType.DETECT, |
|
|
|
{ pattern, lastPredictionTime: unit.lastPredictionTime, data, cache: oldCache } |
|
|
|
{ pattern, lastPredictionTime: unit.lastDetectionTime, data, cache: oldCache } |
|
|
|
); |
|
|
|
); |
|
|
|
console.debug(`run task, id:${id}`); |
|
|
|
console.debug(`run task, id:${id}`); |
|
|
|
let result = await runTask(task); |
|
|
|
let result = await runTask(task); |
|
|
@ -209,13 +209,13 @@ export async function runPredict(id: AnalyticUnit.AnalyticUnitId) { |
|
|
|
|
|
|
|
|
|
|
|
Segment.insertSegments(payload.segments); |
|
|
|
Segment.insertSegments(payload.segments); |
|
|
|
AnalyticUnitCache.setData(id, payload.cache); |
|
|
|
AnalyticUnitCache.setData(id, payload.cache); |
|
|
|
AnalyticUnit.setPredictionTime(id, payload.lastPredictionTime); |
|
|
|
AnalyticUnit.setDetectionTime(id, payload.lastPredictionTime); |
|
|
|
AnalyticUnit.setStatus(id, AnalyticUnit.AnalyticUnitStatus.READY); |
|
|
|
AnalyticUnit.setStatus(id, AnalyticUnit.AnalyticUnitStatus.READY); |
|
|
|
} catch(err) { |
|
|
|
} catch(err) { |
|
|
|
let message = err.message || JSON.stringify(err); |
|
|
|
let message = err.message || JSON.stringify(err); |
|
|
|
await AnalyticUnit.setStatus(id, AnalyticUnit.AnalyticUnitStatus.FAILED, message); |
|
|
|
await AnalyticUnit.setStatus(id, AnalyticUnit.AnalyticUnitStatus.FAILED, message); |
|
|
|
if(previousLastPredictionTime !== undefined) { |
|
|
|
if(previousLastPredictionTime !== undefined) { |
|
|
|
await AnalyticUnit.setPredictionTime(id, previousLastPredictionTime); |
|
|
|
await AnalyticUnit.setDetectionTime(id, previousLastPredictionTime); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|