Commit 6fbddffd authored by Hugo SUBTIL's avatar Hugo SUBTIL
Browse files

feat(conso): add price history. A new service running at night is processing...

feat(conso): add price history. A new service running at night is processing fluid data to index the right price on it.
parent 690cab09
......@@ -17,7 +17,6 @@
},
"editor.tabSize": 2,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnPaste": true,
"editor.formatOnSave": true,
"eslint.validate": [
"javascript",
......
......@@ -149,6 +149,11 @@
"type": "node",
"file": "services/aggregatorUsageEvents/ecolyo.js",
"trigger": "@cron 0 1 * * *"
},
"fluidsPrices": {
"type": "node",
"file": "services/fluidsPrices/ecolyo.js",
"trigger": "@cron 0 2 * * *"
}
},
"permissions": {
......
@echo off
echo Please provide cozysessid (can be found after connection in browser dev tool)
set /p token="CozySessid ? : "
ACH -t %token% import ./data/dayData.json
ACH -t %token% -u http://cozy.tools:8080 import ./data/dayData.json
......@@ -51,7 +51,11 @@ const DataloadComparisonLeft: React.FC<DataloadComparisonLeftProps> = ({
].toLowerCase()}-compare text-16-normal`}
>
{`${formatNumberValues(
converterService.LoadToEuro(compareDataload.value, fluidType)
converterService.LoadToEuro(
compareDataload.value,
fluidType,
compareDataload.price ? compareDataload.price : null
)
)} €`}
</div>
)}
......
......@@ -123,7 +123,11 @@ const DataloadConsumptionVisualizer = ({
].toLowerCase()} text-16-normal`}
>
{`${formatNumberValues(
converterService.LoadToEuro(dataload.value, fluidType)
converterService.LoadToEuro(
dataload.value,
fluidType,
dataload.price ? dataload.price : null
)
)} €`}
</div>
) : (
......@@ -212,7 +216,8 @@ const DataloadConsumptionVisualizer = ({
<div>{`${formatNumberValues(
converterService.LoadToEuro(
dataload.value,
fluidType
fluidType,
dataload.price ? dataload.price : null
)
)} €`}</div>
</div>
......
......@@ -37,9 +37,19 @@ const TotalConsumption: React.FC<TotalConsumptionProps> = ({
const converterService = new ConverterService()
let total = 0
let totalPrice = 0
actualData.forEach(data => {
if (data.value !== -1) total += data.value
if (data.value !== -1) {
total += data.value
}
if (data.price) {
totalPrice += converterService.LoadToEuro(
data.value,
fluidType,
data.price
)
}
})
const displayedValue =
......@@ -50,9 +60,11 @@ const TotalConsumption: React.FC<TotalConsumptionProps> = ({
? '-----'
: fluidType === FluidType.MULTIFLUID
? formatNumberValues(total).toString()
: formatNumberValues(
: totalPrice <= 0
? formatNumberValues(
converterService.LoadToEuro(total, fluidType)
).toString()
: formatNumberValues(totalPrice).toString()
setTotalValue(displayedValue)
}
......
[
{
"fluidType": 0,
"price": 0.1256,
"startDate": "2012-07-23T00:00:00.000Z",
"endDate": "2013-07-31T23:59:59.000Z"
},
{
"fluidType": 0,
"price": 0.1329,
"startDate": "2013-08-01T00:00:00.000Z",
"endDate": "2014-10-31T23:59:59.000Z"
},
{
"fluidType": 0,
"price": 0.1401,
"startDate": "2014-01-11T00:00:00.000Z",
"endDate": "2015-07-31T23:59:59.000Z"
},
{
"fluidType": 0,
"price": 0.1437,
"startDate": "2015-08-01T00:00:00.000Z",
"endDate": "2016-07-31T23:59:59.000Z"
},
{
"fluidType": 0,
"price": 0.1503,
"startDate": "2016-08-01T00:00:00.000Z",
"endDate": "2017-07-31T23:59:59.000Z"
},
{
"fluidType": 0,
"price": 0.1546,
"startDate": "2017-08-01T00:00:00.000Z",
"endDate": "2018-01-31T23:59:59.000Z"
},
{
"fluidType": 0,
"price": 0.1555,
"startDate": "2018-02-01T00:00:00.000Z",
"endDate": "2018-07-31T23:59:59.000Z"
},
{
"fluidType": 0,
"price": 0.145,
"startDate": "2018-08-01T00:00:00.000Z",
"endDate": "2019-05-31T23:59:59.000Z"
},
{
"fluidType": 0,
"price": 0.1531,
"startDate": "2019-06-01T00:00:00.000Z",
"endDate": "2019-07-31T23:59:59.000Z"
},
{
"fluidType": 0,
"price": 0.1524,
"startDate": "2019-08-01T00:00:00.000Z",
"endDate": "2020-01-31T23:59:59.000Z"
},
{
"fluidType": 0,
"price": 0.1546,
"startDate": "2020-02-01T00:00:00.000Z",
"endDate": "2020-07-31T23:59:59.000Z"
},
{
"fluidType": 0,
"price": 0.1557,
"startDate": "2020-08-01T00:00:00.000Z",
"endDate": "2021-01-31T23:59:59.000Z"
},
{
"fluidType": 0,
"price": 0.1582,
"startDate": "2021-02-01T00:00:00.000Z",
"endDate": "2021-07-31T23:59:59.000Z"
},
{
"fluidType": 0,
"price": 0.1558,
"startDate": "2021-08-01T00:00:00.000Z",
"endDate": null
},
{
"fluidType": 2,
"price": 0.0919,
"startDate": "2017-01-01T00:00:00.000Z",
"endDate": "2017-01-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0915,
"startDate": "2017-02-01T00:00:00.000Z",
"endDate": "2017-02-28T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0932,
"startDate": "2017-03-01T00:00:00.000Z",
"endDate": "2017-03-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0927,
"startDate": "2017-04-01T00:00:00.000Z",
"endDate": "2017-04-30T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0906,
"startDate": "2017-05-01T00:00:00.000Z",
"endDate": "2017-05-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0906,
"startDate": "2017-06-01T00:00:00.000Z",
"endDate": "2017-06-30T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0788,
"startDate": "2017-07-01T00:00:00.000Z",
"endDate": "2017-07-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0783,
"startDate": "2017-08-01T00:00:00.000Z",
"endDate": "2017-08-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0783,
"startDate": "2017-09-01T00:00:00.000Z",
"endDate": "2017-09-30T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0791,
"startDate": "2017-10-01T00:00:00.000Z",
"endDate": "2017-10-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0806,
"startDate": "2017-11-01T00:00:00.000Z",
"endDate": "2017-11-30T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0812,
"startDate": "2017-12-01T00:00:00.000Z",
"endDate": "2017-12-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0857,
"startDate": "2018-01-01T00:00:00.000Z",
"endDate": "2018-01-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0866,
"startDate": "2018-02-01T00:00:00.000Z",
"endDate": "2018-02-28T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0847,
"startDate": "2018-03-01T00:00:00.000Z",
"endDate": "2018-03-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0839,
"startDate": "2018-04-01T00:00:00.000Z",
"endDate": "2018-04-30T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0842,
"startDate": "2018-05-01T00:00:00.000Z",
"endDate": "2018-05-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0855,
"startDate": "2018-06-01T00:00:00.000Z",
"endDate": "2018-06-30T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0959,
"startDate": "2018-07-01T00:00:00.000Z",
"endDate": "2018-07-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0961,
"startDate": "2018-08-01T00:00:00.000Z",
"endDate": "2018-08-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0967,
"startDate": "2018-09-01T00:00:00.000Z",
"endDate": "2018-09-30T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0989,
"startDate": "2018-10-01T00:00:00.000Z",
"endDate": "2018-10-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.1031,
"startDate": "2018-11-01T00:00:00.000Z",
"endDate": "2018-11-30T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.1013,
"startDate": "2018-12-01T00:00:00.000Z",
"endDate": "2018-12-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0999,
"startDate": "2019-01-01T00:00:00.000Z",
"endDate": "2019-01-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0993,
"startDate": "2019-02-01T00:00:00.000Z",
"endDate": "2019-02-28T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0993,
"startDate": "2019-03-01T00:00:00.000Z",
"endDate": "2019-03-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0977,
"startDate": "2019-04-01T00:00:00.000Z",
"endDate": "2019-04-30T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0973,
"startDate": "2019-05-01T00:00:00.000Z",
"endDate": "2019-05-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0969,
"startDate": "2019-06-01T00:00:00.000Z",
"endDate": "2019-06-30T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0795,
"startDate": "2019-07-01T00:00:00.000Z",
"endDate": "2019-07-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0791,
"startDate": "2019-08-01T00:00:00.000Z",
"endDate": "2019-08-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0785,
"startDate": "2019-09-01T00:00:00.000Z",
"endDate": "2019-09-30T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.077,
"startDate": "2019-10-01T00:00:00.000Z",
"endDate": "2019-10-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0789,
"startDate": "2019-11-01T00:00:00.000Z",
"endDate": "2019-11-30T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0793,
"startDate": "2019-12-01T00:00:00.000Z",
"endDate": "2019-12-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0787,
"startDate": "2020-01-01T00:00:00.000Z",
"endDate": "2020-01-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0765,
"startDate": "2020-02-01T00:00:00.000Z",
"endDate": "2020-02-29T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0736,
"startDate": "2020-03-01T00:00:00.000Z",
"endDate": "2020-03-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.071,
"startDate": "2020-04-01T00:00:00.000Z",
"endDate": "2020-04-30T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0703,
"startDate": "2020-05-01T00:00:00.000Z",
"endDate": "2020-05-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0687,
"startDate": "2020-06-01T00:00:00.000Z",
"endDate": "2020-06-30T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0698,
"startDate": "2020-07-01T00:00:00.000Z",
"endDate": "2020-07-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0705,
"startDate": "2020-08-01T00:00:00.000Z",
"endDate": "2020-08-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0709,
"startDate": "2020-09-01T00:00:00.000Z",
"endDate": "2020-09-30T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0735,
"startDate": "2020-10-01T00:00:00.000Z",
"endDate": "2020-10-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0745,
"startDate": "2020-11-01T00:00:00.000Z",
"endDate": "2020-11-30T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0759,
"startDate": "2020-12-01T00:00:00.000Z",
"endDate": "2020-12-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.076,
"startDate": "2021-01-01T00:00:00.000Z",
"endDate": "2021-01-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0782,
"startDate": "2021-02-01T00:00:00.000Z",
"endDate": "2021-02-28T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0818,
"startDate": "2021-03-01T00:00:00.000Z",
"endDate": "2021-03-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.079,
"startDate": "2021-04-01T00:00:00.000Z",
"endDate": "2021-04-30T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0797,
"startDate": "2021-05-01T00:00:00.000Z",
"endDate": "2021-05-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0826,
"startDate": "2021-06-01T00:00:00.000Z",
"endDate": "2021-06-30T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0895,
"startDate": "2021-07-01T00:00:00.000Z",
"endDate": "2021-07-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.0934,
"startDate": "2021-08-01T00:00:00.000Z",
"endDate": "2021-08-31T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.1002,
"startDate": "2021-09-01T00:00:00.000Z",
"endDate": "2021-09-30T23:59:59.000Z"
},
{
"fluidType": 2,
"price": 0.1121,
"startDate": "2021-10-01T00:00:00.000Z",
"endDate": null
}
]
export const FLUIDPRICES_DOCTYPE = 'com.grandlyon.ecolyo.fluidsprices'
......@@ -16,6 +16,7 @@ import { CHALLENGE_DOCTYPE } from './com-grandlyon-ecolyo-challenge'
import { USERCHALLENGE_DOCTYPE } from './com-grandlyon-ecolyo-userchallenge'
import { DUEL_DOCTYPE } from './com-grandlyon-ecolyo-duel'
import { QUIZ_DOCTYPE } from './com-grandlyon-ecolyo-quiz'
import { FLUIDPRICES_DOCTYPE } from './com-grandlyon-ecolyo-fluidsprices'
import { USAGEEVENT_DOCTYPE } from './com-grandlyon-ecolyo-usageevent'
import { EXPLORATION_DOCTYPE } from './com-grandlyon-ecolyo-exploration'
import { ENEDIS_YEAR_DOCTYPE } from './com-grandlyon-enedis-year'
......@@ -163,6 +164,11 @@ const doctypes = {
attributes: {},
relationships: {},
},
fluidsPrices: {
doctype: FLUIDPRICES_DOCTYPE,
attributes: {},
relationships: {},
},
enedismonthlyanalysisdata: {
doctype: ENEDIS_MONTHLY_ANALYSIS_DATA_DOCTYPE,
attributes: {},
......@@ -203,6 +209,7 @@ export * from './com-grandlyon-ecolyo-ecogesture'
export * from './com-grandlyon-ecolyo-profile'
export * from './com-grandlyon-ecolyo-profiletype'
export * from './com-grandlyon-ecolyo-schemas'
export * from './com-grandlyon-ecolyo-fluidsprices'
export * from './com-grandlyon-ecolyo-challenge'
export * from './com-grandlyon-ecolyo-userchallenge'
......
......@@ -6,11 +6,13 @@ import {
EGL_DAY_DOCTYPE,
EGL_MONTH_DOCTYPE,
EGL_YEAR_DOCTYPE,
FLUIDPRICES_DOCTYPE,
} from 'doctypes'
import { Profile, ProfileType, UserChallenge } from 'models'
import { Client } from 'cozy-client'
import { DateTime } from 'luxon'
import { UserQuizState } from 'enum/userQuiz.enum'
import fluidsPricesData from 'db/fluidPrices.json'
export const SCHEMA_INITIAL_VERSION = 0
......@@ -264,4 +266,18 @@ export const migrations: Migration[] = [
return docs
},
},
{
baseSchemaVersion: 8,
targetSchemaVersion: 9,
appVersion: '1.6.0',
description: 'Init new doctype fluidPrices',
releaseNotes: null,
docTypes: FLUIDPRICES_DOCTYPE,
isCreate: true,
run: async (_client: Client, docs: any[]): Promise<any> => {
for (const fluidPrice of fluidsPricesData) {
await _client.create(FLUIDPRICES_DOCTYPE, fluidPrice)
}
},
},
]
......@@ -41,9 +41,8 @@ export class MigrationService {
if (result.type === MIGRATION_RESULT_FAILED) {
// Error in case of second failure
const err = new Error(result.errors.toString())
log.error(migrationLog(migration, result))
throw err
throw new Error()
} else {
log.info(migrationLog(migration, result))
}
......
import { QueryResult } from 'cozy-client'