diff --git a/index.js b/index.js index 4df584d6b075568a3a5551143ed92015aae0b370..f26b325fd666b16064e45f37f48f5bbc489a987e 100644 --- a/index.js +++ b/index.js @@ -273,11 +273,11 @@ async function getData(response, baseUrl, apiAuthKey) { function format(response) { const data = response.resultatRetour .slice(1) - .filter(value => { - value.TypeAgregat === 'R' - }) - .map((value, index) => { - const time = moment(value.DateReleve, moment.ISO_8601) + .filter(value => value.ValeurIndex) + const dataLen = data.length + data.map((value, index) => { + const time = moment(value.DateReleve, moment.ISO_8601) + if (index + 1 < dataLen) { log( 'info', 'date -> ' + @@ -289,7 +289,7 @@ function format(response) { '\n' ) return { - load: value.ValeurIndex - response.resultatRetour[index].ValeurIndex, + load: data[index + 1].ValeurIndex - value.ValeurIndex, year: parseInt(time.format('YYYY')), month: parseInt(time.format('M')), day: parseInt(time.format('D')), @@ -297,7 +297,18 @@ function format(response) { minute: 0, type: value.TypeAgregat } - }) + } else { + return { + load: null, + year: parseInt(time.format('YYYY')), + month: parseInt(time.format('M')), + day: parseInt(time.format('D')), + hour: 0, + minute: 0, + type: value.TypeAgregat + } + } + }) log('info', 'DATALOAD LIST\n') data.map(value => { log(