Commit 9b6286f5 authored by Hugo's avatar Hugo
Browse files

build delivery

parent a9d572b8
...@@ -6,6 +6,7 @@ const { ...@@ -6,6 +6,7 @@ const {
hydrateAndFilter, hydrateAndFilter,
cozyClient cozyClient
} = require("cozy-konnector-libs"); } = require("cozy-konnector-libs");
const rp = require("request-promise"); const rp = require("request-promise");
const moment = require("moment"); const moment = require("moment");
require("moment-timezone"); require("moment-timezone");
...@@ -13,12 +14,12 @@ require("moment-timezone"); ...@@ -13,12 +14,12 @@ require("moment-timezone");
moment.locale("fr"); // set the language moment.locale("fr"); // set the language
moment.tz.setDefault("Europe/Paris"); // set the timezone moment.tz.setDefault("Europe/Paris"); // set the timezone
const startDate = moment() const manualExecution = process.env.COZY_JOB_MANUAL_EXECUTION === "true" ? true : false
.startOf("year")
// .subtract(3, "year") const startDate = manualExecution
.subtract(1, "month") ? moment().startOf("year").subtract(1, "year").format("MM/DD/YYYY")
.subtract(1, "day") : moment().startOf("year").subtract(3, "year").format("MM/DD/YYYY")
.format("MM/DD/YYYY");
const endDate = moment().format("MM/DD/YYYY"); const endDate = moment().format("MM/DD/YYYY");
const timeRange = ["day", "month", "year"]; const timeRange = ["day", "month", "year"];
const rangeDate = { const rangeDate = {
...@@ -66,10 +67,8 @@ async function start(fields, cozyParameters) { ...@@ -66,10 +67,8 @@ async function start(fields, cozyParameters) {
} }
async function processData(timeStep, response, baseUrl, apiAuthKey) { async function processData(timeStep, response, baseUrl, apiAuthKey) {
const doctype = rangeDate[timeStep].doctype; const doctype = rangeDate[timeStep].doctype;
log("info", "Getting data TIMESTEP : " + timeStep);
const loadProfile = await getData(response, baseUrl, apiAuthKey); const loadProfile = await getData(response, baseUrl, apiAuthKey);
log("info", "Saving data to Cozy"); log("info", "Saving data to Cozy");
log("info", "Response length : " + loadProfile.length);
if (doctype === rangeDate.day.doctype) { if (doctype === rangeDate.day.doctype) {
await storeData(loadProfile, rangeDate.day.doctype, rangeDate.day.keys); await storeData(loadProfile, rangeDate.day.doctype, rangeDate.day.keys);
} else if (doctype === rangeDate.month.doctype) { } else if (doctype === rangeDate.month.doctype) {
...@@ -157,15 +156,6 @@ function format(response) { ...@@ -157,15 +156,6 @@ function format(response) {
const mapData = data.map((value, index) => { const mapData = data.map((value, index) => {
const time = moment(value.DateReleve, moment.ISO_8601); const time = moment(value.DateReleve, moment.ISO_8601);
if (index + 1 < dataLen) { if (index + 1 < dataLen) {
log(
"info",
"date is " +
value.DateReleve +
" SUBSTRACTING : " +
data[index + 1].ValeurIndex +
" - " +
value.ValeurIndex
);
return { return {
load: data[index + 1].ValeurIndex - value.ValeurIndex, load: data[index + 1].ValeurIndex - value.ValeurIndex,
year: parseInt(time.format("YYYY")), year: parseInt(time.format("YYYY")),
...@@ -248,9 +238,9 @@ function reduceMonthFunction(acc, x) { ...@@ -248,9 +238,9 @@ function reduceMonthFunction(acc, x) {
async function storeData(data, doctype, filterKeys) { async function storeData(data, doctype, filterKeys) {
log("debug", "Store into " + doctype); log("debug", "Store into " + doctype);
log("debug", "Store into keys : " + filterKeys); log("debug", "Store into keys : " + filterKeys);
data.map(v => { // data.map(v => {
log("info", "Saving data " + v.load + " for " + v.day + "/" + v.month + "/" + v.year); // log("info", "Saving data " + v.load + " for " + v.day + "/" + v.month + "/" + v.year);
}); // });
const filteredDocuments = await hydrateAndFilter(data, doctype, { const filteredDocuments = await hydrateAndFilter(data, doctype, {
keys: filterKeys keys: filterKeys
}) })
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment