-
Hugo SUBTIL authoredHugo SUBTIL authored
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 :
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 :
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