Browse Source

Thresholds error: from is NaN hastic/hastic-server#621 (#277)

master
rozetko 6 years ago committed by GitHub
parent
commit
004a6edfd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      src/panel/graph_panel/controllers/analytic_controller.ts
  2. 36
      src/panel/graph_panel/graph_ctrl.ts
  3. 2
      src/panel/graph_panel/partials/tab_analytics.html
  4. 4
      src/panel/graph_panel/services/analytic_service.ts

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

@ -220,8 +220,8 @@ export class AnalyticController {
this.analyticUnits.forEach(a => this._runStatusWaiter(a));
}
fetchAnalyticUnitsDetections(from: number | null, to: number | null) {
if(from === null || to === null) {
fetchAnalyticUnitsDetections(from?: number, to?: number) {
if(from === undefined || to === undefined) {
return;
}
this.analyticUnits.forEach(analyticUnit => {
@ -309,7 +309,9 @@ export class AnalyticController {
async redetectAll() {
this.analyticUnits.forEach(unit => {
// TODO: remove duplication with runDetect
unit.segments.clear();
unit.detectionSpans = [];
unit.status = null;
});
const ids = this.analyticUnits.map(analyticUnit => analyticUnit.id);
@ -318,12 +320,13 @@ export class AnalyticController {
_.each(this.analyticUnits, analyticUnit => this._runStatusWaiter(analyticUnit));
}
async runDetect(analyticUnitId: AnalyticUnitId) {
async runDetect(analyticUnitId: AnalyticUnitId, from?: number, to?: number) {
const analyticUnit = this._analyticUnitsSet.byId(analyticUnitId);
analyticUnit.segments.clear();
analyticUnit.detectionSpans = [];
analyticUnit.status = null;
await this.saveAnalyticUnit(analyticUnit);
await this._analyticService.runDetect(analyticUnitId);
await this._analyticService.runDetect(analyticUnitId, from, to);
this._runStatusWaiter(analyticUnit);
}

36
src/panel/graph_panel/graph_ctrl.ts

@ -59,8 +59,8 @@ class GraphCtrl extends MetricsPanelCtrl {
private _panelId: string;
private _dataTimerange: {
from: number,
to: number
from?: number,
to?: number
};
panelDefaults = {
@ -273,10 +273,8 @@ class GraphCtrl extends MetricsPanelCtrl {
await this.analyticsController.removeAnalyticUnit(analyticUnit.id, true);
}
if(analyticUnit.status === 'READY') {
if(this.range === undefined) {
this.updateTimeRange();
}
await this.analyticsController.fetchSegments(analyticUnit, +this.range.from, +this.range.to);
const { from, to } = this.rangeTimestamp;
await this.analyticsController.fetchSegments(analyticUnit, from, to);
}
this.render(this.seriesList);
this.$scope.$digest();
@ -372,8 +370,7 @@ class GraphCtrl extends MetricsPanelCtrl {
this.dataList = dataList;
this.loading = true;
const from = +this.range.from;
const to = +this.range.to;
const { from, to } = this.rangeTimestamp;
if(this.analyticsController !== undefined) {
const hsrSeries = await this.analyticsController.getHSRSeries(from, to);
@ -432,10 +429,9 @@ class GraphCtrl extends MetricsPanelCtrl {
const from = _.find(series.datapoints, datapoint => datapoint[0] !== null);
const to = _.findLast(series.datapoints, datapoint => datapoint[0] !== null);
this._dataTimerange = {};
if(from !== undefined && to !== undefined) {
this._dataTimerange = { from: from[1], to: to[1] };
} else {
this._dataTimerange = { from: null, to: null }
}
if (series.unit) {
@ -580,8 +576,13 @@ class GraphCtrl extends MetricsPanelCtrl {
this.analyticsController.redetectAll();
}
async runDetect(analyticUnitId: AnalyticUnitId) {
this.analyticsController.runDetect(analyticUnitId);
async runDetectInCurrentRange(analyticUnitId: AnalyticUnitId) {
const { from, to } = this.rangeTimestamp;
this.analyticsController.runDetect(
analyticUnitId,
from, to
);
}
async saveNew() {
@ -734,6 +735,17 @@ class GraphCtrl extends MetricsPanelCtrl {
this.$scope.$digest();
}
get rangeTimestamp(): { from: number, to: number } {
if(this.range === undefined) {
this.updateTimeRange();
}
return {
from: +this.range.from,
to: +this.range.to
};
}
get hasticDatasources() {
return this._hasticDatasources;
}

2
src/panel/graph_panel/partials/tab_analytics.html

@ -113,7 +113,7 @@
<button
class="btn btn-inverse"
ng-if="analyticUnit.detectorType === 'threshold'"
ng-click="ctrl.runDetect(analyticUnit.id)"
ng-click="ctrl.runDetectInCurrentRange(analyticUnit.id)"
ng-disabled="analyticUnit.status === 'PENDING' || analyticUnit.status === 'LEARNING'"
>
Apply

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

@ -219,11 +219,11 @@ export class AnalyticService {
return this.patch('/analyticUnits', updateObj);
}
async runDetect(ids: AnalyticUnitId | AnalyticUnitId[]) {
async runDetect(ids: AnalyticUnitId | AnalyticUnitId[], from?: number, to?: number) {
if(!_.isArray(ids)) {
ids = [ids];
}
return this.post('/analyticUnits/detect', { ids });
return this.post('/analyticUnits/detect', { ids, from, to });
}
private async _analyticRequest(method: string, url: string, data?: any) {

Loading…
Cancel
Save