From be5d658fd6c8b4996466e88e5457a13c5cb169db Mon Sep 17 00:00:00 2001
From: git-directory-deploy <>
Date: Tue, 9 Nov 2021 12:01:03 +0100
Subject: [PATCH] publish: update package version to 1.0.3

generated from commit b843506388b6c4768a079eea935b3b05ad741ea6
---
 index.js           | 152 +++++++++++++--------------------------------
 manifest.konnector |   2 +-
 package.json       |   7 ++-
 3 files changed, 48 insertions(+), 113 deletions(-)

diff --git a/index.js b/index.js
index ff7938f..483479e 100644
--- a/index.js
+++ b/index.js
@@ -108,8 +108,12 @@ const manualExecution =
   process.env.COZY_JOB_MANUAL_EXECUTION === 'true' ? true : false
 
 const startDate = manualExecution
-  ? moment().subtract(1, 'year').format('MM/DD/YYYY')
-  : moment().subtract(3, 'year').format('MM/DD/YYYY')
+  ? moment()
+      .subtract(1, 'year')
+      .format('MM/DD/YYYY')
+  : moment()
+      .subtract(3, 'year')
+      .format('MM/DD/YYYY')
 
 const endDate = moment().format('MM/DD/YYYY')
 // const timeRange = ['day', 'month', 'year']
