From 9b6286f54b21636b7494d9768c9d439769c4bad1 Mon Sep 17 00:00:00 2001 From: Hugo <hnouts.dev@gmail.com> Date: Thu, 25 Feb 2021 10:46:14 +0100 Subject: [PATCH] build delivery --- src/index.js | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/src/index.js b/src/index.js index 5201292..9891c76 100644 --- a/src/index.js +++ b/src/index.js @@ -6,6 +6,7 @@ const { hydrateAndFilter, cozyClient } = require("cozy-konnector-libs"); + const rp = require("request-promise"); const moment = require("moment"); require("moment-timezone"); @@ -13,12 +14,12 @@ require("moment-timezone"); moment.locale("fr"); // set the language moment.tz.setDefault("Europe/Paris"); // set the timezone -const startDate = moment() - .startOf("year") - // .subtract(3, "year") - .subtract(1, "month") - .subtract(1, "day") - .format("MM/DD/YYYY"); +const manualExecution = process.env.COZY_JOB_MANUAL_EXECUTION === "true" ? true : false + +const startDate = manualExecution + ? moment().startOf("year").subtract(1, "year").format("MM/DD/YYYY") + : moment().startOf("year").subtract(3, "year").format("MM/DD/YYYY") + const endDate = moment().format("MM/DD/YYYY"); const timeRange = ["day", "month", "year"]; const rangeDate = { @@ -66,10 +67,8 @@ async function start(fields, cozyParameters) { } async function processData(timeStep, response, baseUrl, apiAuthKey) { const doctype = rangeDate[timeStep].doctype; - log("info", "Getting data TIMESTEP : " + timeStep); const loadProfile = await getData(response, baseUrl, apiAuthKey); log("info", "Saving data to Cozy"); - log("info", "Response length : " + loadProfile.length); if (doctype === rangeDate.day.doctype) { await storeData(loadProfile, rangeDate.day.doctype, rangeDate.day.keys); } else if (doctype === rangeDate.month.doctype) { @@ -157,15 +156,6 @@ function format(response) { const mapData = data.map((value, index) => { const time = moment(value.DateReleve, moment.ISO_8601); if (index + 1 < dataLen) { - log( - "info", - "date is " + - value.DateReleve + - " SUBSTRACTING : " + - data[index + 1].ValeurIndex + - " - " + - value.ValeurIndex - ); return { load: data[index + 1].ValeurIndex - value.ValeurIndex, year: parseInt(time.format("YYYY")), @@ -248,9 +238,9 @@ function reduceMonthFunction(acc, x) { async function storeData(data, doctype, filterKeys) { log("debug", "Store into " + doctype); log("debug", "Store into keys : " + filterKeys); - data.map(v => { - log("info", "Saving data " + v.load + " for " + v.day + "/" + v.month + "/" + v.year); - }); + // data.map(v => { + // log("info", "Saving data " + v.load + " for " + v.day + "/" + v.month + "/" + v.year); + // }); const filteredDocuments = await hydrateAndFilter(data, doctype, { keys: filterKeys }) -- GitLab