diff --git a/docs/ecolyo/services/enedis_halfhour_monthly_analysis.md b/docs/ecolyo/services/enedis_halfhour_monthly_analysis.md new file mode 100644 index 0000000000000000000000000000000000000000..056d7913ae56522740b159ea760f363355de5bdb --- /dev/null +++ b/docs/ecolyo/services/enedis_halfhour_monthly_analysis.md @@ -0,0 +1,75 @@ +# Definition of the service +The service will run everyday 3rd of month at 8.00 am, as defined in the manifest: + +``` + "enedisHalfHourMonthlyAnalysis": { + "type": "node", + "file": "services/enedisHalfHourMonthlyAnalysis/ecolyo.js", + "trigger": "@cron 0 0 8 3 * *" + } +``` +# Main responsabilities of the service + +The service is reponsible of calculating the average consumption load for half hour timestep on a given month. It is exclusively for Electricity fluid. The data result is stored in the doctype *com.grandlyon.enedis.monthly.analysis.data* + +Main steps are the following : + +- Check *com.grandlyon.enedis.minute* doctype. If the doctype contains entries, it means the half-hour consumption tracking has been activated, and there is data to use. + +- If there is half-hour data, creates the average consumption load for the last month (for the analysis) and store it in the doctype *com.grandlyon.enedis.monthly.analysis.data* + +- Checks **if there is other entries** in this doctype, if so, it means the service has already run before, so we create and store enedis monthly analysis for every month between the first entry in the enedis.minute doctype and the first entry in the enedis.monthly.analysis doctype. This way we will have an analysis available until the first month the half-hour consumption tracking has been activated + +- **If there is no other entries** in this doctype, it means it is the first the service runs, so we create and store enedis analysis from the last month analysis and until the minimum date between 1 year ago and the the date of first enedis.minute doctype entry. + +# Calculating the average half-hour consumption + +In order to calculate the average half-hour consumption on a given month, we use the function *getEnedisMonthAnalysisData* which takes the cozy client , a month and a year in parameters. + +This function is charged to do the following things : + +- Get the graph data for the chosen month on the given month period. + +- For each day, get the half-hour consumption + +- Filter days in 2 parts : weekdays and week end days + +- For each half-hour data push the data in a global 2dimensionnal array ; there is 2 global array, one for week-end days and the other for weekdays + +- At the point we have 2 global array with each 48 arrays filled with the corresponding values. To illustrate this, here is an example of how the data is sorted : + +``` +weekEndValuesArray : [ + 8h-8h30 : [day1Value, day2Value, day3value ..... lastWeekEndDayValue] + 8h30-9h : [day1Value, day2Value, day3value ..... lastWeekEndDayValue] + 9h-9h30 : [day1Value, day2Value, day3value ..... lastWeekEndDayValue] + ... + 23h30-00h : [day1Value, day2Value, day3value ..... lastWeekEndDayValue] +] +``` +- Once the array is filled with all available values, we just have to calculate the average for each half-hour step + +****Insert minimum cons value part once it's done**** + +- The result is stored in *com.grandlyon.enedis.monthly.analysis.data* according to the following model : + +``` +EnedisMonthlyAnalysisData { + weekDays: { + halfHourAverageValues: number[] + } + weekEndDays: { + halfHourAverageValues: number[] + } + minLoad: number + month: number + year: number +} +``` + +## Important rules + +- The empty half-hour values represented by a "-1" are not pushed in the valuesArray so we can keep an accurate average +- We have no choice but to get the half-hour values day per day because cozy limits the request result number to 1000 entries, and it is not enough to get a maximum of 48*31= 1488 entries per month, plus it doesn't allows us to properly calculate and average and handle the empty values. +- This service is quite long to run so we decided to run it 2 hours before the newsletter sending, this way user can acces his last enedis analysis once he received the newsletter. + diff --git a/mkdocs.yml b/mkdocs.yml index ef15bb6a4d60cd3eb49d5d34f8b8ce356c082654..ae0a53500763e0dbc1b7629916e9f1eef40bf67c 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -55,6 +55,7 @@ nav: - Monthly report notification: ecolyo/services/monthly_report_notification.md - Aggregator usage events: ecolyo/services/aggregator_usage_events.md - Consumption Alert: ecolyo/services/consumption_alert.md + - Enedis Halfhour Monthly Analysis: ecolyo/services/enedis_halfhour_monthly_analysis.md - Functionalities: - Initialization: ecolyo/functionalities/initialization.md - Consumption: ecolyo/functionalities/consumption.md