commit a7285540e9b1a69c1fddb1a3153812d67b8e0abd
Author: hlavja <hlavjah@gmail.com>
Date:   Mon Apr 19 16:25:37 2021 +0200

    Re #8676 - Definovat analytics API
    
    + new API endpoints (analytics)
    * changing getting sensor observation data from analytics endpoint

diff --git a/proxy-config.json b/proxy-config.json
index 50ecf95..5216158 100644
--- a/proxy-config.json
+++ b/proxy-config.json
@@ -1,14 +1,18 @@
 {
   "/senslog1": {
-    "target": "http://51.15.45.95:8080",
+    "target": "https://51.15.45.95:8080",
     "secure": false
   },
   "/senslog-lite2/rest": {
-    "target": "http://51.15.45.95:8080",
+    "target": "https://51.15.45.95:8080",
     "secure": false
   },
   "/api/SensLogV1/OGCSensorThings": {
-    "target": "http://51.15.45.95:9080",
+    "target": "https://51.15.45.95:9080",
+    "secure": false
+  },
+  "/analytics": {
+    "target": "https://51.15.45.95:9090",
     "secure": false
   }
 }
diff --git a/src/app/auth/interceptors/auth.interceptor.ts b/src/app/auth/interceptors/auth.interceptor.ts
index 405538a..d6a36d0 100644
--- a/src/app/auth/interceptors/auth.interceptor.ts
+++ b/src/app/auth/interceptors/auth.interceptor.ts
@@ -28,7 +28,7 @@ export class AuthInterceptor implements HttpInterceptor {
       return of(null);
     }
 
