Browse Source

Fix after merging hastic/hastic-server#594 (#262)

master
rozetko 6 years ago committed by Alexey Velikiy
parent
commit
82a293a927
  1. 26
      src/panel/graph_panel/controllers/analytic_controller.ts
  2. 2
      src/panel/graph_panel/graph_ctrl.ts
  3. 8
      src/panel/graph_panel/models/analytic_unit.ts
  4. 6
      src/panel/graph_panel/models/detection_span.ts
  5. 12
      src/panel/graph_panel/services/analytic_service.ts

26
src/panel/graph_panel/controllers/analytic_controller.ts

@ -14,7 +14,7 @@ import { SegmentsSet } from '../models/segment_set';
import { SegmentArray } from '../models/segment_array'; import { SegmentArray } from '../models/segment_array';
import { HasticServerInfo, HasticServerInfoUnknown } from '../models/hastic_server_info'; import { HasticServerInfo, HasticServerInfoUnknown } from '../models/hastic_server_info';
import { Threshold, Condition } from '../models/threshold'; import { Threshold, Condition } from '../models/threshold';
import { DetectionState } from '../models/detection_status'; import { DetectionStatus } from '../models/detection_span';
import text from '../partials/help_section.html'; import text from '../partials/help_section.html';
import { import {
@ -224,7 +224,7 @@ export class AnalyticController {
this.analyticUnits.forEach(a => this._runStatusWaiter(a)); this.analyticUnits.forEach(a => this._runStatusWaiter(a));
} }
async fetchAnalyticUnitsDetectionStatuses(from: number, to: number): Promise<void[]> { async fetchAnalyticUnitsDetectionSpans(from: number, to: number): Promise<void[]> {
if(!_.isNumber(+from)) { if(!_.isNumber(+from)) {
throw new Error('from isn`t number'); throw new Error('from isn`t number');
} }
@ -232,18 +232,18 @@ export class AnalyticController {
throw new Error('to isn`t number'); throw new Error('to isn`t number');
} }
const tasks = this.analyticUnits const tasks = this.analyticUnits
.map(analyticUnit => this.fetchDetectionStatus(analyticUnit, from, to)); .map(analyticUnit => this.fetchDetectionSpans(analyticUnit, from, to));
return Promise.all(tasks); return Promise.all(tasks);
} }
async fetchDetectionStatus(analyticUnit: AnalyticUnit, from: number, to: number): Promise<void> { async fetchDetectionSpans(analyticUnit: AnalyticUnit, from: number, to: number): Promise<void> {
if(!_.isNumber(+from)) { if(!_.isNumber(+from)) {
throw new Error('from isn`t number'); throw new Error('from isn`t number');
} }
if(!_.isNumber(+to)) { if(!_.isNumber(+to)) {
throw new Error('to isn`t number'); throw new Error('to isn`t number');
} }
analyticUnit.detectionStatuses = await this._analyticService.getDetectionStatus(analyticUnit.id, from, to); analyticUnit.detectionSpans = await this._analyticService.getDetectionSpans(analyticUnit.id, from, to);
} }
async fetchAnalyticUnitsSegments(from: number, to: number): Promise<void[]> { async fetchAnalyticUnitsSegments(from: number, to: number): Promise<void[]> {
@ -372,28 +372,28 @@ export class AnalyticController {
if(!analyticUnit.inspect) { if(!analyticUnit.inspect) {
return; return;
} }
const detectionStatuses = analyticUnit.detectionStatuses; const detectionSpans = analyticUnit.detectionSpans;
if(detectionStatuses === undefined) { if(detectionSpans === undefined) {
return; return;
} }
const minValue = _.min(_.map(plot.getYAxes(), axis => axis.min)); const minValue = _.min(_.map(plot.getYAxes(), axis => axis.min));
detectionStatuses.forEach(detectionStatus => { detectionSpans.forEach(detectionSpan => {
let underlineColor; let underlineColor;
switch(detectionStatus.state) { switch(detectionSpan.status) {
case DetectionState.READY: case DetectionStatus.READY:
underlineColor = 'green' underlineColor = 'green'
break; break;
case DetectionState.RUNNING: case DetectionStatus.RUNNING:
underlineColor = 'yellow' underlineColor = 'yellow'
break; break;
case DetectionState.FAILED: case DetectionStatus.FAILED:
underlineColor = 'red' underlineColor = 'red'
break; break;
default: default:
break; break;
} }
options.grid.markings.push({ options.grid.markings.push({
xaxis: { from: detectionStatus.from, to: detectionStatus.to }, xaxis: { from: detectionSpan.from, to: detectionSpan.to },
color: underlineColor, color: underlineColor,
yaxis: { from: minValue, to: minValue } yaxis: { from: minValue, to: minValue }
}); });

2
src/panel/graph_panel/graph_ctrl.ts

@ -399,7 +399,7 @@ class GraphCtrl extends MetricsPanelCtrl {
// this.annotationsPromise, // this.annotationsPromise,
this.analyticsController.fetchAnalyticUnitsSegments(from, to), this.analyticsController.fetchAnalyticUnitsSegments(from, to),
// TODO: run detection status waiter if detection state !== 'READY' // TODO: run detection status waiter if detection state !== 'READY'
this.analyticsController.fetchAnalyticUnitsDetectionStatuses(from, to) this.analyticsController.fetchAnalyticUnitsDetectionSpans(from, to)
]; ];
await Promise.all(loadTasks); await Promise.all(loadTasks);

8
src/panel/graph_panel/models/analytic_unit.ts

@ -1,7 +1,7 @@
import { SegmentsSet } from './segment_set'; import { SegmentsSet } from './segment_set';
import { SegmentArray } from './segment_array'; import { SegmentArray } from './segment_array';
import { Segment, SegmentId } from './segment'; import { Segment, SegmentId } from './segment';
import { DetectionStatus } from './detection_status'; import { DetectionSpan } from './detection_span';
import { ANALYTIC_UNIT_COLORS, DEFAULT_DELETED_SEGMENT_COLOR } from '../colors'; import { ANALYTIC_UNIT_COLORS, DEFAULT_DELETED_SEGMENT_COLOR } from '../colors';
@ -40,7 +40,7 @@ export class AnalyticUnit {
private _selected: boolean = false; private _selected: boolean = false;
private _saving: boolean = false; private _saving: boolean = false;
private _segmentSet = new SegmentArray<AnalyticSegment>(); private _segmentSet = new SegmentArray<AnalyticSegment>();
private _detectionStatuses: DetectionStatus[]; private _detectionSpans: DetectionSpan[];
private _inspect = false; private _inspect = false;
private _status: string; private _status: string;
private _error: string; private _error: string;
@ -119,8 +119,8 @@ export class AnalyticUnit {
this._segmentSet.setSegments(value.getSegments()); this._segmentSet.setSegments(value.getSegments());
} }
get detectionStatuses(): DetectionStatus[] { return this._detectionStatuses; } get detectionSpans(): DetectionSpan[] { return this._detectionSpans; }
set detectionStatuses(value: DetectionStatus[]) { this._detectionStatuses = value; } set detectionSpans(value: DetectionSpan[]) { this._detectionSpans = value; }
get status() { return this._status; } get status() { return this._status; }
set status(value) { set status(value) {

6
src/panel/graph_panel/models/detection_status.ts → src/panel/graph_panel/models/detection_span.ts

@ -1,14 +1,14 @@
import { AnalyticUnitId } from './analytic_unit'; import { AnalyticUnitId } from './analytic_unit';
export enum DetectionState { export enum DetectionStatus {
READY = 'READY', READY = 'READY',
RUNNING = 'RUNNING', RUNNING = 'RUNNING',
FAILED = 'FAILED' FAILED = 'FAILED'
}; };
export type DetectionStatus = { export type DetectionSpan = {
id: AnalyticUnitId, id: AnalyticUnitId,
state: DetectionState, status: DetectionStatus,
from: number, from: number,
to: number to: number
}; };

12
src/panel/graph_panel/services/analytic_service.ts

@ -5,7 +5,7 @@ import { SegmentsSet } from '../models/segment_set';
import { AnalyticUnitId, AnalyticUnit, AnalyticSegment } from '../models/analytic_unit'; import { AnalyticUnitId, AnalyticUnit, AnalyticSegment } from '../models/analytic_unit';
import { HasticServerInfo, HasticServerInfoUnknown } from '../models/hastic_server_info'; import { HasticServerInfo, HasticServerInfoUnknown } from '../models/hastic_server_info';
import { Threshold } from '../models/threshold'; import { Threshold } from '../models/threshold';
import { DetectionStatus } from '../models/detection_status'; import { DetectionSpan } from '../models/detection_span';
import { isHasticServerResponse, isSupportedServerVersion, SUPPORTED_SERVER_VERSION } from '../../../utlis'; import { isHasticServerResponse, isSupportedServerVersion, SUPPORTED_SERVER_VERSION } from '../../../utlis';
@ -136,16 +136,16 @@ export class AnalyticService {
return data.addedIds as SegmentId[]; return data.addedIds as SegmentId[];
} }
async getDetectionStatus(id: AnalyticUnitId, from: number, to: number): Promise<DetectionStatus[]> { async getDetectionSpans(id: AnalyticUnitId, from: number, to: number): Promise<DetectionSpan[]> {
if(id === undefined) { if(id === undefined) {
throw new Error('id is undefined'); throw new Error('id is undefined');
} }
let payload: any = { id, from, to }; let payload: any = { id, from, to };
const data = await this.get('/detectionStatus', payload); const data = await this.get('/detections/spans', payload);
if(data.timeranges === undefined) { if(data === undefined || data.spans === undefined) {
throw new Error('Server didn`t return timeranges array'); throw new Error('Server didn`t return spans array');
} }
return data.timeranges; return data.spans;
} }
async getSegments(id: AnalyticUnitId, from?: number, to?: number): Promise<AnalyticSegment[]> { async getSegments(id: AnalyticUnitId, from?: number, to?: number): Promise<AnalyticSegment[]> {

Loading…
Cancel
Save