|
@@ -1,8 +1,8 @@
|
|
|
import { Component, OnDestroy, OnInit } from '@angular/core';
|
|
import { Component, OnDestroy, OnInit } from '@angular/core';
|
|
|
import { ActivatedRoute } from '@angular/router';
|
|
import { ActivatedRoute } from '@angular/router';
|
|
|
import * as moment from 'moment-timezone';
|
|
import * as moment from 'moment-timezone';
|
|
|
-import { AnalyticsService } from '../../shared/api/endpoints/services/analytics.service';
|
|
|
|
|
-import { AggregationModel } from '../../shared/models/aggregationModel';
|
|
|
|
|
|
|
+// import { AnalyticsService } from '../../shared/api/endpoints/services/analytics.service';
|
|
|
|
|
+// import { AggregationModel } from '../../shared/models/aggregationModel';
|
|
|
import { GraphLoader } from '../../shared/graph-loading/graphloader';
|
|
import { GraphLoader } from '../../shared/graph-loading/graphloader';
|
|
|
import { ObservationService } from '../../shared/api/endpoints/services/observation.service';
|
|
import { ObservationService } from '../../shared/api/endpoints/services/observation.service';
|
|
|
import { HttpResponse } from '@angular/common/http';
|
|
import { HttpResponse } from '@angular/common/http';
|
|
@@ -25,9 +25,9 @@ export class SensorComponent implements OnInit, OnDestroy {
|
|
|
time = [];
|
|
time = [];
|
|
|
from: Date = moment().hour(0).minutes(0).subtract(7, 'days').toDate();
|
|
from: Date = moment().hour(0).minutes(0).subtract(7, 'days').toDate();
|
|
|
to: Date = moment().toDate();
|
|
to: Date = moment().toDate();
|
|
|
- showAggregation = false;
|
|
|
|
|
- aggregationFunction: AggregationModel[];
|
|
|
|
|
- selectedAggregationFunction = 'HOUR';
|
|
|
|
|
|
|
+ //showAggregation = false;
|
|
|
|
|
+ //aggregationFunction: AggregationModel[];
|
|
|
|
|
+ //selectedAggregationFunction = 'HOUR';
|
|
|
sensor: Sensor;
|
|
sensor: Sensor;
|
|
|
dateChanged = false;
|
|
dateChanged = false;
|
|
|
unitDescription: string;
|
|
unitDescription: string;
|
|
@@ -36,7 +36,7 @@ export class SensorComponent implements OnInit, OnDestroy {
|
|
|
|
|
|
|
|
constructor(
|
|
constructor(
|
|
|
private activatedRoute: ActivatedRoute,
|
|
private activatedRoute: ActivatedRoute,
|
|
|
- private analyticsService: AnalyticsService,
|
|
|
|
|
|
|
+ //private analyticsService: AnalyticsService,
|
|
|
private observationService: ObservationService,
|
|
private observationService: ObservationService,
|
|
|
private toastService: ToastService,
|
|
private toastService: ToastService,
|
|
|
private sensorsService: SensorsService,
|
|
private sensorsService: SensorsService,
|
|
@@ -62,12 +62,12 @@ export class SensorComponent implements OnInit, OnDestroy {
|
|
|
});
|
|
});
|
|
|
this.sensorId = parseInt(this.activatedRoute.snapshot.paramMap.get('sensorId'), 10);
|
|
this.sensorId = parseInt(this.activatedRoute.snapshot.paramMap.get('sensorId'), 10);
|
|
|
this.unitId = parseInt(this.activatedRoute.snapshot.paramMap.get('unitId'), 10);
|
|
this.unitId = parseInt(this.activatedRoute.snapshot.paramMap.get('unitId'), 10);
|
|
|
- this.aggregationFunction = [
|
|
|
|
|
- { name: 'Hour', code: 'HOUR' },
|
|
|
|
|
- { name: 'Day', code: 'DAY' },
|
|
|
|
|
- { name: 'Month', code: 'MONTH' },
|
|
|
|
|
- { name: 'Year', code: 'YEAR' }
|
|
|
|
|
- ];
|
|
|
|
|
|
|
+ // this.aggregationFunction = [
|
|
|
|
|
+ // { name: 'Hour', code: 'HOUR' },
|
|
|
|
|
+ // { name: 'Day', code: 'DAY' },
|
|
|
|
|
+ // { name: 'Month', code: 'MONTH' },
|
|
|
|
|
+ // { name: 'Year', code: 'YEAR' }
|
|
|
|
|
+ // ];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -81,61 +81,49 @@ export class SensorComponent implements OnInit, OnDestroy {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * Shows aggregation select box and get data button
|
|
|
|
|
|
|
+ * Shows get data button
|
|
|
*/
|
|
*/
|
|
|
- // aggregationShow() {
|
|
|
|
|
- // this.dateChanged = true;
|
|
|
|
|
- // this.showAggregation = moment(this.to).diff(moment(this.from), 'days') > 7;
|
|
|
|
|
- // }
|
|
|
|
|
-
|
|
|
|
|
- onDateChanged(): void{
|
|
|
|
|
|
|
+ onDateChanged(): void {
|
|
|
this.dateChanged = true;
|
|
this.dateChanged = true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Gets data based on selected time range
|
|
* Gets data based on selected time range
|
|
|
*/
|
|
*/
|
|
|
- showGraph() {
|
|
|
|
|
- // if (moment(this.to).diff(moment(this.from), 'days') > 7) {
|
|
|
|
|
- // this.showAggregation = true;
|
|
|
|
|
- // const range: Date[] = [this.from, this.to];
|
|
|
|
|
- // this.getAnalytics(range);
|
|
|
|
|
- // } else {
|
|
|
|
|
- //this.showAggregation = false;
|
|
|
|
|
|
|
+ showGraph() {
|
|
|
const range: Date[] = [this.from, this.to];
|
|
const range: Date[] = [this.from, this.to];
|
|
|
this.getObservations(range);
|
|
this.getObservations(range);
|
|
|
- //}
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Get data from analytics endpoint
|
|
* Get data from analytics endpoint
|
|
|
* @param range from and to interval
|
|
* @param range from and to interval
|
|
|
*/
|
|
*/
|
|
|
- getAnalytics(range: Date[]) {
|
|
|
|
|
- this.analyticsService.getAnalytics$Response({
|
|
|
|
|
- unit_id: this.unitId, sensor_id: this.sensorId,
|
|
|
|
|
- from: moment(range[0]).format('yyyy-MM-DD HH:mm:ssZ').slice(0, -3),
|
|
|
|
|
- to: moment(range[1]).format('yyyy-MM-DD HH:mm:ssZ').slice(0, -3), interval: this.selectedAggregationFunction
|
|
|
|
|
- }).pipe(
|
|
|
|
|
- map((response: HttpResponse<any>) => {
|
|
|
|
|
- if (response.status === 200) {
|
|
|
|
|
- return response.body;
|
|
|
|
|
- } else if (response.status === 204) {
|
|
|
|
|
- this.toastService.showWarningNoData();
|
|
|
|
|
- return response.body;
|
|
|
|
|
- } else {
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- ).subscribe(
|
|
|
|
|
- observations => {
|
|
|
|
|
- if (observations) {
|
|
|
|
|
- GraphLoader.getGraphWithInterval(this.sensorId, observations[this.sensorId].data, observations[this.sensorId].interval * 1000, this.sensor, '#view', true);
|
|
|
|
|
- } else {
|
|
|
|
|
- GraphLoader.getGraph(null, null, null, '#view', null);
|
|
|
|
|
- }
|
|
|
|
|
- }, err => this.toastService.showError(err.error.message));
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // getAnalytics(range: Date[]) {
|
|
|
|
|
+ // this.analyticsService.getAnalytics$Response({
|
|
|
|
|
+ // unit_id: this.unitId, sensor_id: this.sensorId,
|
|
|
|
|
+ // from: moment(range[0]).format('yyyy-MM-DD HH:mm:ssZ').slice(0, -3),
|
|
|
|
|
+ // to: moment(range[1]).format('yyyy-MM-DD HH:mm:ssZ').slice(0, -3), interval: this.selectedAggregationFunction
|
|
|
|
|
+ // }).pipe(
|
|
|
|
|
+ // map((response: HttpResponse<any>) => {
|
|
|
|
|
+ // if (response.status === 200) {
|
|
|
|
|
+ // return response.body;
|
|
|
|
|
+ // } else if (response.status === 204) {
|
|
|
|
|
+ // this.toastService.showWarningNoData();
|
|
|
|
|
+ // return response.body;
|
|
|
|
|
+ // } else {
|
|
|
|
|
+ // return false;
|
|
|
|
|
+ // }
|
|
|
|
|
+ // })
|
|
|
|
|
+ // ).subscribe(
|
|
|
|
|
+ // observations => {
|
|
|
|
|
+ // if (observations) {
|
|
|
|
|
+ // GraphLoader.getGraphWithInterval(this.sensorId, observations[this.sensorId].data, observations[this.sensorId].interval * 1000, this.sensor, '#view', true);
|
|
|
|
|
+ // } else {
|
|
|
|
|
+ // GraphLoader.getGraph(null, null, null, '#view', null);
|
|
|
|
|
+ // }
|
|
|
|
|
+ // }, err => this.toastService.showError(err.error.message));
|
|
|
|
|
+ // }
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Get data from observation endpoint
|
|
* Get data from observation endpoint
|