@@ -135,8 +139,7 @@ module.exports = new BaseKonnector(start)
 // the account information come from ./konnector-dev-config.json file
 async function start(fields, cozyParameters) {
   try {
-    // resetting data for demo only
-    // await resetData()
+    // Local debug data
     // const baseUrl = fields.eglBaseURL
     // const apiAuthKey = fields.eglAPIAuthKey
     const baseUrl = cozyParameters.secret.eglBaseURL
@@ -239,30 +242,6 @@ async function buildAgregatedData(data, doctype) {
   return agregatedData
 }
 
-// async function processData(timeStep, response, baseUrl, apiAuthKey) {
-//   const doctype = rangeDate[timeStep].doctype;
-//   const loadProfile = await getData(response, baseUrl, apiAuthKey);
-//   log("info", "Saving data to Cozy");
-//   if (doctype === rangeDate.day.doctype) {
-//     await storeData(loadProfile, rangeDate.day.doctype, rangeDate.day.keys);
-//   } else if (doctype === rangeDate.month.doctype) {
-//     await resetInProgressAggregatedData(rangeDate.month.doctype);
-//     const monthlyData = processMonthlyAggregation(loadProfile, rangeDate.month);
-//     log("info", "Saving monthly data");
-//     await storeData(monthlyData, rangeDate.month.doctype, rangeDate.month.keys);
-//   } else if (doctype === rangeDate.year.doctype) {
-//     await resetInProgressAggregatedData(rangeDate.year.doctype);
-//     const yearlyData = processYearAggregation(
-//       loadProfile,
-//       rangeDate.year.doctype
-//     );
-//     log("info", "Saving yearly data");
-//     await storeData(yearlyData, rangeDate.year.doctype, rangeDate.year.keys);
-//   } else {
-//     throw new Error("Unkonw range type: " + doctype);
-//   }
-// }
-
 async function authenticate(login, password, baseUrl, apiAuthKey) {
   const authRequest = {
     method: 'POST',
@@ -304,16 +283,22 @@ async function getData(response, baseUrl, apiAuthKey) {
     json: true
   }
   try {
-    const responseEgl = await rp(dataRequest)
+    // Sort data by date
+    const responseEgl = await rp(dataRequest).then(eglRawData => {
+      eglRawData.resultatRetour.sort(function(a, b) {
+        return new Date(a.DateReleve) - new Date(b.DateReleve)
+      })
+      return eglRawData
+    })
     switch (responseEgl.codeRetour) {
       case 100:
         return format(responseEgl)
       case -2:
-        throw new Error(errors.LOGIN_FAILED)
+        throw errors.LOGIN_FAILED
       case -1:
-        throw new Error(errors.VENDOR_DOWN)
+        throw errors.VENDOR_DOWN
       default:
-        throw new Error(errors.UNKNOWN_ERROR)
+        throw errors.UNKNOWN_ERROR
     }
   } catch (error) {
     throw new Error(errors.VENDOR_DOWN)
@@ -322,90 +307,39 @@ async function getData(response, baseUrl, apiAuthKey) {
 
 function format(response) {
   log('info', 'origin response size is : ' + response.resultatRetour.length)
+  // Store first value as reference for index processing
+  let refValue = response.resultatRetour[0]
+  // Create copy of data without first value
   const data = response.resultatRetour
     .slice(1)
     .filter(value => value.ValeurIndex)
-  const dataLen = data.length
-  log('info', 'filtered size is : ' + dataLen)
-  const mapData = data.map((value, index) => {
+  log('info', 'filtered size is : ' + data.length)
+  return data.map(value => {
     const time = moment(value.DateReleve, moment.ISO_8601)
-    if (index !== 0 && index < dataLen) {
-      return {
-        load: value.ValeurIndex - data[index - 1].ValeurIndex,
-        year: parseInt(time.format('YYYY')),
-        month: parseInt(time.format('M')),
-        day: parseInt(time.format('D')),
-        hour: 0,
-        minute: 0,
-        type: value.TypeAgregat
-      }
-    } else {
-      return {
-        load: null,
-        year: parseInt(time.format('YYYY')),
-        month: parseInt(time.format('M')),
-        day: parseInt(time.format('D')),
-        hour: 0,
-        minute: 0,
-        type: value.TypeAgregat
-      }
+    const procesedLoad = value.ValeurIndex - refValue.ValeurIndex
+    if (procesedLoad < 0) {
+      log(
+        'error',
+        `processing load for day ${parseInt(time.format('D'))}/${parseInt(
+          time.format('M')
+        )}/${parseInt(time.format('YYYY'))}, value is : ${procesedLoad}`
+      )
+      throw errors.VENDOR_DOWN
+    }
+    // Change index ref value
+    refValue = value
+    return {
+      load: procesedLoad,
+      year: parseInt(time.format('YYYY')),
+      month: parseInt(time.format('M')),
+      day: parseInt(time.format('D')),
+      hour: 0,
+      minute: 0,
+      type: value.TypeAgregat
     }
   })
-  const res = [...mapData].filter(v => v.load !== null)
-  return res
 }
 
-// function processYearAggregation(data, doctype) {
-//   log("info", "Start aggregation for : " + doctype);
-//   const grouped = data.reduce(reduceYearFunction, {});
-//   return Object.values(grouped);
-// }
-
-// function processMonthlyAggregation(data, range) {
-//   log("info", "Start aggregation for : " + range.doctype);
-//   // Filter by year
-//   const tmpData = groupBy(data, "year");
-//   const keys = Object.keys(tmpData);
-//   var dataToStore = [];
-//   // Monthly aggregation
-//   for (const index in keys) {
-//     // Get daily data of a year
-//     var monthlyData = tmpData[keys[index]];
-//     // Monthly aggregation
-//     var aggregatedData = monthlyData.reduce(reduceMonthFunction, {});
-//     // Store it
-//     dataToStore = dataToStore.concat(Object.values(aggregatedData));
-//   }
-//   return dataToStore;
-// }
-
-// function groupBy(xs, key) {
-//   return xs.reduce(function(rv, x) {
-//     (rv[x[key]] = rv[x[key]] || []).push(x);
-//     return rv;
-//   }, {});
-// }
-
-// function reduceYearFunction(acc, x) {
-//   var id = acc[x.year];
-//   if (id) {
-//     id.load += x.load;
-//   } else {
-//     acc[x.year] = x;
-//   }
-//   return acc;
-// }
-
-// function reduceMonthFunction(acc, x) {
-//   var id = acc[x.month];
-//   if (id) {
-//     id.load += x.load;
-//   } else {
-//     acc[x.month] = x;
-//   }
-//   return acc;
-// }
-
 /**
  * Save data in the right doctype db and prevent duplicated keys
  */
@@ -138046,7 +137980,7 @@ const fs = __webpack_require__(167);
 
 const path = __webpack_require__(160);
 
-let manifest = typeof {"version":"1.0.1","name":"EGL","type":"konnector","language":"node","icon":"icon.png","slug":"eglgrandlyon","source":"https://forge.grandlyon.com/web-et-numerique/llle_project/egl-konnector.git","editor":"Métropole de Lyon","vendor_link":"www.grandlyon.com","frequency":"daily","categories":["energy"],"fields":{"login":{"type":"text"},"password":{"type":"password"},"advancedFields":{"folderPath":{"advanced":true,"isRequired":false}}},"data_types":[],"screenshots":[],"permissions":{"egl data":{"type":"com.grandlyon.egl.*"},"accounts":{"type":"io.cozy.accounts","verbs":["GET"]}},"developer":{"name":"Métropole de Lyon","url":"https://grandlyon.com"},"langs":["fr"],"locales":{"fr":{"short_description":"Courbe de charge depuis l'API eau du Grand Lyon","long_description":"Ce connecteur récupère la courbe de charge enregistrée par le compteur Téléo","permissions":{"egl data":{"description":"Requises pour accéder et stocker les données collectées par le compteur Téléo et exposées par les API Eau du Grand Lyon (consommations d’eau au jour, mois et année)."},"accounts":{"description":"Utilisé pour accéder à vos données de consommation."}}},"en":{"short_description":"Water consumption data fetched from \"Eau du Grand Lyon\" API","long_description":"This konnector fetches the data curve gathered by Téléo device.","permissions":{"egl data":{"description":"Required to access and store the data collected by the Téléo meter and exposed by Eau du Grand Lyon APIs (daily, monthly and yearly consumption)."},"accounts":{"description":"Used to access your consumption data."}}}},"manifest_version":"2"} === 'undefined' ? {} : {"version":"1.0.1","name":"EGL","type":"konnector","language":"node","icon":"icon.png","slug":"eglgrandlyon","source":"https://forge.grandlyon.com/web-et-numerique/llle_project/egl-konnector.git","editor":"Métropole de Lyon","vendor_link":"www.grandlyon.com","frequency":"daily","categories":["energy"],"fields":{"login":{"type":"text"},"password":{"type":"password"},"advancedFields":{"folderPath":{"advanced":true,"isRequired":false}}},"data_types":[],"screenshots":[],"permissions":{"egl data":{"type":"com.grandlyon.egl.*"},"accounts":{"type":"io.cozy.accounts","verbs":["GET"]}},"developer":{"name":"Métropole de Lyon","url":"https://grandlyon.com"},"langs":["fr"],"locales":{"fr":{"short_description":"Courbe de charge depuis l'API eau du Grand Lyon","long_description":"Ce connecteur récupère la courbe de charge enregistrée par le compteur Téléo","permissions":{"egl data":{"description":"Requises pour accéder et stocker les données collectées par le compteur Téléo et exposées par les API Eau du Grand Lyon (consommations d’eau au jour, mois et année)."},"accounts":{"description":"Utilisé pour accéder à vos données de consommation."}}},"en":{"short_description":"Water consumption data fetched from \"Eau du Grand Lyon\" API","long_description":"This konnector fetches the data curve gathered by Téléo device.","permissions":{"egl data":{"description":"Required to access and store the data collected by the Téléo meter and exposed by Eau du Grand Lyon APIs (daily, monthly and yearly consumption)."},"accounts":{"description":"Used to access your consumption data."}}}},"manifest_version":"2"};
+let manifest = typeof {"version":"1.0.3","name":"EGL","type":"konnector","language":"node","icon":"icon.png","slug":"eglgrandlyon","source":"https://forge.grandlyon.com/web-et-numerique/llle_project/egl-konnector.git","editor":"Métropole de Lyon","vendor_link":"www.grandlyon.com","frequency":"daily","categories":["energy"],"fields":{"login":{"type":"text"},"password":{"type":"password"},"advancedFields":{"folderPath":{"advanced":true,"isRequired":false}}},"data_types":[],"screenshots":[],"permissions":{"egl data":{"type":"com.grandlyon.egl.*"},"accounts":{"type":"io.cozy.accounts","verbs":["GET"]}},"developer":{"name":"Métropole de Lyon","url":"https://grandlyon.com"},"langs":["fr"],"locales":{"fr":{"short_description":"Courbe de charge depuis l'API eau du Grand Lyon","long_description":"Ce connecteur récupère la courbe de charge enregistrée par le compteur Téléo","permissions":{"egl data":{"description":"Requises pour accéder et stocker les données collectées par le compteur Téléo et exposées par les API Eau du Grand Lyon (consommations d’eau au jour, mois et année)."},"accounts":{"description":"Utilisé pour accéder à vos données de consommation."}}},"en":{"short_description":"Water consumption data fetched from \"Eau du Grand Lyon\" API","long_description":"This konnector fetches the data curve gathered by Téléo device.","permissions":{"egl data":{"description":"Required to access and store the data collected by the Téléo meter and exposed by Eau du Grand Lyon APIs (daily, monthly and yearly consumption)."},"accounts":{"description":"Used to access your consumption data."}}}},"manifest_version":"2"} === 'undefined' ? {} : {"version":"1.0.3","name":"EGL","type":"konnector","language":"node","icon":"icon.png","slug":"eglgrandlyon","source":"https://forge.grandlyon.com/web-et-numerique/llle_project/egl-konnector.git","editor":"Métropole de Lyon","vendor_link":"www.grandlyon.com","frequency":"daily","categories":["energy"],"fields":{"login":{"type":"text"},"password":{"type":"password"},"advancedFields":{"folderPath":{"advanced":true,"isRequired":false}}},"data_types":[],"screenshots":[],"permissions":{"egl data":{"type":"com.grandlyon.egl.*"},"accounts":{"type":"io.cozy.accounts","verbs":["GET"]}},"developer":{"name":"Métropole de Lyon","url":"https://grandlyon.com"},"langs":["fr"],"locales":{"fr":{"short_description":"Courbe de charge depuis l'API eau du Grand Lyon","long_description":"Ce connecteur récupère la courbe de charge enregistrée par le compteur Téléo","permissions":{"egl data":{"description":"Requises pour accéder et stocker les données collectées par le compteur Téléo et exposées par les API Eau du Grand Lyon (consommations d’eau au jour, mois et année)."},"accounts":{"description":"Utilisé pour accéder à vos données de consommation."}}},"en":{"short_description":"Water consumption data fetched from \"Eau du Grand Lyon\" API","long_description":"This konnector fetches the data curve gathered by Téléo device.","permissions":{"egl data":{"description":"Required to access and store the data collected by the Téléo meter and exposed by Eau du Grand Lyon APIs (daily, monthly and yearly consumption)."},"accounts":{"description":"Used to access your consumption data."}}}},"manifest_version":"2"};
 
 if (false) {}
 
diff --git a/manifest.konnector b/manifest.konnector
index a4588cb..57c9815 100644
--- a/manifest.konnector
+++ b/manifest.konnector
@@ -1,5 +1,5 @@
 {
-  "version": "1.0.1",
+  "version": "1.0.3",
   "name": "EGL",
   "type": "konnector",
   "language": "node",
diff --git a/package.json b/package.json
index 3b71ce5..d2499de 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "egl",
-  "version": "1.0.1",
+  "version": "1.0.3",
   "description": "",
   "repository": {
     "type": "git",
@@ -39,7 +39,7 @@
     "travisDeployKey": "./bin/generate_travis_deploy_key"
   },
   "dependencies": {
-    "cozy-konnector-libs": "4.34.5",
+    "cozy-konnector-libs": "4.42.3",
     "moment": "^2.24.0",
     "moment-timezone": "^0.5.26"
   },
@@ -47,7 +47,8 @@
     "@types/moment-timezone": "^0.5.30",
     "copy-webpack-plugin": "6.1.1",
     "cozy-app-publish": "0.25.0",
-    "cozy-jobs-cli": "1.13.6",
+    "cozy-jobs-cli": "1.16.2",
+    "cozy-konnector-build": "1.2.2",
     "eslint": "5.16.0",
     "eslint-config-cozy-app": "1.6.0",
     "eslint-plugin-prettier": "3.0.1",
-- 
GitLab