|
|
@ -142,14 +142,15 @@ async function processLearningResult(taskResult: any): Promise<{ |
|
|
|
if(taskResult.status !== 'SUCCESS') { |
|
|
|
if(taskResult.status !== 'SUCCESS') { |
|
|
|
return Promise.reject(taskResult.error); |
|
|
|
return Promise.reject(taskResult.error); |
|
|
|
} |
|
|
|
} |
|
|
|
if(taskResult.segments === undefined || !Array.isArray(taskResult.segments)) { |
|
|
|
console.log(taskResult) |
|
|
|
throw new Error('Missing segments is result or it is corrupted: ' + taskResult); |
|
|
|
// if(taskResult.segments === undefined || !Array.isArray(taskResult.segments)) {
|
|
|
|
} |
|
|
|
// throw new Error('Missing segments in result or it is corrupted: ' + taskResult);
|
|
|
|
if(taskResult.lastPredictionTime === undefined || isNaN(+taskResult.lastPredictionTime)) { |
|
|
|
// }
|
|
|
|
throw new Error( |
|
|
|
// if(taskResult.lastPredictionTime === undefined || isNaN(+taskResult.lastPredictionTime)) {
|
|
|
|
'Missing lastPredictionTime is result or it is corrupted: ' + taskResult.lastPredictionTime |
|
|
|
// throw new Error(
|
|
|
|
); |
|
|
|
// 'Missing lastPredictionTime is result or it is corrupted: ' + taskResult.lastPredictionTime
|
|
|
|
} |
|
|
|
// );
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
return { |
|
|
|
lastPredictionTime: +taskResult.lastPredictionTime, |
|
|
|
lastPredictionTime: +taskResult.lastPredictionTime, |
|
|
@ -159,34 +160,34 @@ async function processLearningResult(taskResult: any): Promise<{ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export async function runPredict(id: AnalyticUnit.AnalyticUnitId) { |
|
|
|
export async function runPredict(id: AnalyticUnit.AnalyticUnitId) { |
|
|
|
// let unit = await AnalyticUnit.findById(id);
|
|
|
|
let unit = await AnalyticUnit.findById(id); |
|
|
|
// let pattern = unit.type;
|
|
|
|
let pattern = unit.type; |
|
|
|
// let task = {
|
|
|
|
|
|
|
|
// type: 'PREDICT',
|
|
|
|
let task = new AnalyticsTask( |
|
|
|
// analyticUnitId: id,
|
|
|
|
id, |
|
|
|
// pattern,
|
|
|
|
AnalyticsTaskType.PREDICT, |
|
|
|
// lastPredictionTime: unit.lastPredictionTime
|
|
|
|
{ pattern, lastPredictionTime: unit.lastPredictionTime } |
|
|
|
// };
|
|
|
|
); |
|
|
|
// let result = await runTask(task);
|
|
|
|
let result = await runTask(task); |
|
|
|
|
|
|
|
|
|
|
|
// if(result.status === 'FAILED') {
|
|
|
|
if(result.status === 'FAILED') { |
|
|
|
// return [];
|
|
|
|
return []; |
|
|
|
// }
|
|
|
|
} |
|
|
|
// // Merging segments
|
|
|
|
// Merging segments
|
|
|
|
// let segments = getLabeledSegments(id);
|
|
|
|
let segments = await Segment.findMany(id, { labeled: true }); |
|
|
|
// if(segments.length > 0 && result.segments.length > 0) {
|
|
|
|
if(segments.length > 0 && result.segments.length > 0) { |
|
|
|
// let lastOldSegment = segments[segments.length - 1];
|
|
|
|
let lastOldSegment = segments[segments.length - 1]; |
|
|
|
// let firstNewSegment = result.segments[0];
|
|
|
|
let firstNewSegment = result.segments[0]; |
|
|
|
|
|
|
|
|
|
|
|
// if(firstNewSegment.start <= lastOldSegment.finish) {
|
|
|
|
if(firstNewSegment.from <= lastOldSegment.to) { |
|
|
|
// result.segments[0].start = lastOldSegment.start;
|
|
|
|
result.segments[0].from = lastOldSegment.from; |
|
|
|
// removeSegments(id, [lastOldSegment.id]);
|
|
|
|
Segment.removeSegments([lastOldSegment.id]) |
|
|
|
// }
|
|
|
|
} |
|
|
|
// }
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// insertSegments(id, result.segments, false);
|
|
|
|
Segment.insertSegments(result.segments); |
|
|
|
// AnalyticUnit.setPredictionTime(id, result.lastPredictionTime);
|
|
|
|
AnalyticUnit.setPredictionTime(id, result.lastPredictionTime); |
|
|
|
// return result.segments;
|
|
|
|
return result.segments; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function isAnalyticReady(): boolean { |
|
|
|
export function isAnalyticReady(): boolean { |
|
|
|