Skip to content
Snippets Groups Projects

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 since 2012 for the following fluids :

  • Electricity
  • 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 updating the database with the most relevant price for a fluid doctype. The connectors are responsible for the calculation of the price.

Service

Process

The Cozy service responsible for updating prices is fluidsPrices. You can find the full logic in the following diagram :

This service is running every morning before 7:00 AM.

New price

In case of price update or new price, simply add a new price in the backoffice and the service will take care of the rest.

Prices Data

We store in database 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. These prices are updated manually whenever a new version of Ecolyo is published.

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\fluidsPrices\ecolyo.js

Future Changes

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