From 23449a3118063198138cc756179cb5311a4587c0 Mon Sep 17 00:00:00 2001 From: Hugo <hnouts.dev@gmail.com> Date: Thu, 18 Feb 2021 15:58:18 +0100 Subject: [PATCH] substracting whith pending data :( --- package.json | 1 + src/index.js | 16 +++++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 4ec1206..9171513 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "build": "webpack", "lint": "eslint --fix .", "deploy": "git-directory-deploy --directory build/ --branch ${DEPLOY_BRANCH:-build} --repo=${DEPLOY_REPOSITORY:-https://forge.grandlyon.com/web-et-numerique/llle_project/egl-konnector.git}", + "deploy-dev": "git-directory-deploy --directory build/ --branch ${DEPLOY_BRANCH:-build-dev} --repo=${DEPLOY_REPOSITORY:-https://forge.grandlyon.com/web-et-numerique/llle_project/egl-konnector.git}", "cozyPublish": "cozy-app-publish --token $REGISTRY_TOKEN --build-commit $(git rev-parse ${DEPLOY_BRANCH:-build})", "travisDeployKey": "./bin/generate_travis_deploy_key" }, diff --git a/src/index.js b/src/index.js index 15894fb..f75402f 100644 --- a/src/index.js +++ b/src/index.js @@ -46,7 +46,7 @@ async function start(fields, cozyParameters) { // await resetData() const baseUrl = cozyParameters.secret.eglBaseURL const apiAuthKey = cozyParameters.secret.eglAPIAuthKey - log('debug', fields, 'Fields') + log('info', 'Start fields are : ' + fields) log('info', 'Authenticating ...') const response = await authenticate( @@ -67,24 +67,24 @@ async function start(fields, cozyParameters) { } async function processData(timeStep, response, baseUrl, apiAuthKey) { const doctype = rangeDate[timeStep].doctype - log('info', 'Getting data') + log('info', 'Getting data TIMESTEP : ' + timeStep) const loadProfile = await getData(response, baseUrl, apiAuthKey) log('info', 'Saving data to Cozy') if (doctype === rangeDate.day.doctype) { - log('info', 'Saving daily data') + log('info', 'Saving daily data' + loadProfile) await storeData(loadProfile, rangeDate.day.doctype, rangeDate.day.keys) } else if (doctype === rangeDate.month.doctype) { - log('info', 'Saving monthly data') await resetInProgressAggregatedData(rangeDate.month.doctype) const monthlyData = processMonthlyAggregation(loadProfile, rangeDate.month) + log('info', 'Saving monthly data' + monthlyData) await storeData(monthlyData, rangeDate.month.doctype, rangeDate.month.keys) } else if (doctype === rangeDate.year.doctype) { - log('info', 'Saving yearly data') await resetInProgressAggregatedData(rangeDate.year.doctype) const yearlyData = processYearAggregation( loadProfile, rangeDate.year.doctype ) + log('info', 'Saving yearly data' + yearlyData) await storeData(yearlyData, rangeDate.year.doctype, rangeDate.year.keys) } else { throw new Error('Unkonw range type: ' + doctype) @@ -114,8 +114,8 @@ async function authenticate(login, password, baseUrl, apiAuthKey) { } async function getData(response, baseUrl, apiAuthKey) { - log('debug', startDate, 'Start date') - log('debug', endDate, 'End date') + log('debug', 'Start date : ' + startDate) + log('debug', 'End date : ' + endDate) const dataRequest = { method: 'POST', uri: baseUrl + '/getAllAgregatsByAbonnement.aspx', @@ -152,6 +152,7 @@ function format(response) { const data = response.resultatRetour.slice(1).map((value, index) => { const time = moment(value.DateReleve, moment.ISO_8601) return { + // Add if/else to not substract null value (typeagregat T) load: value.ValeurIndex - response.resultatRetour[index].ValeurIndex, year: parseInt(time.format('YYYY')), month: parseInt(time.format('M')), @@ -161,6 +162,7 @@ function format(response) { type: value.TypeAgregat } }) + log('info', 'Dataload is : ' + data) return data } -- GitLab