Browse Source

sensor: hide aggreg & only observation data

kunickyd 3 năm trước cách đây
mục cha
commit
468a4c1ee3

+ 1 - 1
src/app/sensor/components/sensor.component.html

@@ -43,7 +43,7 @@
         </div>
         <p-calendar id="to" [(ngModel)]="to" [showTime]="true" (onSelect)="onDateChanged()" [maxDate]="today" showButtonBar="true"></p-calendar>
       </div>
-      <p-listbox *ngIf="showAggregation" [options]="aggregationFunction" [(ngModel)]="selectedAggregationFunction" optionLabel="name" optionValue="code"></p-listbox>
+      <!-- <p-listbox *ngIf="showAggregation" [options]="aggregationFunction" [(ngModel)]="selectedAggregationFunction" optionLabel="name" optionValue="code"></p-listbox> -->
       <div>
         <button pButton label="Load data" *ngIf="dateChanged" class="p-button-primary" icon="pi pi-chart-line" (click)="showGraph()"></button>
       </div>

+ 40 - 52
src/app/sensor/components/sensor.component.ts

@@ -1,8 +1,8 @@
 import { Component, OnDestroy, OnInit } from '@angular/core';
 import { ActivatedRoute } from '@angular/router';
 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 { ObservationService } from '../../shared/api/endpoints/services/observation.service';
 import { HttpResponse } from '@angular/common/http';
@@ -25,9 +25,9 @@ export class SensorComponent implements OnInit, OnDestroy {
   time = [];
   from: Date = moment().hour(0).minutes(0).subtract(7, 'days').toDate();
   to: Date = moment().toDate();
-  showAggregation = false;
-  aggregationFunction: AggregationModel[];
-  selectedAggregationFunction = 'HOUR';
+  //showAggregation = false;
+  //aggregationFunction: AggregationModel[];
+  //selectedAggregationFunction = 'HOUR';
   sensor: Sensor;
   dateChanged = false;
   unitDescription: string;
@@ -36,7 +36,7 @@ export class SensorComponent implements OnInit, OnDestroy {
 
   constructor(
     private activatedRoute: ActivatedRoute,
-    private analyticsService: AnalyticsService,
+    //private analyticsService: AnalyticsService,
     private observationService: ObservationService,
     private toastService: ToastService,
     private sensorsService: SensorsService,
@@ -62,12 +62,12 @@ export class SensorComponent implements OnInit, OnDestroy {
     });
     this.sensorId = parseInt(this.activatedRoute.snapshot.paramMap.get('sensorId'), 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;
   }
 
   /**
    * 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];
     this.getObservations(range);
-    //}
   }
 
   /**
    * Get data from analytics endpoint
    * @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