From 5cfdae826cd826ca1e0b0eef26b43304e4721417 Mon Sep 17 00:00:00 2001 From: Hugo NOUTS <hnouts@grandlyon.com> Date: Thu, 22 Jun 2023 08:25:51 +0000 Subject: [PATCH] feat(dju): new data.grandlyon API version --- manifest.webapp | 2 +- src/components/Analysis/AnalysisConsumption.tsx | 2 +- src/doctypes/remote/org.ecolyo.dju.ts | 1 + src/models/dju.model.ts | 14 ++++++++++++++ src/services/profileType.service.ts | 16 +++++++++------- 5 files changed, 26 insertions(+), 9 deletions(-) create mode 100644 src/doctypes/remote/org.ecolyo.dju.ts create mode 100644 src/models/dju.model.ts diff --git a/manifest.webapp b/manifest.webapp index 52a6bc49b..12d4e0cf0 100644 --- a/manifest.webapp +++ b/manifest.webapp @@ -235,7 +235,7 @@ "verbs": ["GET"] }, "ecolyo-dju": { - "type": "org.ecolyo.dju", + "type": "org.ecolyo.dju_v2", "verbs": ["GET"] }, "dacc": { diff --git a/src/components/Analysis/AnalysisConsumption.tsx b/src/components/Analysis/AnalysisConsumption.tsx index ad5efafcd..80c8c93bf 100644 --- a/src/components/Analysis/AnalysisConsumption.tsx +++ b/src/components/Analysis/AnalysisConsumption.tsx @@ -110,7 +110,7 @@ const AnalysisConsumption = ({ const profileTypeService: ProfileTypeService = new ProfileTypeService( profileType, client, - analysisMonth.year + analysisMonth.minus({ month: 1 }).year ) const monthlyForecast: MonthlyForecast = await profileTypeService.getMonthlyForecast( diff --git a/src/doctypes/remote/org.ecolyo.dju.ts b/src/doctypes/remote/org.ecolyo.dju.ts new file mode 100644 index 000000000..ccc8e113b --- /dev/null +++ b/src/doctypes/remote/org.ecolyo.dju.ts @@ -0,0 +1 @@ +export const REMOTE_ORG_ECOLYO_DJU = '/remote/org.ecolyo.dju_v2' diff --git a/src/models/dju.model.ts b/src/models/dju.model.ts new file mode 100644 index 000000000..a74baa162 --- /dev/null +++ b/src/models/dju.model.ts @@ -0,0 +1,14 @@ +export interface DjuResult { + fields: string[] + layer_name: string + nb_result: number + table_href: string + values: DjuMeasure[] +} + +export interface DjuMeasure { + horodate: string + measurement: number + observation: string + unit: string +} diff --git a/src/services/profileType.service.ts b/src/services/profileType.service.ts index f911b87f8..2255192a8 100644 --- a/src/services/profileType.service.ts +++ b/src/services/profileType.service.ts @@ -6,6 +6,7 @@ import elecSpeData from 'constants/consumptionConstants/electricSpecific.json' import heatingData from 'constants/consumptionConstants/heating.json' import { Client } from 'cozy-client' import logger from 'cozy-logger' +import { REMOTE_ORG_ECOLYO_DJU } from 'doctypes/remote/org.ecolyo.dju' import { FluidType } from 'enum/fluid.enum' import { ConstructionYear, @@ -18,6 +19,7 @@ import { ThreeChoicesAnswer, } from 'enum/profileType.enum' import { DateTime } from 'luxon' +import { DjuResult } from 'models/dju.model' import { DetailsMonthlyForecast, FluidForecast, @@ -496,7 +498,6 @@ export default class ProfileTypeService { .set({ year: this.year }) .set({ month: month }) .startOf('month') - .minus({ minutes: 5 }) .toISO() const endDate: string = DateTime.local() .setZone('utc', { @@ -505,21 +506,22 @@ export default class ProfileTypeService { .set({ year: this.year }) .set({ month: month }) .endOf('month') - .plus({ minutes: 5 }) .toISO() - // We add or remove 5 minutes so the api returns the exact period try { - const result = await this._client + const result: DjuResult = await this._client .getStackClient() .fetchJSON( 'GET', - `/remote/org.ecolyo.dju?observedProperty=degreeDay&startDate=${startDate}&endDate=${endDate}` + `${REMOTE_ORG_ECOLYO_DJU}?startDate=${startDate}&endDate=${endDate}` ) let monthDju = 0 if (result) { - for (const observation of result.observations) { - monthDju += observation.result.value + const degreeDayObservations = result.values.filter( + value => value.observation === 'degreeDay' + ) + for (const observation of degreeDayObservations) { + monthDju += observation.measurement } } if (monthDju === 0) { -- GitLab