Skip to content
Snippets Groups Projects
Commit 3365060f authored by Hugo's avatar Hugo
Browse files

filter map

parent 7351b5ce
No related branches found
No related tags found
1 merge request!4Dev
...@@ -47,8 +47,6 @@ async function start(fields, cozyParameters) { ...@@ -47,8 +47,6 @@ async function start(fields, cozyParameters) {
// await resetData() // await resetData()
const baseUrl = cozyParameters.secret.eglBaseURL const baseUrl = cozyParameters.secret.eglBaseURL
const apiAuthKey = cozyParameters.secret.eglAPIAuthKey const apiAuthKey = cozyParameters.secret.eglAPIAuthKey
log('info', 'Start fields are : ' + fields)
log('info', 'Authenticating ...') log('info', 'Authenticating ...')
const response = await authenticate( const response = await authenticate(
fields.login, fields.login,
...@@ -150,12 +148,23 @@ async function getData(response, baseUrl, apiAuthKey) { ...@@ -150,12 +148,23 @@ async function getData(response, baseUrl, apiAuthKey) {
} }
function format(response) { 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) 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 { return {
// Add if/else to not substract null value (typeagregat T) load:
load: value.TypeAgregat === 'T' ? null : value.ValeurIndex - response.resultatRetour[index].ValeurIndex, value.TypeAgregat === 'T'
? null
: value.ValeurIndex - response.resultatRetour[index].ValeurIndex,
year: parseInt(time.format('YYYY')), year: parseInt(time.format('YYYY')),
month: parseInt(time.format('M')), month: parseInt(time.format('M')),
day: parseInt(time.format('D')), day: parseInt(time.format('D')),
...@@ -165,8 +174,18 @@ function format(response) { ...@@ -165,8 +174,18 @@ function format(response) {
} }
}) })
log('info', 'DATALOAD LIST\n') log('info', 'DATALOAD LIST\n')
data.map((value) => { data.map(value => {
log('info', value.month + '-' + value.day + '-' + value.year + ' : ' + value.load + '\n') log(
'info',
value.month +
'-' +
value.day +
'-' +
value.year +
' : ' +
value.load +
'\n'
)
}) })
return data return data
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment