From e904447b6751501116cf44a0669cae0b4961f69e Mon Sep 17 00:00:00 2001
From: Yoan VALLET <ext.sopra.yvallet@grandlyon.com>
Date: Wed, 10 Jun 2020 13:32:22 +0200
Subject: [PATCH] publish: Change doctype to com.grandlyon.enedis.*

generated from commit 66a59bea2341e125c3203c66e9160b4f4dfe5173
---
 index.js | 33 +++++++++++++++++++--------------
 1 file changed, 19 insertions(+), 14 deletions(-)

diff --git a/index.js b/index.js
index 55c6109..84bfebd 100644
--- a/index.js
+++ b/index.js
@@ -153,7 +153,7 @@ async function start(fields, cozyParameters, doRetry = true) {
     log('info', 'Process enedis daily data')
     const processedDailyData = await processData(
       fetchedDailyData,
-      'io.enedis.day',
+      'com.grandlyon.enedis.day',
       ['year', 'month', 'day']
     )
     log('info', 'Agregate enedis daily data for month and year')
@@ -165,7 +165,7 @@ async function start(fields, cozyParameters, doRetry = true) {
       log('info', 'Process enedis load data')
       const processedLoadData = await processData(
         fetchedLoadData,
-        'io.enedis.minute',
+        'com.grandlyon.enedis.minute',
         ['year', 'month', 'day', 'hour', 'minute']
       )
       log('info', 'Agregate enedis load data for hour')
@@ -303,15 +303,18 @@ async function agregateMonthAndYearData(data) {
     // Agregation for Month data
     const agregatedMonthData = await buildAgregatedData(
       monthData,
-      'io.enedis.month'
+      'com.grandlyon.enedis.month'
     )
-    await storeData(agregatedMonthData, 'io.enedis.month', ['year', 'month'])
+    await storeData(agregatedMonthData, 'com.grandlyon.enedis.month', [
+      'year',
+      'month'
+    ])
     // Agregation for Year data
     const agregatedYearData = await buildAgregatedData(
       yearData,
-      'io.enedis.year'
+      'com.grandlyon.enedis.year'
     )
-    await storeData(agregatedYearData, 'io.enedis.year', ['year'])
+    await storeData(agregatedYearData, 'com.grandlyon.enedis.year', ['year'])
   }
 }
 
@@ -338,9 +341,9 @@ async function agregateHourlyData(data) {
     // Agregation for Month data
     const agregatedMonthData = await buildAgregatedData(
       hourData,
-      'io.enedis.hour'
+      'com.grandlyon.enedis.hour'
     )
-    await storeData(agregatedMonthData, 'io.enedis.hour', [
+    await storeData(agregatedMonthData, 'com.grandlyon.enedis.hour', [
       'year',
       'month',
       'day',
@@ -370,7 +373,9 @@ async function formateData(data, doctype) {
     const date = moment(record.date, 'YYYY/MM/DD h:mm:ss')
     if (record.value != -2) {
       const load =
-        doctype === 'io.enedis.minute' ? record.value / 2 : record.value
+        doctype === 'com.grandlyon.enedis.minute'
+          ? record.value / 2
+          : record.value
       return {
         load: parseFloat(load / 1000),
         year: parseInt(date.format('YYYY')),
@@ -406,12 +411,12 @@ async function buildAgregatedData(data, doctype) {
  */
 async function buildDataFromKey(doctype, key, value) {
   let year, month, day, hour
-  if (doctype === 'io.enedis.year') {
+  if (doctype === 'com.grandlyon.enedis.year') {
     year = key
     month = 1
     day = 0
     hour = 0
-  } else if (doctype === 'io.enedis.month') {
+  } else if (doctype === 'com.grandlyon.enedis.month') {
     const split = key.split('-')
     year = split[0]
     month = split[1]
@@ -437,7 +442,7 @@ async function buildDataFromKey(doctype, key, value) {
 /**
  * Function handling special case.
  * The temporary aggregated data need to be remove in order for the most recent one te be saved.
- * ex for io.enedis.year :
+ * ex for com.grandlyon.enedis.year :
  * { load: 76.712, year: 2020, ... } need to be replace by
  * { load: 82.212, year: 2020, ... } after enedis data reprocess
  */
@@ -448,12 +453,12 @@ async function resetInProgressAggregatedData(data, doctype) {
   if (result && result.length > 0) {
     // Filter data to remove
     var filtered = []
-    if (doctype === 'io.enedis.year') {
+    if (doctype === 'com.grandlyon.enedis.year') {
       // Yearly case
       filtered = result.filter(function(el) {
         return el.year == data.year
       })
-    } else if (doctype === 'io.enedis.month') {
+    } else if (doctype === 'com.grandlyon.enedis.month') {
       // Monthly case
       filtered = result.filter(function(el) {
         return el.year == data.year && el.month == data.month
-- 
GitLab