Skip to content
Snippets Groups Projects
Commit d3d444c9 authored by Bastien DUMONT's avatar Bastien DUMONT :angel:
Browse files

feat: standalone mode

parent 9097cdbb
No related branches found
No related tags found
1 merge request!8feat : standalone mode
...@@ -28,7 +28,10 @@ Create a `konnector-dev-config.json` file at the root with your test credentials ...@@ -28,7 +28,10 @@ Create a `konnector-dev-config.json` file at the root with your test credentials
```javascript ```javascript
{ {
"COZY_URL": "http://cozy.tools:8080", "COZY_URL": "http://cozy.tools:8080",
"fields": {"login":"zuck.m@rk.fb", "password":"123456"} "fields": {
"access_token": ,
"id_pce":
}
} }
``` ```
Then : Then :
......
...@@ -40,6 +40,12 @@ module.exports = new BaseKonnector(start) ...@@ -40,6 +40,12 @@ module.exports = new BaseKonnector(start)
async function start(fields) { async function start(fields) {
log('debug', 'Starting grdf adict konnector') 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() const accountId = getAccountId()
let body = '' let body = ''
let id_pce = '' let id_pce = ''
...@@ -60,18 +66,7 @@ async function start(fields) { ...@@ -60,18 +66,7 @@ async function start(fields) {
log('debug', 'THE ID_PCE SENDING TO GETDATA : ' + id_pce) log('debug', 'THE ID_PCE SENDING TO GETDATA : ' + id_pce)
const grdfData = await getData(fields.access_token, id_pce) const grdfData = await getData(fields.access_token, id_pce)
if (grdfData) { processAndAggregateData(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')
}
} else { } else {
log('debug', 'no id_token found in oauth_callback_results') log('debug', 'no id_token found in oauth_callback_results')
log( log(
...@@ -166,7 +161,7 @@ async function getData(token, idPCE) { ...@@ -166,7 +161,7 @@ async function getData(token, idPCE) {
* Return the list of filtered data * Return the list of filtered data
*/ */
async function processData(data, doctype, filterKeys) { async function processData(data, doctype, filterKeys) {
const formatedData = await formateData(data) const formatedData = await formatData(data)
log('debug', 'processData - data formated') log('debug', 'processData - data formated')
// Remove data for existing days into the DB // Remove data for existing days into the DB
const filteredData = await hydrateAndFilter(formatedData, doctype, { const filteredData = await hydrateAndFilter(formatedData, doctype, {
...@@ -193,7 +188,7 @@ async function storeData(data, doctype, filterKeys) { ...@@ -193,7 +188,7 @@ async function storeData(data, doctype, filterKeys) {
* Format data for DB storage * Format data for DB storage
* Remove bad data * Remove bad data
*/ */
async function formateData(data) { async function formatData(data) {
log('debug', 'Formating data') log('debug', 'Formating data')
return data.map(record => { return data.map(record => {
let date = moment(record.date_debut_consommation, 'YYYY/MM/DD h:mm:ss') let date = moment(record.date_debut_consommation, 'YYYY/MM/DD h:mm:ss')
...@@ -344,3 +339,22 @@ async function resetInProgressAggregatedData(data, doctype) { ...@@ -344,3 +339,22 @@ async function resetInProgressAggregatedData(data, doctype) {
} }
return 0.0 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");
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment