diff --git a/src/index.js b/src/index.js index f660550f6b4dee163f42fb7db93183239439bb52..7372806b477e9b9d4bdf15568d8043464d31ee26 100644 --- a/src/index.js +++ b/src/index.js @@ -16,7 +16,7 @@ moment.tz.setDefault("Europe/Paris"); // set the timezone const startDate = moment() .startOf("year") // .subtract(3, "year") - .subtract(6, 'month') + .subtract(6, "month") .subtract(1, "day") .format("MM/DD/YYYY"); const endDate = moment().format("MM/DD/YYYY"); @@ -71,17 +71,11 @@ async function processData(timeStep, response, baseUrl, apiAuthKey) { log("info", "Saving data to Cozy"); log("info", "Response length : " + loadProfile.length); if (doctype === rangeDate.day.doctype) { - loadProfile.map(v => { - log( - "info", - "Saving daily data " + v.load + " for " + v.day + "/" + v.month - ); - }); await storeData(loadProfile, rangeDate.day.doctype, rangeDate.day.keys); } else if (doctype === rangeDate.month.doctype) { await resetInProgressAggregatedData(rangeDate.month.doctype); const monthlyData = processMonthlyAggregation(loadProfile, rangeDate.month); - log("info", "Saving monthly data" + monthlyData); + log("info", "Saving monthly data"); await storeData(monthlyData, rangeDate.month.doctype, rangeDate.month.keys); } else if (doctype === rangeDate.year.doctype) { await resetInProgressAggregatedData(rangeDate.year.doctype); @@ -89,7 +83,7 @@ async function processData(timeStep, response, baseUrl, apiAuthKey) { loadProfile, rangeDate.year.doctype ); - log("info", "Saving yearly data" + yearlyData); + log("info", "Saving yearly data"); await storeData(yearlyData, rangeDate.year.doctype, rangeDate.year.keys); } else { throw new Error("Unkonw range type: " + doctype); @@ -164,16 +158,12 @@ function format(response) { if (index + 1 < dataLen) { log( "info", - "date -> " + + "date is " + value.DateReleve + " SUBSTRACTING : " + data[index + 1].ValeurIndex + " - " + - value.ValeurIndex + - " == " + - data[index + 1].ValeurIndex - - value.ValeurIndex + - "\n" + value.ValeurIndex ); return { load: data[index + 1].ValeurIndex - value.ValeurIndex, @@ -253,7 +243,10 @@ function reduceMonthFunction(acc, x) { async function storeData(data, doctype, keys) { log("debug", "Store into " + doctype); - log("debug", keys, "Store into keys "); + log("debug", "Store into keys : " + keys); + data.map(v => { + log("info", "Saving data " + v.load + " for " + v.day + "/" + v.month); + }); return hydrateAndFilter(data, doctype, { keys: keys }).then(filteredDocuments => {