diff --git a/index.js b/index.js index e70c0873dffaf72df675751a417f34277a1ab6d1..5dfc64c50ac0c98bda05a776e1795cb927958fb5 100644 --- a/index.js +++ b/index.js @@ -114,6 +114,7 @@ const startDailyDate = manualExecution const startDailyDateString = startDailyDate.format('YYYY-MM-DD') const startLoadDate = moment().subtract(7, 'day') const startLoadDateString = startLoadDate.format('YYYY-MM-DD') +const checkHistoryDate = moment().subtract(8, 'day') const endDate = moment() const endDateString = endDate.format('YYYY-MM-DD') const baseUrl = 'https://gw.prd.api.enedis.fr' @@ -242,7 +243,7 @@ async function startLoadDataProcess(token, usagePointID) { log('info', 'Check history') const isHistory = await isHistoryLoaded('com.grandlyon.enedis.minute') log('info', `isHistory: ${isHistory}`) - if (isHistory) { + if (isHistory || manualExecution) { log('info', 'launch process without history') await launchLoadDataProcess( token, @@ -331,7 +332,7 @@ async function isHistoryLoaded(doctype) { day: el.day, minute: el.minute, }) - return elDate.isBefore(startLoadDate) + return elDate.isBefore(checkHistoryDate) }) if (filtered.length > 0) { return true @@ -360,13 +361,13 @@ async function launchLoadDataProcess( ) if (fetchedLoadData && fetchedLoadData.length > 0) { log('info', 'Process enedis load data') - const processedLoadData = await processData( - fetchedLoadData, - 'com.grandlyon.enedis.minute', - ['year', 'month', 'day', 'hour', 'minute'] - ) - // log('info', 'Agregate enedis load data for hour') - // await agregateHourlyData(processedLoadData) + await processData(fetchedLoadData, 'com.grandlyon.enedis.minute', [ + 'year', + 'month', + 'day', + 'hour', + 'minute', + ]) } else { log('info', 'No consent or data for load curve') } @@ -449,40 +450,6 @@ async function agregateMonthAndYearData(data) { } } -/** - * Agregate data from load data (every 30 min) to Hourly data - */ -async function agregateHourlyData(data) { - // Sum year and month values into object with year or year-month as keys - if (data && data.length > 0) { - let hourData = {} - data.forEach(element => { - let key = - element.year + - '-' + - element.month + - '-' + - element.day + - '-' + - element.hour - key in hourData - ? (hourData[key] += element.load) - : (hourData[key] = element.load) - }) - // Agregation for Month data - const agregatedMonthData = await buildAgregatedData( - hourData, - 'com.grandlyon.enedis.hour' - ) - await storeData(agregatedMonthData, 'com.grandlyon.enedis.hour', [ - 'year', - 'month', - 'day', - 'hour', - ]) - } -} - /** * Save data in the right doctype db and prevent duplicated keys */