Browse Source

basic anomaly model (#630)

pull/1/head
Coin de Gamma 6 years ago committed by GitHub
parent
commit
af3c90d6aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 86
      server/src/models/analytic_units/anomaly_analytic_unit_model.ts
  2. 7
      server/src/models/analytic_units/types.ts
  3. 3
      server/src/models/analytic_units/utils.ts

86
server/src/models/analytic_units/anomaly_analytic_unit_model.ts

@ -0,0 +1,86 @@
import { AnalyticUnit } from './analytic_unit_model';
import { AnalyticUnitId, AnalyticUnitStatus, DetectorType } from './types';
import { Metric } from 'grafana-datasource-kit';
export class AnomalyAnalyticUnit extends AnalyticUnit {
constructor(
name: string,
grafanaUrl: string,
panelId: string,
type: string,
public alpha: number,
public confidence: number,
metric?: Metric,
alert?: boolean,
id?: AnalyticUnitId,
lastDetectionTime?: number,
status?: AnalyticUnitStatus,
error?: string,
labeledColor?: string,
deletedColor?: string,
visible?: boolean
) {
super(
name,
grafanaUrl,
panelId,
type,
metric,
alert,
id,
lastDetectionTime,
status,
error,
labeledColor,
deletedColor,
DetectorType.THRESHOLD,
visible
);
}
toObject() {
const baseObject = super.toObject();
return {
...baseObject,
alpha: this.alpha,
confidence: this.confidence
};
}
toPanelObject() {
const baseObject = super.toPanelObject();
return {
...baseObject,
alpha: this.alpha,
confidence: this.confidence
};
}
static fromObject(obj: any) {
// TODO: remove duplication
let metric: Metric;
if (obj.metric !== undefined) {
metric = Metric.fromObject(obj.metric);
}
return new AnomalyAnalyticUnit(
obj.name,
obj.grafanaUrl,
obj.panelId,
obj.type,
obj.alpha,
obj.confidence,
metric,
obj.alert,
obj._id,
obj.lastDetectionTime,
obj.status,
obj.error,
obj.labeledColor,
obj.deletedColor,
obj.visible
);
}
}

7
server/src/models/analytic_units/types.ts

@ -50,6 +50,12 @@ export const ANALYTIC_UNIT_TYPES = {
value: 'DROP' value: 'DROP'
} }
], ],
anomaly: [
{
name: 'Anomaly',
value: 'ANOMALY'
}
],
threshold: [ threshold: [
{ {
name: 'Threshold', name: 'Threshold',
@ -60,5 +66,6 @@ export const ANALYTIC_UNIT_TYPES = {
export enum DetectorType { export enum DetectorType {
PATTERN = 'pattern', PATTERN = 'pattern',
ANOMALY = 'anomaly',
THRESHOLD = 'threshold' THRESHOLD = 'threshold'
}; };

3
server/src/models/analytic_units/utils.ts

@ -1,6 +1,7 @@
import { DetectorType, ANALYTIC_UNIT_TYPES } from './types'; import { DetectorType, ANALYTIC_UNIT_TYPES } from './types';
import { AnalyticUnit } from './analytic_unit_model'; import { AnalyticUnit } from './analytic_unit_model';
import { PatternAnalyticUnit } from './pattern_analytic_unit_model'; import { PatternAnalyticUnit } from './pattern_analytic_unit_model';
import { AnomalyAnalyticUnit } from './anomaly_analytic_unit_model';
import { ThresholdAnalyticUnit } from './threshold_analytic_unit_model'; import { ThresholdAnalyticUnit } from './threshold_analytic_unit_model';
import * as _ from 'lodash'; import * as _ from 'lodash';
@ -15,6 +16,8 @@ export function createAnalyticUnitFromObject(obj: any): AnalyticUnit {
switch (detectorType) { switch (detectorType) {
case DetectorType.PATTERN: case DetectorType.PATTERN:
return PatternAnalyticUnit.fromObject(obj); return PatternAnalyticUnit.fromObject(obj);
case DetectorType.ANOMALY:
return AnomalyAnalyticUnit.fromObject(obj)
case DetectorType.THRESHOLD: case DetectorType.THRESHOLD:
return ThresholdAnalyticUnit.fromObject(obj); return ThresholdAnalyticUnit.fromObject(obj);

Loading…
Cancel
Save