diff --git a/README.md b/README.md index 36cd1d526c703cdf4ab05c066d86e8b0dcbd7577..ee408f3c9cb112be30833ab074c84ef51a8efff3 100755 --- a/README.md +++ b/README.md @@ -28,7 +28,10 @@ Create a `konnector-dev-config.json` file at the root with your test credentials ```javascript { "COZY_URL": "http://cozy.tools:8080", - "fields": {"login":"zuck.m@rk.fb", "password":"123456"} + "fields": { + "access_token": , + "id_pce": + } } ``` Then : diff --git a/src/index.js b/src/index.js index 6dec2afa0c1303276beaea8a555950dae84e0db2..53640371e0d85e6c4255e9c3250d191c30908451 100755 --- a/src/index.js +++ b/src/index.js @@ -40,6 +40,12 @@ module.exports = new BaseKonnector(start) async function start(fields) { log('debug', 'Starting grdf adict konnector') + if (process.env.NODE_ENV === "standalone") { + const grdfData = await getData(fields.access_token, fields.id_pce); + processAndAggregateData(grdfData) + return + } + const accountId = getAccountId() let body = '' let id_pce = '' @@ -60,18 +66,7 @@ async function start(fields) { log('debug', 'THE ID_PCE SENDING TO GETDATA : ' + id_pce) const grdfData = await getData(fields.access_token, id_pce) - if (grdfData) { - log('debug', 'Process grdf daily data') - const processedLoadData = await processData( - grdfData, - 'com.grandlyon.grdf.day', - ['year', 'month', 'day'] - ) - log('debug', 'Agregate grdf load data for month and year') - await agregateMonthAndYearData(processedLoadData) - } else { - log('debug', 'No consent or data for load curve') - } + processAndAggregateData(grdfData) } else { log('debug', 'no id_token found in oauth_callback_results') log( @@ -166,7 +161,7 @@ async function getData(token, idPCE) { * Return the list of filtered data */ async function processData(data, doctype, filterKeys) { - const formatedData = await formateData(data) + const formatedData = await formatData(data) log('debug', 'processData - data formated') // Remove data for existing days into the DB const filteredData = await hydrateAndFilter(formatedData, doctype, { @@ -193,7 +188,7 @@ async function storeData(data, doctype, filterKeys) { * Format data for DB storage * Remove bad data */ -async function formateData(data) { +async function formatData(data) { log('debug', 'Formating data') return data.map(record => { let date = moment(record.date_debut_consommation, 'YYYY/MM/DD h:mm:ss') @@ -344,3 +339,22 @@ async function resetInProgressAggregatedData(data, doctype) { } return 0.0 } + +/** + * 1. Processes data. + * 2. Aggregates data. + */ +async function processAndAggregateData(data) { + if (data) { + log("debug", "Process grdf daily data"); + const processedLoadData = await processData( + data, + "com.grandlyon.grdf.day", + ["year", "month", "day"] + ); + log("debug", "Agregate grdf load data for month and year"); + await agregateMonthAndYearData(processedLoadData); + } else { + log("debug", "No consent or data for load curve"); + } +}