|
|
@ -1,12 +1,6 @@ |
|
|
|
import { |
|
|
|
|
|
|
|
AnalyticUnit, |
|
|
|
|
|
|
|
AnalyticUnitId, |
|
|
|
|
|
|
|
findById, |
|
|
|
|
|
|
|
setPredictionTime, |
|
|
|
|
|
|
|
setStatus |
|
|
|
|
|
|
|
} from '../models/analytic_unit' |
|
|
|
|
|
|
|
import { getTarget } from './metrics_controler'; |
|
|
|
import { getTarget } from './metrics_controler'; |
|
|
|
import { getLabeledSegments, insertSegments, removeSegments } from './segments_controller' |
|
|
|
import { getLabeledSegments, insertSegments, removeSegments } from './segments_controller' |
|
|
|
|
|
|
|
import * as AnalyticUnit from '../models/analytic_unit' |
|
|
|
import { AnalyticsConnection } from '../services/analytics_service' |
|
|
|
import { AnalyticsConnection } from '../services/analytics_service' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -28,7 +22,7 @@ function onResponse(response: any) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async function runTask(task): Promise<any> { |
|
|
|
async function runTask(task): Promise<any> { |
|
|
|
let anomaly: AnalyticUnit = findById(task.analyticUnitId); |
|
|
|
let anomaly: AnalyticUnit.AnalyticUnit = AnalyticUnit.findById(task.analyticUnitId); |
|
|
|
task.metric = { |
|
|
|
task.metric = { |
|
|
|
datasource: anomaly.metric.datasource, |
|
|
|
datasource: anomaly.metric.datasource, |
|
|
|
targets: anomaly.metric.targets.map(getTarget) |
|
|
|
targets: anomaly.metric.targets.map(getTarget) |
|
|
@ -42,11 +36,11 @@ async function runTask(task): Promise<any> { |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export async function runLearning(id: AnalyticUnitId) { |
|
|
|
export async function runLearning(id: AnalyticUnit.AnalyticUnitId) { |
|
|
|
let segments = getLabeledSegments(id); |
|
|
|
let segments = getLabeledSegments(id); |
|
|
|
setStatus(id, 'learning'); |
|
|
|
AnalyticUnit.setStatus(id, 'learning'); |
|
|
|
let anomaly: AnalyticUnit = findById(id); |
|
|
|
let unit = AnalyticUnit.findById(id); |
|
|
|
let pattern = anomaly.type; |
|
|
|
let pattern = unit.type; |
|
|
|
let task = { |
|
|
|
let task = { |
|
|
|
analyticUnitId: id, |
|
|
|
analyticUnitId: id, |
|
|
|
type: 'learn', |
|
|
|
type: 'learn', |
|
|
@ -57,16 +51,16 @@ export async function runLearning(id: AnalyticUnitId) { |
|
|
|
let result = await runTask(task); |
|
|
|
let result = await runTask(task); |
|
|
|
|
|
|
|
|
|
|
|
if (result.status === 'success') { |
|
|
|
if (result.status === 'success') { |
|
|
|
setStatus(id, 'ready'); |
|
|
|
AnalyticUnit.setStatus(id, 'ready'); |
|
|
|
insertSegments(id, result.segments, false); |
|
|
|
insertSegments(id, result.segments, false); |
|
|
|
setPredictionTime(id, result.lastPredictionTime); |
|
|
|
AnalyticUnit.setPredictionTime(id, result.lastPredictionTime); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
setStatus(id, 'failed', result.error); |
|
|
|
AnalyticUnit.setStatus(id, 'failed', result.error); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export async function runPredict(id: AnalyticUnitId) { |
|
|
|
export async function runPredict(id: AnalyticUnit.AnalyticUnitId) { |
|
|
|
let unit: AnalyticUnit = findById(id); |
|
|
|
let unit = AnalyticUnit.findById(id); |
|
|
|
let pattern = unit.type; |
|
|
|
let pattern = unit.type; |
|
|
|
let task = { |
|
|
|
let task = { |
|
|
|
type: 'predict', |
|
|
|
type: 'predict', |
|
|
@ -92,6 +86,6 @@ export async function runPredict(id: AnalyticUnitId) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
insertSegments(id, result.segments, false); |
|
|
|
insertSegments(id, result.segments, false); |
|
|
|
setPredictionTime(id, result.last_prediction_time); |
|
|
|
AnalyticUnit.setPredictionTime(id, result.lastPredictionTime); |
|
|
|
return result.segments; |
|
|
|
return result.segments; |
|
|
|
} |
|
|
|
} |
|
|
|