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

36
src/panel/graph_panel/graph_ctrl.ts

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

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

@ -113,7 +113,7 @@
<button <button
class="btn btn-inverse" class="btn btn-inverse"
ng-if="analyticUnit.detectorType === 'threshold'" 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'" ng-disabled="analyticUnit.status === 'PENDING' || analyticUnit.status === 'LEARNING'"
> >
Apply Apply

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

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

Loading…
Cancel
Save