|
|
@ -1,9 +1,9 @@ |
|
|
|
import { |
|
|
|
import { |
|
|
|
AnalyticUnit, |
|
|
|
AnalyticUnit, |
|
|
|
AnalyticUnitId, getAnomalyTypeInfo, |
|
|
|
AnalyticUnitId, |
|
|
|
loadById, |
|
|
|
findById, |
|
|
|
setPredictionTime, |
|
|
|
setPredictionTime, |
|
|
|
setAnomalyStatus |
|
|
|
setStatus |
|
|
|
} from '../models/analytic_unit' |
|
|
|
} from '../models/analytic_unit' |
|
|
|
import { getTarget } from './metrics'; |
|
|
|
import { getTarget } from './metrics'; |
|
|
|
import { getLabeledSegments, insertSegments, removeSegments } from './segments' |
|
|
|
import { getLabeledSegments, insertSegments, removeSegments } from './segments' |
|
|
@ -28,10 +28,10 @@ function onResponse(response: any) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async function runTask(task): Promise<any> { |
|
|
|
async function runTask(task): Promise<any> { |
|
|
|
let anomaly: AnalyticUnit = loadById(task.predictor_id); |
|
|
|
let anomaly: AnalyticUnit = findById(task.analyticUnitId); |
|
|
|
task.metric = { |
|
|
|
task.metric = { |
|
|
|
datasource: anomaly.metric.datasource, |
|
|
|
datasource: anomaly.metric.datasource, |
|
|
|
targets: anomaly.metric.targets.map(t => getTarget(t)) |
|
|
|
targets: anomaly.metric.targets.map(getTarget) |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
task.__task_id = nextTaskId++; |
|
|
|
task.__task_id = nextTaskId++; |
|
|
@ -42,14 +42,14 @@ async function runTask(task): Promise<any> { |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export async function runLearning(predictorId:AnalyticUnitId) { |
|
|
|
export async function runLearning(id: AnalyticUnitId) { |
|
|
|
let segments = getLabeledSegments(predictorId); |
|
|
|
let segments = getLabeledSegments(id); |
|
|
|
setAnomalyStatus(predictorId, 'learning'); |
|
|
|
setStatus(id, 'learning'); |
|
|
|
let anomaly:AnalyticUnit = loadById(predictorId); |
|
|
|
let anomaly: AnalyticUnit = findById(id); |
|
|
|
let pattern = anomaly.type; |
|
|
|
let pattern = anomaly.type; |
|
|
|
let task = { |
|
|
|
let task = { |
|
|
|
|
|
|
|
analyticUnitId: id, |
|
|
|
type: 'learn', |
|
|
|
type: 'learn', |
|
|
|
predictor_id: predictorId, |
|
|
|
|
|
|
|
pattern, |
|
|
|
pattern, |
|
|
|
segments: segments |
|
|
|
segments: segments |
|
|
|
}; |
|
|
|
}; |
|
|
@ -57,22 +57,22 @@ export async function runLearning(predictorId:AnalyticUnitId) { |
|
|
|
let result = await runTask(task); |
|
|
|
let result = await runTask(task); |
|
|
|
|
|
|
|
|
|
|
|
if (result.status === 'success') { |
|
|
|
if (result.status === 'success') { |
|
|
|
setAnomalyStatus(predictorId, 'ready'); |
|
|
|
setStatus(id, 'ready'); |
|
|
|
insertSegments(predictorId, result.segments, false); |
|
|
|
insertSegments(id, result.segments, false); |
|
|
|
setPredictionTime(predictorId, result.last_prediction_time); |
|
|
|
setPredictionTime(id, result.lastPredictionTime); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
setAnomalyStatus(predictorId, 'failed', result.error); |
|
|
|
setStatus(id, 'failed', result.error); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export async function runPredict(predictorId:AnalyticUnitId) { |
|
|
|
export async function runPredict(id: AnalyticUnitId) { |
|
|
|
let anomaly:AnalyticUnit = loadById(predictorId); |
|
|
|
let unit: AnalyticUnit = findById(id); |
|
|
|
let pattern = anomaly.type; |
|
|
|
let pattern = unit.type; |
|
|
|
let task = { |
|
|
|
let task = { |
|
|
|
type: 'predict', |
|
|
|
type: 'predict', |
|
|
|
predictor_id: predictorId, |
|
|
|
predictor_id: id, |
|
|
|
pattern, |
|
|
|
pattern, |
|
|
|
last_prediction_time: anomaly.lastPredictionTime |
|
|
|
lastPredictionTime: unit.lastPredictionTime |
|
|
|
}; |
|
|
|
}; |
|
|
|
let result = await runTask(task); |
|
|
|
let result = await runTask(task); |
|
|
|
|
|
|
|
|
|
|
@ -80,18 +80,18 @@ export async function runPredict(predictorId:AnalyticUnitId) { |
|
|
|
return []; |
|
|
|
return []; |
|
|
|
} |
|
|
|
} |
|
|
|
// Merging segments
|
|
|
|
// Merging segments
|
|
|
|
let segments = getLabeledSegments(predictorId); |
|
|
|
let segments = getLabeledSegments(id); |
|
|
|
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.start <= lastOldSegment.finish) { |
|
|
|
result.segments[0].start = lastOldSegment.start; |
|
|
|
result.segments[0].start = lastOldSegment.start; |
|
|
|
removeSegments(predictorId, [lastOldSegment.id]); |
|
|
|
removeSegments(id, [lastOldSegment.id]); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
insertSegments(predictorId, result.segments, false); |
|
|
|
insertSegments(id, result.segments, false); |
|
|
|
setPredictionTime(predictorId, result.last_prediction_time); |
|
|
|
setPredictionTime(id, result.last_prediction_time); |
|
|
|
return result.segments; |
|
|
|
return result.segments; |
|
|
|
} |
|
|
|
} |