observation.service.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /* tslint:disable */
  2. /* eslint-disable */
  3. import { formatDate } from '@angular/common';
  4. import { Injectable } from '@angular/core';
  5. import { HttpClient, HttpResponse } from '@angular/common/http';
  6. import { BaseService } from '../base-service';
  7. import { ApiConfiguration } from '../api-configuration';
  8. import { StrictHttpResponse } from '../strict-http-response';
  9. import { RequestBuilder } from '../request-builder';
  10. import { Observable } from 'rxjs';
  11. import { map, filter } from 'rxjs/operators';
  12. import { OldObservation } from '../models/old-observation';
  13. /**
  14. * Observations endpoints
  15. */
  16. @Injectable({
  17. providedIn: 'root',
  18. })
  19. export class ObservationService extends BaseService {
  20. constructor(
  21. config: ApiConfiguration,
  22. http: HttpClient
  23. ) {
  24. super(config, http);
  25. }
  26. /**
  27. * Path part for operation getObservation
  28. */
  29. static readonly GetObservationPath = '/senslog15/SensorService?Operation=GetObservations';
  30. static readonly RestObservationsPath = '/senslog15/rest/observation/';
  31. /**
  32. * Get observation.
  33. *
  34. *
  35. *
  36. * This method provides access to the full `HttpResponse`, allowing access to response headers.
  37. * To access only the response body, use `getObservation()` instead.
  38. *
  39. * This method doesn't expect any request body.
  40. */
  41. getObservation$Response(params: {
  42. unit_id: number;
  43. sensor_id: number;
  44. from?: string;
  45. to?: string;
  46. }): Observable<StrictHttpResponse<Array<OldObservation>>> {
  47. const rb = new RequestBuilder(this.rootUrl, ObservationService.GetObservationPath, 'get');
  48. if (params) {
  49. rb.query('unit_id', params.unit_id, {});
  50. rb.query('sensor_id', params.sensor_id, {});
  51. rb.query('from', params.from, {});
  52. rb.query('to', params.to, {});
  53. }
  54. return this.http.request(rb.build({
  55. responseType: 'json',
  56. accept: 'application/json'
  57. })).pipe(
  58. filter((r: any) => r instanceof HttpResponse),
  59. map((r: HttpResponse<any>) => {
  60. return r as StrictHttpResponse<Array<OldObservation>>;
  61. })
  62. );
  63. }
  64. /**
  65. * Get observation.
  66. *
  67. *
  68. *
  69. * This method provides access to only to the response body.
  70. * To access the full response (for headers, for example), `getObservation$Response()` instead.
  71. *
  72. * This method doesn't expect any request body.
  73. */
  74. getObservation(params: {
  75. unit_id: number;
  76. sensor_id: number;
  77. from?: string;
  78. to?: string;
  79. }): Observable<Array<OldObservation>> {
  80. return this.getObservation$Response(params).pipe(
  81. map((r: StrictHttpResponse<Array<OldObservation>>) => r.body as Array<OldObservation>)
  82. );
  83. }
  84. exportObservations(params: {
  85. //group_id: number,
  86. sensor_id: number,
  87. from?: Date;
  88. to?: Date;
  89. }): Observable<StrictHttpResponse<string>> {
  90. const rb = new RequestBuilder(this.rootUrl, ObservationService.RestObservationsPath + 'export', 'get');
  91. if (params) {
  92. rb.query('sensor_id', params.sensor_id);
  93. rb.query('from_time', formatDate(params.from, 'yyyy-MM-dd', 'en-US'));
  94. rb.query('to_time', formatDate(params.to, 'yyyy-MM-dd', 'en-US'));
  95. rb.query('style', 'crosstab');
  96. rb.query('nullable', false);
  97. }
  98. return this.http.request(rb.build({
  99. responseType: 'text',
  100. accept: 'text/plain'
  101. })).pipe(
  102. filter((r: any) => r instanceof HttpResponse),
  103. map((r: HttpResponse<any>) => {
  104. return r as StrictHttpResponse<string>;
  105. })
  106. );
  107. }
  108. }