Commit 3365060f authored by Hugo's avatar Hugo
Browse files

filter map

parent 7351b5ce
......@@ -47,8 +47,6 @@ async function start(fields, cozyParameters) {
// await resetData()
const baseUrl = cozyParameters.secret.eglBaseURL
const apiAuthKey = cozyParameters.secret.eglAPIAuthKey
log('info', 'Start fields are : ' + fields)
log('info', 'Authenticating ...')
const response = await authenticate(
fields.login,
......@@ -150,12 +148,23 @@ async function getData(response, baseUrl, apiAuthKey) {
}
function format(response) {
const data = response.resultatRetour.slice(1).map((value, index) => {
const data = response.resultatRetour.slice(1).filter(value => {
value.TypeAgregat === "R"
}).map((value, index) => {
const time = moment(value.DateReleve, moment.ISO_8601)
log('info', 'SUBSTRACTING : ' + value.ValeurIndex + ' - ' + response.resultatRetour[index].ValeurIndex + '\n')
log(
'info',
'date -> ' + value.DateReleve + ' SUBSTRACTING : ' +
value.ValeurIndex +
' - ' +
response.resultatRetour[index].ValeurIndex +
'\n'
)
return {
// Add if/else to not substract null value (typeagregat T)
load: value.TypeAgregat === 'T' ? null : value.ValeurIndex - response.resultatRetour[index].ValeurIndex,
load:
value.TypeAgregat === 'T'
? null
: value.ValeurIndex - response.resultatRetour[index].ValeurIndex,
year: parseInt(time.format('YYYY')),
month: parseInt(time.format('M')),
day: parseInt(time.format('D')),
......@@ -165,8 +174,18 @@ function format(response) {
}
})
log('info', 'DATALOAD LIST\n')
data.map((value) => {
log('info', value.month + '-' + value.day + '-' + value.year + ' : ' + value.load + '\n')
data.map(value => {
log(
'info',
value.month +
'-' +
value.day +
'-' +
value.year +
' : ' +
value.load +
'\n'
)
})
return data
}
......
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