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

build delivery

parent a9d572b8
......@@ -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
})
......
Markdown is supported
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