Projekt

Obecné

Profil

« Předchozí | Další » 

Revize a7285540

Přidáno uživatelem Jakub Hlaváč před téměř 4 roky(ů)

Re #8676 - Definovat analytics API

+ new API endpoints (analytics)
  • changing getting sensor observation data from analytics endpoint

Zobrazit rozdíly:

proxy-config.json
1 1
{
2 2
  "/senslog1": {
3
    "target": "http://51.15.45.95:8080",
3
    "target": "https://51.15.45.95:8080",
4 4
    "secure": false
5 5
  },
6 6
  "/senslog-lite2/rest": {
7
    "target": "http://51.15.45.95:8080",
7
    "target": "https://51.15.45.95:8080",
8 8
    "secure": false
9 9
  },
10 10
  "/api/SensLogV1/OGCSensorThings": {
11
    "target": "http://51.15.45.95:9080",
11
    "target": "https://51.15.45.95:9080",
12
    "secure": false
13
  },
14
  "/analytics": {
15
    "target": "https://51.15.45.95:9090",
12 16
    "secure": false
13 17
  }
14 18
}
src/app/auth/interceptors/auth.interceptor.ts
28 28
      return of(null);
29 29
    }
30 30

  
31
    if (!request.url.includes('ControllerServlet')){
31
    if (request.url.includes('DataService')){
32 32
      request = request.clone({
33 33
        setParams: {
34 34
          user: localStorage.getItem(GlobalVariable.USER_NAME)
src/app/shared/api/endpoints/api.module.ts
8 8
import { GroupService } from './services/group.service';
9 9
import { ObservationService } from './services/observation.service';
10 10
import { DataService } from './services/data.service';
11
import { AnalyticsService } from './services/analytics.service';
11 12

  
12 13
/**
13 14
 * Module that provides all services and configuration.
......
21 22
    GroupService,
22 23
    ObservationService,
23 24
    DataService,
25
    AnalyticsService,
24 26
    ApiConfiguration
25 27
  ],
26 28
})
src/app/shared/api/endpoints/models.ts
10 10
export { GeneralInfo } from './models/general-info';
11 11
export { Drivers } from './models/drivers';
12 12
export { Observation } from './models/observation';
13
export { Sensors } from './models/sensors';
14
export { SensorsData } from './models/sensors-data';
15
export { Data } from './models/data';
16
export { Obser } from './models/obser';
17
export { Statistics } from './models/statistics';
src/app/shared/api/endpoints/models/data.ts
1
/* tslint:disable */
2
/* eslint-disable */
3
import { Obser } from './obser';
4
export interface Data {
5
  observation?: Obser;
6
}
src/app/shared/api/endpoints/models/obser.ts
1
/* tslint:disable */
2
/* eslint-disable */
3
export interface Obser {
4
  avg?: number;
5
  max?: number;
6
  min?: number;
7
  sum?: number;
8
  timestamp?: string;
9
}
src/app/shared/api/endpoints/models/sensors-data.ts
1
/* tslint:disable */
2
/* eslint-disable */
3
import { Data } from './data';
4
import { Statistics } from './statistics';
5
export interface SensorsData {
6
  data?: Data;
7
  interval?: number;
8
  statistics?: Statistics;
9
}
src/app/shared/api/endpoints/models/sensors.ts
1
/* tslint:disable */
2
/* eslint-disable */
3
import { SensorsData } from './sensors-data';
4
export interface Sensors {
5
  sensorsData?: SensorsData;
6
}
src/app/shared/api/endpoints/models/statistics.ts
1
/* tslint:disable */
2
/* eslint-disable */
3
export interface Statistics {
4
  avg?: number;
5
  max?: number;
6
  min?: number;
7
  sum?: number;
8
}
src/app/shared/api/endpoints/services.ts
2 2
export { GroupService } from './services/group.service';
3 3
export { ObservationService } from './services/observation.service';
4 4
export { DataService } from './services/data.service';
5
export { AnalyticsService } from './services/analytics.service';
src/app/shared/api/endpoints/services/analytics.service.ts
1
/* tslint:disable */
2
/* eslint-disable */
3
import { Injectable } from '@angular/core';
4
import { HttpClient, HttpResponse } from '@angular/common/http';
5
import { BaseService } from '../base-service';
6
import { ApiConfiguration } from '../api-configuration';
7
import { StrictHttpResponse } from '../strict-http-response';
8
import { RequestBuilder } from '../request-builder';
9
import { Observable } from 'rxjs';
10
import { map, filter } from 'rxjs/operators';
11

  
12
import { Sensors } from '../models/sensors';
13

  
14

  
15
/**
16
 * Analitics endpoints
17
 */
18
@Injectable({
19
  providedIn: 'root',
20
})
21
export class AnalyticsService extends BaseService {
22
  constructor(
23
    config: ApiConfiguration,
24
    http: HttpClient
25
  ) {
26
    super(config, http);
27
  }
28

  
29
  /**
30
   * Path part for operation getAnalytics
31
   */
32
  static readonly GetAnalyticsPath = '/analytics/analytics';
33

  
34
  /**
35
   * Get analytics.
36
   *
37
   *
38
   *
39
   * This method provides access to the full `HttpResponse`, allowing access to response headers.
40
   * To access only the response body, use `getAnalytics()` instead.
41
   *
42
   * This method doesn't expect any request body.
43
   */
44
  getAnalytics$Response(params: {
45
    unit_id: number;
46
    sensor_id?: number;
47
    from?: string;
48
    to?: string;
49
    interval?: string;
50
  }): Observable<StrictHttpResponse<Array<any>>> {
51

  
52
    const rb = new RequestBuilder(this.rootUrl, AnalyticsService.GetAnalyticsPath, 'get');
53
    if (params) {
54
      rb.query('unit_id', params.unit_id, {});
55
      rb.query('sensor_id', params.sensor_id, {});
56
      rb.query('from', params.from, {});
57
      rb.query('to', params.to, {});
58
      rb.query('interval', params.interval, {});
59
    }
60

  
61
    return this.http.request(rb.build({
62
      responseType: 'json',
63
      accept: 'application/json'
64
    })).pipe(
65
      filter((r: any) => r instanceof HttpResponse),
66
      map((r: HttpResponse<any>) => {
67
        return r as StrictHttpResponse<Array<any>>;
68
      })
69
    );
70
  }
71

  
72
  /**
73
   * Get analytics.
74
   *
75
   *
76
   *
77
   * This method provides access to only to the response body.
78
   * To access the full response (for headers, for example), `getAnalytics$Response()` instead.
79
   *
80
   * This method doesn't expect any request body.
81
   */
82
  getAnalytics(params: {
83
    unit_id: number;
84
    sensor_id?: number;
85
    from?: string;
86
    to?: string;
87
    interval?: string;
88
  }): Observable<Array<any>> {
89

  
90
    return this.getAnalytics$Response(params).pipe(
91
      map((r: StrictHttpResponse<Array<any>>) => r.body as Array<any>)
92
    );
93
  }
94

  
95
}
src/app/shared/api/endpoints/services/observation.service.ts
11 11

  
12 12
import { Observation } from '../models/observation';
13 13

  
14

  
15
/**
16
 * Observations endpoints
17
 */
14 18
@Injectable({
15 19
  providedIn: 'root',
16 20
})
src/app/shared/api/openapi.yaml
19 19
  description: Data endpoints
20 20
- name: observation
21 21
  description: Observations endpoints
22
- name: analytics
23
  description: Analitics endpoints
22 24

  
23 25
paths:
24 26
  /senslog1/ControllerServlet:
......
145 147
                        unit:
146 148
                          $ref: '#/components/schemas/Unit'
147 149

  
150
  /analytics/analytics:
151
    get:
152
      tags:
153
        - analytics
154
      summary: Get analytics
155
      operationId: getAnalytics
156
      parameters:
157
        - in: query
158
          name: unit_id
159
          required: true
160
          schema:
161
            type: integer
162
        - in: query
163
          name: sensor_id
164
          required: false
165
          schema:
166
            type: integer
167
        - in: query
168
          name: from
169
          schema:
170
            type: string
171
        - in: query
172
          name: to
173
          schema:
174
            type: string
175
        - in: query
176
          name: interval
177
          schema:
178
            type: string
179
      responses:
180
        200:
181
          description: Get observation for unit
182
          content:
183
            application/json:
184
              schema:
185
                type: array
186
                properties:
187
                  sensor:
188
                    $ref: '#/components/schemas/Sensors'
189

  
148 190
components:
149 191
  schemas:
150 192
    UserInfo:
......
272 314
        value:
273 315
          type: number
274 316

  
317
    Sensors:
318
      type: object
319
      properties:
320
        sensorsData:
321
          $ref: '#/components/schemas/SensorsData'
322

  
323
    SensorsData:
324
      type: object
325
      properties:
326
        interval:
327
          type: number
328
        data:
329
          $ref: '#/components/schemas/Data'
330
        statistics:
331
          $ref: '#/components/schemas/Statistics'
332

  
333
    Data:
334
      type: object
335
      properties:
336
        observation:
337
          $ref: '#/components/schemas/Obser'
338

  
339
    Obser:
340
      type: object
341
      properties:
342
        min:
343
          type: number
344
        max:
345
          type: number
346
        avg:
347
          type: number
348
        sum:
349
          type: number
350
        timestamp:
351
          type: string
352
          format: date-time
353

  
354
    Statistics:
355
      type: object
356
      properties:
357
        min:
358
          type: number
359
        max:
360
          type: number
361
        avg:
362
          type: number
363
        sum:
364
          type: number
365

  
366

  
367

  
368

  
369

  
370

  
275 371

  
src/app/shared/models/aggreation.model.ts
1
/* tslint:disable */
2
/* eslint-disable */
3
export interface AggreationModel {
4
  name?: string,
5
  code?: string
6
}
src/vega/data.json
7 7
  "signals": [
8 8
    {
9 9
      "name": "length",
10
      "value":  ["year","month"],
10
      "value":  ["year","month", "date"],
11 11
      "bind": {
12 12
        "input": "select",
13 13
        "options": [
......
48 48
      "transform": [
49 49
        {
50 50
          "type": "formula",
51
          "expr": "toDate(datum[\"time\"])",
51
          "expr": "toDate(datum[\"timestamp\"])",
52 52
          "as": "dateTime"
53 53
        },
54 54
        {
......
58 58
        },
59 59
        {
60 60
          "type": "aggregate",
61
          "fields": ["value"],
61
          "fields": ["max"],
62 62
          "ops": [{"signal" :  "operation"}],
63 63
          "groupby": ["unit0"],
64 64
          "as": ["avg"]

Také k dispozici: Unified diff