Commit 7e588a1b authored by Yoan VALLET's avatar Yoan VALLET
Browse files

fix issue when load is unknown

parent 86dd2096
......@@ -54,8 +54,8 @@ async function start(fields) {
const grdfData = await getData(fields.access_token, id_pce)
if (grdfData) {
log("debug", "Clean data retrieve by old scraping konnector")
await cleanOldData()
// log("debug", "Clean data retrieve by old scraping konnector")
// await cleanOldData()
log('debug', 'Process grdf daily data')
const processedLoadData = await processData(
grdfData,
......@@ -132,42 +132,42 @@ async function getData(token, idPCE) {
* Get All actual daily data stored in the db
* Return the list of daily data
*/
async function cleanOldData() {
if(moment().diff(moment("2020-12-02", "DD/MM/YYYY")) > 0){
log('debug', 'No cleaning to do')
return false
} else {
log('debug', 'Start cleaning old data')
const documents = await cozyClient.data.findAll('com.grandlyon.grdf.day')
if (documents && documents.length > 0) {
const result = []
for (const doc of documents) {
const deleteResult = await cozyClient.data.delete('com.grandlyon.grdf.day', doc)
result.push(deleteResult)
}
log("debug", "NB OF DELETED OLD DAY DATA : " + result.length)
}
const documentsMonth = await cozyClient.data.findAll('com.grandlyon.grdf.month')
if (documentsMonth && documentsMonth.length > 0) {
const result = []
for (const doc of documentsMonth) {
const deleteResult = await cozyClient.data.delete('com.grandlyon.grdf.month', doc)
result.push(deleteResult)
}
log("debug", "NB OF DELETED OLD MONTH DATA : " + result.length)
}
const documentsYear = await cozyClient.data.findAll('com.grandlyon.grdf.year')
if (documentsYear && documentsYear.length > 0) {
const result = []
for (const doc of documentsYear) {
await cozyClient.data.delete('com.grandlyon.grdf.year', doc)
result.push(deleteResult)
}
log("debug", "NB OF DELETED OLD YEAR DATA : " + result.length)
}
return true
}
}
// async function cleanOldData() {
// if(moment().diff(moment("2020-12-02", "DD/MM/YYYY")) > 0){
// log('debug', 'No cleaning to do')
// return false
// } else {
// log('debug', 'Start cleaning old data')
// const documents = await cozyClient.data.findAll('com.grandlyon.grdf.day')
// if (documents && documents.length > 0) {
// const result = []
// for (const doc of documents) {
// const deleteResult = await cozyClient.data.delete('com.grandlyon.grdf.day', doc)
// result.push(deleteResult)
// }
// log("debug", "NB OF DELETED OLD DAY DATA : " + result.length)
// }
// const documentsMonth = await cozyClient.data.findAll('com.grandlyon.grdf.month')
// if (documentsMonth && documentsMonth.length > 0) {
// const result = []
// for (const doc of documentsMonth) {
// const deleteResult = await cozyClient.data.delete('com.grandlyon.grdf.month', doc)
// result.push(deleteResult)
// }
// log("debug", "NB OF DELETED OLD MONTH DATA : " + result.length)
// }
// const documentsYear = await cozyClient.data.findAll('com.grandlyon.grdf.year')
// if (documentsYear && documentsYear.length > 0) {
// const result = []
// for (const doc of documentsYear) {
// await cozyClient.data.delete('com.grandlyon.grdf.year', doc)
// result.push(deleteResult)
// }
// log("debug", "NB OF DELETED OLD YEAR DATA : " + result.length)
// }
// return true
// }
// }
/**
* Parse data
......@@ -208,9 +208,11 @@ async function formateData(data) {
return data.map(record => {
let date = moment(record.date_debut_consommation, 'YYYY/MM/DD h:mm:ss')
let load =
record.energie !== 0
record.energie && record.energie !== 0
? record.energie
: record.volume_brut * record.coeff_calcul.coeff_conversion
: record.volume_brut
? record.volume_brut * record.coeff_calcul.coeff_conversion
: 0
return {
load: parseFloat(load),
year: parseInt(date.format('YYYY')),
......
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