diff --git a/manifest.webapp b/manifest.webapp index 52a6bc49b62dc410bbbe13049dae55ca282b66c4..12d4e0cf017acee4422a15569d7081c71c40451d 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 ad5efafcdb595980f14c6cdaee777e0afe901481..80c8c93bf400a58bf11af6527525aba834d9dda7 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 0000000000000000000000000000000000000000..ccc8e113b55304436422772de428c90ed6165094 --- /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 0000000000000000000000000000000000000000..a74baa1625edf2d6fb82661d45a1e63c330469bc --- /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 f911b87f894a6ae38c19496dff57d6ab13bd4ef1..2255192a8c05659608928105a284886e8dd118a7 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) {