-    if (!request.url.includes('ControllerServlet')){
+    if (request.url.includes('DataService')){
       request = request.clone({
         setParams: {
           user: localStorage.getItem(GlobalVariable.USER_NAME)
diff --git a/src/app/shared/api/endpoints/api.module.ts b/src/app/shared/api/endpoints/api.module.ts
index 71f7509..c21dd2b 100644
--- a/src/app/shared/api/endpoints/api.module.ts
+++ b/src/app/shared/api/endpoints/api.module.ts
@@ -8,6 +8,7 @@ import { LoginService } from './services/login.service';
 import { GroupService } from './services/group.service';
 import { ObservationService } from './services/observation.service';
 import { DataService } from './services/data.service';
+import { AnalyticsService } from './services/analytics.service';
 
 /**
  * Module that provides all services and configuration.
@@ -21,6 +22,7 @@ import { DataService } from './services/data.service';
     GroupService,
     ObservationService,
     DataService,
+    AnalyticsService,
     ApiConfiguration
   ],
 })
diff --git a/src/app/shared/api/endpoints/models.ts b/src/app/shared/api/endpoints/models.ts
index 0c1041d..581b861 100644
--- a/src/app/shared/api/endpoints/models.ts
+++ b/src/app/shared/api/endpoints/models.ts
@@ -10,3 +10,8 @@ export { Lastpos } from './models/lastpos';
 export { GeneralInfo } from './models/general-info';
 export { Drivers } from './models/drivers';
 export { Observation } from './models/observation';
+export { Sensors } from './models/sensors';
+export { SensorsData } from './models/sensors-data';
+export { Data } from './models/data';
+export { Obser } from './models/obser';
+export { Statistics } from './models/statistics';
diff --git a/src/app/shared/api/endpoints/models/data.ts b/src/app/shared/api/endpoints/models/data.ts
new file mode 100644
index 0000000..e6f1a17
--- /dev/null
+++ b/src/app/shared/api/endpoints/models/data.ts
@@ -0,0 +1,6 @@
+/* tslint:disable */
+/* eslint-disable */
+import { Obser } from './obser';
+export interface Data {
+  observation?: Obser;
+}
diff --git a/src/app/shared/api/endpoints/models/obser.ts b/src/app/shared/api/endpoints/models/obser.ts
new file mode 100644
index 0000000..b1ed022
--- /dev/null
+++ b/src/app/shared/api/endpoints/models/obser.ts
@@ -0,0 +1,9 @@
+/* tslint:disable */
+/* eslint-disable */
+export interface Obser {
+  avg?: number;
+  max?: number;
+  min?: number;
+  sum?: number;
+  timestamp?: string;
+}
diff --git a/src/app/shared/api/endpoints/models/sensors-data.ts b/src/app/shared/api/endpoints/models/sensors-data.ts
new file mode 100644
index 0000000..af31494
--- /dev/null
+++ b/src/app/shared/api/endpoints/models/sensors-data.ts
@@ -0,0 +1,9 @@
+/* tslint:disable */
+/* eslint-disable */
+import { Data } from './data';
+import { Statistics } from './statistics';
+export interface SensorsData {
+  data?: Data;
+  interval?: number;
+  statistics?: Statistics;
+}
diff --git a/src/app/shared/api/endpoints/models/sensors.ts b/src/app/shared/api/endpoints/models/sensors.ts
new file mode 100644
index 0000000..3f8d379
--- /dev/null
+++ b/src/app/shared/api/endpoints/models/sensors.ts
@@ -0,0 +1,6 @@
+/* tslint:disable */
+/* eslint-disable */
+import { SensorsData } from './sensors-data';
+export interface Sensors {
+  sensorsData?: SensorsData;
+}
diff --git a/src/app/shared/api/endpoints/models/statistics.ts b/src/app/shared/api/endpoints/models/statistics.ts
new file mode 100644
index 0000000..59dba4a
--- /dev/null
+++ b/src/app/shared/api/endpoints/models/statistics.ts
@@ -0,0 +1,8 @@
+/* tslint:disable */
+/* eslint-disable */
+export interface Statistics {
+  avg?: number;
+  max?: number;
+  min?: number;
+  sum?: number;
+}
diff --git a/src/app/shared/api/endpoints/services.ts b/src/app/shared/api/endpoints/services.ts
index 7c12c75..d475b8e 100644
--- a/src/app/shared/api/endpoints/services.ts
+++ b/src/app/shared/api/endpoints/services.ts
@@ -2,3 +2,4 @@ export { LoginService } from './services/login.service';
 export { GroupService } from './services/group.service';
 export { ObservationService } from './services/observation.service';
 export { DataService } from './services/data.service';
+export { AnalyticsService } from './services/analytics.service';
diff --git a/src/app/shared/api/endpoints/services/analytics.service.ts b/src/app/shared/api/endpoints/services/analytics.service.ts
new file mode 100644
index 0000000..a78d7a3
--- /dev/null
+++ b/src/app/shared/api/endpoints/services/analytics.service.ts
@@ -0,0 +1,95 @@
+/* tslint:disable */
+/* eslint-disable */
+import { Injectable } from '@angular/core';
+import { HttpClient, HttpResponse } from '@angular/common/http';
+import { BaseService } from '../base-service';
+import { ApiConfiguration } from '../api-configuration';
+import { StrictHttpResponse } from '../strict-http-response';
+import { RequestBuilder } from '../request-builder';
+import { Observable } from 'rxjs';
+import { map, filter } from 'rxjs/operators';
+
+import { Sensors } from '../models/sensors';
+
+
+/**
+ * Analitics endpoints
+ */
+@Injectable({
+  providedIn: 'root',
+})
+export class AnalyticsService extends BaseService {
+  constructor(
+    config: ApiConfiguration,
+    http: HttpClient
+  ) {
+    super(config, http);
+  }
+
+  /**
+   * Path part for operation getAnalytics
+   */
+  static readonly GetAnalyticsPath = '/analytics/analytics';
+
+  /**
+   * Get analytics.
+   *
+   *
+   *
+   * This method provides access to the full `HttpResponse`, allowing access to response headers.
+   * To access only the response body, use `getAnalytics()` instead.
+   *
+   * This method doesn't expect any request body.
+   */
+  getAnalytics$Response(params: {
+    unit_id: number;
+    sensor_id?: number;
+    from?: string;
+    to?: string;
+    interval?: string;
+  }): Observable<StrictHttpResponse<Array<any>>> {
+
+    const rb = new RequestBuilder(this.rootUrl, AnalyticsService.GetAnalyticsPath, 'get');
+    if (params) {
+      rb.query('unit_id', params.unit_id, {});
+      rb.query('sensor_id', params.sensor_id, {});
+      rb.query('from', params.from, {});
+      rb.query('to', params.to, {});
+      rb.query('interval', params.interval, {});
+    }
+
+    return this.http.request(rb.build({
+      responseType: 'json',
+      accept: 'application/json'
+    })).pipe(
+      filter((r: any) => r instanceof HttpResponse),
+      map((r: HttpResponse<any>) => {
+        return r as StrictHttpResponse<Array<any>>;
+      })
+    );
+  }
+
+  /**
+   * Get analytics.
+   *
+   *
+   *
+   * This method provides access to only to the response body.
+   * To access the full response (for headers, for example), `getAnalytics$Response()` instead.
+   *
+   * This method doesn't expect any request body.
+   */
+  getAnalytics(params: {
+    unit_id: number;
+    sensor_id?: number;
+    from?: string;
+    to?: string;
+    interval?: string;
+  }): Observable<Array<any>> {
+
+    return this.getAnalytics$Response(params).pipe(
+      map((r: StrictHttpResponse<Array<any>>) => r.body as Array<any>)
+    );
+  }
+
+}
diff --git a/src/app/shared/api/endpoints/services/observation.service.ts b/src/app/shared/api/endpoints/services/observation.service.ts
index 61de522..2f2133f 100644
--- a/src/app/shared/api/endpoints/services/observation.service.ts
+++ b/src/app/shared/api/endpoints/services/observation.service.ts
@@ -11,6 +11,10 @@ import { map, filter } from 'rxjs/operators';
 
 import { Observation } from '../models/observation';
 
+
+/**
+ * Observations endpoints
+ */
 @Injectable({
   providedIn: 'root',
 })
diff --git a/src/app/shared/api/openapi.yaml b/src/app/shared/api/openapi.yaml
index 71030f7..0283aea 100644
--- a/src/app/shared/api/openapi.yaml
+++ b/src/app/shared/api/openapi.yaml
@@ -19,6 +19,8 @@ tags:
   description: Data endpoints
 - name: observation
   description: Observations endpoints
+- name: analytics
+  description: Analitics endpoints
 
 paths:
   /senslog1/ControllerServlet:
@@ -145,6 +147,46 @@ paths:
                         unit:
                           $ref: '#/components/schemas/Unit'
 
+  /analytics/analytics:
+    get:
+      tags:
+        - analytics
+      summary: Get analytics
+      operationId: getAnalytics
+      parameters:
+        - in: query
+          name: unit_id
+          required: true
+          schema:
+            type: integer
+        - in: query
+          name: sensor_id
+          required: false
+          schema:
+            type: integer
+        - in: query
+          name: from
+          schema:
+            type: string
+        - in: query
+          name: to
+          schema:
+            type: string
+        - in: query
+          name: interval
+          schema:
+            type: string
+      responses:
+        200:
+          description: Get observation for unit
+          content:
+            application/json:
+              schema:
+                type: array
+                properties:
+                  sensor:
+                    $ref: '#/components/schemas/Sensors'
+
 components:
   schemas:
     UserInfo:
@@ -272,4 +314,58 @@ components:
         value:
           type: number
 
+    Sensors:
+      type: object
+      properties:
+        sensorsData:
+          $ref: '#/components/schemas/SensorsData'
+
+    SensorsData:
+      type: object
+      properties:
+        interval:
+          type: number
+        data:
+          $ref: '#/components/schemas/Data'
+        statistics:
+          $ref: '#/components/schemas/Statistics'
+
+    Data:
+      type: object
+      properties:
+        observation:
+          $ref: '#/components/schemas/Obser'
+
+    Obser:
+      type: object
+      properties:
+        min:
+          type: number
+        max:
+          type: number
+        avg:
+          type: number
+        sum:
+          type: number
+        timestamp:
+          type: string
+          format: date-time
+
+    Statistics:
+      type: object
+      properties:
+        min:
+          type: number
+        max:
+          type: number
+        avg:
+          type: number
+        sum:
+          type: number
+
+
+
+
+
+
 
diff --git a/src/app/shared/models/aggreation.model.ts b/src/app/shared/models/aggreation.model.ts
new file mode 100644
index 0000000..e873395
--- /dev/null
+++ b/src/app/shared/models/aggreation.model.ts
@@ -0,0 +1,6 @@
+/* tslint:disable */
+/* eslint-disable */
+export interface AggreationModel {
+  name?: string,
+  code?: string
+}
diff --git a/src/vega/data.json b/src/vega/data.json
index 3398d2c..7c93149 100644
--- a/src/vega/data.json
+++ b/src/vega/data.json
@@ -7,7 +7,7 @@
   "signals": [
     {
       "name": "length",
-      "value":  ["year","month"],
+      "value":  ["year","month", "date"],
       "bind": {
         "input": "select",
         "options": [
@@ -48,7 +48,7 @@
       "transform": [
         {
           "type": "formula",
-          "expr": "toDate(datum[\"time\"])",
+          "expr": "toDate(datum[\"timestamp\"])",
           "as": "dateTime"
         },
         {
@@ -58,7 +58,7 @@
         },
         {
           "type": "aggregate",
-          "fields": ["value"],
+          "fields": ["max"],
           "ops": [{"signal" :  "operation"}],
           "groupby": ["unit0"],
           "as": ["avg"]
