Skip to content
Snippets Groups Projects
Commit 46f436db authored by Hugo SUBTIL's avatar Hugo SUBTIL
Browse files

feat(doc): add price calculation doc

parent 20a9956e
No related branches found
No related tags found
No related merge requests found
# Price Calculation
This section explains the price calculation process.
## Description
Since version `1.6.0` of the app, we have a database storing fluid prices evolution sincre 2012 for the following fluids :
* Elecricity
* Gas
Before this version, the app was applying a hard coded price for each fluid without taking care of the time period. Now, there is a service running every night that process fresh data in order to apply the current price to this data, but also apply the most relevant price for a fluid doctype.
## Service
### Process
The Cozy service responsible for price calculation is `fluidsPrices`. You can find the full logic in the following diagram :
```plantuml
@startuml
scale 0.8
start
repeat :Select Price (Elec, gas);
:Apply Prices on selected price;
if (There is prices in database) then (true)
:Get oldest data without price;
if (There is a doctype without price) then (Process price)
:Take founded date as time reference;
if (FluidType is elec) then (true)
repeat
:Get half-hour data by day (48 elements);
:Get price for the period;
:Apply price on each element;
:Save all elements;
:Increment date by one day;
repeat while (Date is not today)
else (false)
endif
repeat
:Get daily data by month (max 31 elements);
:Get price for the period;
:Apply price on each element;
:Save all elements;
:Increment date by one month;
repeat while (Date is not in current month)
:Start aggregation for month and year;
repeat
:Get daily data by month (max 31 elements);
:Get monthly data without price (1 element);
:Sum prices for all daily elements;
:Add price on monthly data doc;
:Save monthly element;
:Increment date by one month;
repeat while (Date is not in current month)
repeat
:Get monthly data by year (max 12 elements);
:Get yearly data without price (1 element);
:Sum prices for all monthly elements;
:Add price on yearly data doc;
:Save yearly element;
:Increment date by one year;
repeat while (Date is not in current year)
else (Stop service)
:Log error and stop process;
end
endif
else (Stop service)
:Log error and stop process;
end
endif
repeat while (All fluid are not processed)
stop
@enduml
```
This service is running every night at 02:00 AM.
!!! warning "note"
You might observe some price miscalculation if data from konnector is collect after the service runtime. Because of the hard code price, which is the current price, the user should not see any difference.
### Init
A migration job has been setup to init the database with json data store inside the app. This job should be run once and will init electricy and gas prices.
### New price
In case of price update the following procedure must be done :
* Create a migration for adding new prices
* Update hard coded price inside app in order to maintain fallback calculation
* Verify full service calculation with new data
* Verify calculation with existing data
!!! warning "note"
The service does not handle change during a month because the case does not exist anymore for Enedis and Grdf.
### Prices Data
We store in databse a collection of prices with the following info :
* StartDate
* EndDate
* fluidType
* Price
The EndDate is set to null if it's the current fluid price.
## App Price display
The app can handle the new price calculation and also keep the old calculation system.
### Regular display
If there is a price on the doctype we want to process, it will be use for display and calculation ( see analysis functionality).
### Fallback
The app take the hard code price for a given fluid and apply it to a load. This allow the app to handle prices in any case.
### How to test service ?
In a shell run a build and test service with le following command line :
```bash
yarn build-dev:browser; yarn run cozy-konnector-dev -m .\manifest.webapp .\build\services\monthlyReport\ecolyo.js
```
### Evolutions
We might consider a more dynamic process for fallback price calculation in the future:
* Get last price for a given price in database
* Use it to calculate value instead of the hard coded one
* Use it in all info pop-in for user information
......@@ -57,29 +57,30 @@ nav:
- Consumption Alert: ecolyo/services/consumption_alert.md
- Enedis Halfhour Monthly Analysis: ecolyo/services/enedis_halfhour_monthly_analysis.md
- Functionalities:
- Initialization: ecolyo/functionalities/initialization.md
- Analysis: ecolyo/functionalities/analysis.md
- Challenge: ecolyo/functionalities/challenge.md
- Consumption: ecolyo/functionalities/consumption.md
- Ecogesture: ecolyo/functionalities/ecogesture.md
- Challenge: ecolyo/functionalities/challenge.md
- Profile Type: ecolyo/functionalities/profile_type.md
- Analysis: ecolyo/functionalities/analysis.md
- Usage events tracking: ecolyo/functionalities/usage_events_tracking.md
- Feedback: ecolyo/functionalities/feedback.md
- Initialization: ecolyo/functionalities/initialization.md
- Price Calculation: ecolyo/functionalities/prices_calculation.md
- Profile Type: ecolyo/functionalities/profile_type.md
- Terms: ecolyo/functionalities/terms.md
- Ecolyo-Agent:
- Usage events tracking: ecolyo/functionalities/usage_events_tracking.md
- Ecolyo-Agent:
- Introduction: ecolyo/ecolyo-agent/introduction.md
- Getting started:
- Setup your environment: ecolyo/ecolyo-agent/getting_started/setup_your_environment.md
- Launch the application on local: ecolyo/ecolyo-agent/getting_started/launch_local_application.md
- Libraries: ecolyo/ecolyo-agent/getting_started/libraries.md
- Setup your environment: ecolyo/ecolyo-agent/getting_started/setup_your_environment.md
- Launch the application on local: ecolyo/ecolyo-agent/getting_started/launch_local_application.md
- Libraries: ecolyo/ecolyo-agent/getting_started/libraries.md
- Functionalities:
- General: ecolyo/ecolyo-agent/functionalities/general.md
- Authentification: ecolyo/ecolyo-agent/functionalities/authentification.md
- Routes: ecolyo/ecolyo-agent/functionalities/routes.md
- General: ecolyo/ecolyo-agent/functionalities/general.md
- Authentification: ecolyo/ecolyo-agent/functionalities/authentification.md
- Routes: ecolyo/ecolyo-agent/functionalities/routes.md
- Development:
- Deploy: ecolyo/ecolyo-agent/development/deploy.md
- Handle assets: ecolyo/ecolyo-agent/development/handle_assets.md
- Backup: ecolyo/ecolyo-agent/development/backup.md
- Deploy: ecolyo/ecolyo-agent/development/deploy.md
- Handle assets: ecolyo/ecolyo-agent/development/handle_assets.md
- Backup: ecolyo/ecolyo-agent/development/backup.md
- Pilote:
- Pilote - TS - Back:
- Index: pilote/Pilote - TS - Back/index.md
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment