Browse Source

AnalyticUnitKey -> AnalyticUnitId

master
Alexey Velikiy 6 years ago
parent
commit
6b7c414497
  1. 15
      src/controllers/analytic_controller.ts
  2. 12
      src/models/analytic_unit.ts
  3. 8
      src/module.ts
  4. 12
      src/services/analytic_service.ts

15
src/controllers/analytic_controller.ts

@ -1,7 +1,9 @@
// Corresponds to https://github.com/hastic/hastic-server/blob/master/server/src/models/analytic_unit.ts
import { AnalyticService } from '../services/analytic_service'
import {
AnalyticUnitKey, AnalyticUnit,
AnalyticUnitId, AnalyticUnit,
AnalyticUnitsSet, AnalyticSegment, AnalyticSegmentsSearcher, AnalyticSegmentPair
} from '../models/analytic_unit';
import { MetricExpanded } from '../models/metric';
@ -9,6 +11,7 @@ import { DatasourceRequest } from '../models/datasource';
import { Segment, SegmentKey } from '../models/segment';
import { SegmentsSet } from '../models/segment_set';
import { SegmentArray } from '../models/segment_array';
import { Emitter } from 'grafana/app/core/utils/emitter'
import _ from 'lodash';
@ -23,7 +26,7 @@ export const REGION_DELETE_COLOR_DARK = 'white';
export class AnalyticController {
private _analyticUnitsSet: AnalyticUnitsSet;
private _selectedAnalyticUnitKey: AnalyticUnitKey = null;
private _selectedAnalyticUnitKey: AnalyticUnitId = null;
private _labelingDataAddedSegments: SegmentsSet<AnalyticSegment>;
private _labelingDataDeletedSegments: SegmentsSet<AnalyticSegment>;
@ -33,7 +36,7 @@ export class AnalyticController {
private _tempIdCounted = -1;
private _graphLocked = false;
private _statusRunners: Set<AnalyticUnitKey> = new Set<AnalyticUnitKey>();
private _statusRunners: Set<AnalyticUnitId> = new Set<AnalyticUnitId>();
constructor(private _panelObject: any, private _analyticService: AnalyticService, private _emitter: Emitter) {
@ -91,7 +94,7 @@ export class AnalyticController {
return this._analyticUnitsSet.byKey(this._selectedAnalyticUnitKey);
}
async toggleAnomalyTypeLabelingMode(key: AnalyticUnitKey) {
async toggleAnomalyTypeLabelingMode(key: AnalyticUnitId) {
if(this.labelingAnomaly && this.labelingAnomaly.saving) {
throw new Error('Can`t toggel during saving');
}
@ -158,7 +161,7 @@ export class AnalyticController {
return this._analyticUnitsSet.items;
}
onAnomalyColorChange(key: AnalyticUnitKey, value) {
onAnomalyColorChange(key: AnalyticUnitId, value) {
this._analyticUnitsSet.byKey(key).color = value;
}
@ -332,7 +335,7 @@ export class AnalyticController {
return this._tempIdCounted;
}
public toggleVisibility(key: AnalyticUnitKey, value?: boolean) {
public toggleVisibility(key: AnalyticUnitId, value?: boolean) {
var anomaly = this._analyticUnitsSet.byKey(key);
if(value !== undefined) {
anomaly.visible = value;

12
src/models/analytic_unit.ts

@ -8,7 +8,7 @@ import _ from 'lodash';
export type AnalyticSegmentPair = { anomalyType: AnalyticUnit, segment: AnalyticSegment };
export type AnalyticSegmentsSearcher = (point: number, rangeDist: number) => AnalyticSegmentPair[];
export type AnalyticUnitKey = string;
export type AnalyticUnitId = string;
export class AnalyticSegment extends Segment {
constructor(public labeled: boolean, key: SegmentKey, from: number, to: number) {
@ -42,7 +42,7 @@ export class AnalyticUnit {
//this._metric = new Metric(_panelObject.metric);
}
get key(): AnalyticUnitKey { return this.name; }
get key(): AnalyticUnitId { return this.name; }
set name(value: string) { this._panelObject.name = value; }
get name(): string { return this._panelObject.name; }
@ -118,14 +118,14 @@ export class AnalyticUnit {
export class AnalyticUnitsSet {
private _mapKeyIndex: Map<AnalyticUnitKey, number>;
private _mapKeyIndex: Map<AnalyticUnitId, number>;
private _items: AnalyticUnit[];
constructor(private _panelObject: any[]) {
if(_panelObject === undefined) {
throw new Error('panel object can`t be undefined');
}
this._mapKeyIndex = new Map<AnalyticUnitKey, number>();
this._mapKeyIndex = new Map<AnalyticUnitId, number>();
this._items = _panelObject.map(p => new AnalyticUnit(p));
this._rebuildIndex();
}
@ -138,7 +138,7 @@ export class AnalyticUnitsSet {
this._items.push(anomalyType);
}
removeAnomalyType(key: AnalyticUnitKey) {
removeAnomalyType(key: AnalyticUnitId) {
var index = this._mapKeyIndex[key];
this._panelObject.splice(index, 1);
this._items.splice(index, 1);
@ -151,7 +151,7 @@ export class AnalyticUnitsSet {
});
}
byKey(key: AnalyticUnitKey): AnalyticUnit {
byKey(key: AnalyticUnitId): AnalyticUnit {
return this._items[this._mapKeyIndex[key]];
}

8
src/module.ts

@ -8,7 +8,7 @@ import { GraphLegend } from './graph_legend';
import { DataProcessor } from './data_processor';
import { MetricExpanded } from './models/metric';
import { DatasourceRequest } from './models/datasource';
import { AnalyticUnitKey, AnalyticUnit } from './models/analytic_unit';
import { AnalyticUnitId, AnalyticUnit } from './models/analytic_unit';
import { AnalyticService } from './services/analytic_service';
import { AnalyticController } from './controllers/analytic_controller';
@ -525,7 +525,7 @@ class GraphCtrl extends MetricsPanelCtrl {
this.render(this.seriesList);
}
onColorChange(key: AnalyticUnitKey, value) {
onColorChange(key: AnalyticUnitId, value) {
this.analyticsController.onAnomalyColorChange(key, value);
this.render();
}
@ -553,7 +553,7 @@ class GraphCtrl extends MetricsPanelCtrl {
}
async onToggleLabelingMode(key) {
await this.analyticsController.toggleAnomalyTypeLabelingMode(key as AnalyticUnitKey);
await this.analyticsController.toggleAnomalyTypeLabelingMode(key as AnalyticUnitId);
this.$scope.$digest();
this.render();
}
@ -569,7 +569,7 @@ class GraphCtrl extends MetricsPanelCtrl {
this.analyticsController.toggleAnomalyTypeAlertEnabled(anomalyType);
}
onToggleVisibility(key: AnalyticUnitKey) {
onToggleVisibility(key: AnalyticUnitId) {
this.analyticsController.toggleVisibility(key);
this.render();
}

12
src/services/analytic_service.ts

@ -2,7 +2,7 @@ import { Segment, SegmentKey } from '../models/segment';
import { MetricExpanded } from '../models/metric';
import { DatasourceRequest } from '../models/datasource';
import { SegmentsSet } from '../models/segment_set';
import { AnalyticUnitKey, AnalyticUnit, AnalyticSegment } from '../models/analytic_unit';
import { AnalyticUnitId, AnalyticUnit, AnalyticSegment } from '../models/analytic_unit';
import { BackendSrv } from 'grafana/app/core/services/backend_srv';
@ -35,7 +35,7 @@ export class AnalyticService {
}
async updateSegments(
key: AnalyticUnitKey, addedSegments: SegmentsSet<Segment>, removedSegments: SegmentsSet<Segment>
key: AnalyticUnitId, addedSegments: SegmentsSet<Segment>, removedSegments: SegmentsSet<Segment>
): Promise<SegmentKey[]> {
const getJSONs = (segs: SegmentsSet<Segment>) => segs.getSegments().map(segment => ({
@ -57,7 +57,7 @@ export class AnalyticService {
return data.added_ids as SegmentKey[];
}
async getSegments(key: AnalyticUnitKey, from?: number, to?: number): Promise<AnalyticSegment[]> {
async getSegments(key: AnalyticUnitId, from?: number, to?: number): Promise<AnalyticSegment[]> {
var payload: any = { predictor_id: key };
if(from !== undefined) {
payload['from'] = from;
@ -76,7 +76,7 @@ export class AnalyticService {
return segments.map(s => new AnalyticSegment(s.labeled, s.id, s.start, s.finish));
}
async * getAnomalyTypeStatusGenerator(key: AnalyticUnitKey, duration: number) {
async * getAnomalyTypeStatusGenerator(key: AnalyticUnitId, duration: number) {
let statusCheck = async () => {
var data = await this._backendSrv.get(
this._backendURL + '/anomalies/status', { name: key }
@ -95,7 +95,7 @@ export class AnalyticService {
}
async getAlertEnabled(key: AnalyticUnitKey): Promise<boolean> {
async getAlertEnabled(key: AnalyticUnitId): Promise<boolean> {
var data = await this._backendSrv.get(
this._backendURL + '/alerts', { predictor_id: key }
);
@ -103,7 +103,7 @@ export class AnalyticService {
}
async setAlertEnabled(key: AnalyticUnitKey, value: boolean): Promise<void> {
async setAlertEnabled(key: AnalyticUnitId, value: boolean): Promise<void> {
return this._backendSrv.post(
this._backendURL + '/alerts', { predictor_id: key, enable: value }
);

Loading…
Cancel
Save