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 { HasticServerInfo, HasticServerInfoUnknown } from '../models/hastic_server_info';
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 {
@ -224,7 +224,7 @@ export class AnalyticController {
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)) {
throw new Error('from isn`t number');
}
@ -232,18 +232,18 @@ export class AnalyticController {
throw new Error('to isn`t number');
}
const tasks = this.analyticUnits
.map(analyticUnit => this.fetchDetectionStatus(analyticUnit, from, to));
.map(analyticUnit => this.fetchDetectionSpans(analyticUnit, from, to));
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)) {
throw new Error('from isn`t number');
}
if(!_.isNumber(+to)) {
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[]> {
@ -372,28 +372,28 @@ export class AnalyticController {
if(!analyticUnit.inspect) {
return;
}
const detectionStatuses = analyticUnit.detectionStatuses;
if(detectionStatuses === undefined) {
const detectionSpans = analyticUnit.detectionSpans;
if(detectionSpans === undefined) {
return;
}
const minValue = _.min(_.map(plot.getYAxes(), axis => axis.min));
detectionStatuses.forEach(detectionStatus => {
detectionSpans.forEach(detectionSpan => {
let underlineColor;
switch(detectionStatus.state) {
case DetectionState.READY:
switch(detectionSpan.status) {
case DetectionStatus.READY:
underlineColor = 'green'
break;
case DetectionState.RUNNING:
case DetectionStatus.RUNNING:
underlineColor = 'yellow'
break;
case DetectionState.FAILED:
case DetectionStatus.FAILED:
underlineColor = 'red'
break;
default:
break;
}
options.grid.markings.push({
xaxis: { from: detectionStatus.from, to: detectionStatus.to },
xaxis: { from: detectionSpan.from, to: detectionSpan.to },
color: underlineColor,
yaxis: { from: minValue, to: minValue }
});

2
src/panel/graph_panel/graph_ctrl.ts

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

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

@ -1,7 +1,7 @@
import { SegmentsSet } from './segment_set';
import { SegmentArray } from './segment_array';
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';
@ -40,7 +40,7 @@ export class AnalyticUnit {
private _selected: boolean = false;
private _saving: boolean = false;
private _segmentSet = new SegmentArray<AnalyticSegment>();
private _detectionStatuses: DetectionStatus[];
private _detectionSpans: DetectionSpan[];
private _inspect = false;
private _status: string;
private _error: string;
@ -119,8 +119,8 @@ export class AnalyticUnit {
this._segmentSet.setSegments(value.getSegments());
}
get detectionStatuses(): DetectionStatus[] { return this._detectionStatuses; }
set detectionStatuses(value: DetectionStatus[]) { this._detectionStatuses = value; }
get detectionSpans(): DetectionSpan[] { return this._detectionSpans; }
set detectionSpans(value: DetectionSpan[]) { this._detectionSpans = value; }
get status() { return this._status; }
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';
export enum DetectionState {
export enum DetectionStatus {
READY = 'READY',
RUNNING = 'RUNNING',
FAILED = 'FAILED'
};
export type DetectionStatus = {
export type DetectionSpan = {
id: AnalyticUnitId,
state: DetectionState,
status: DetectionStatus,
from: 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 { HasticServerInfo, HasticServerInfoUnknown } from '../models/hastic_server_info';
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';
@ -136,16 +136,16 @@ export class AnalyticService {
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) {
throw new Error('id is undefined');
}
let payload: any = { id, from, to };
const data = await this.get('/detectionStatus', payload);
if(data.timeranges === undefined) {
throw new Error('Server didn`t return timeranges array');
const data = await this.get('/detections/spans', payload);
if(data === undefined || data.spans === undefined) {
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[]> {

Loading…
Cancel
Save