Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • web-et-numerique/factory/llle_project/egl-konnector
1 result
Show changes
Commits on Source (14)
# You can override the included template(s) by including variable overrides
# SAST customization: https://docs.gitlab.com/ee/user/application_security/sast/#customizing-the-sast-settings
# Secret Detection customization: https://docs.gitlab.com/ee/user/application_security/secret_detection/#customizing-settings
# Dependency Scanning customization: https://docs.gitlab.com/ee/user/application_security/dependency_scanning/#customizing-the-dependency-scanning-settings
# Container Scanning customization: https://docs.gitlab.com/ee/user/application_security/container_scanning/#customizing-the-container-scanning-settings
# Note that environment variables can be set in several places
# See https://docs.gitlab.com/ee/ci/variables/#cicd-variable-precedence
default:
tags:
- build-push-to-registry
stages:
- test
- build
- deploy
- publish
sast:
stage: test
include:
- template: Security/SAST.gitlab-ci.yml
build-dev:
image: ${CI_DEPENDENCY_PROXY_DIRECT_GROUP_IMAGE_PREFIX}/node:16.14.2-alpine3.14
stage: build
before_script:
- apk add git
- apk add bash
script:
- yarn
- yarn build
- git config --global user.name build-token
- git config --global user.email "$GIT_USER"
- git config --global user.password "$GIT_PWD"
- git config user.email "$GIT_USER"
- git remote set-url origin https://"$GIT_USER":"$GIT_PWD"@forge.grandlyon.com/web-et-numerique/factory/llle_project/egl-konnector.git
- git config --global credential.helper store
- yarn deploy-dev
build:
image: ${CI_DEPENDENCY_PROXY_DIRECT_GROUP_IMAGE_PREFIX}/node:16.14.2-alpine3.14
stage: build
before_script:
- apk add git
- apk add bash
script:
- yarn
- yarn build
- git config --global user.name build-token
- git config --global user.email "$GIT_USER"
- git config --global user.password "$GIT_PWD"
- git config user.email "$GIT_USER"
- git remote set-url origin https://"$GIT_USER":"$GIT_PWD"@forge.grandlyon.com/web-et-numerique/factory/llle_project/egl-konnector.git
- git config --global credential.helper store
- yarn deploy
only:
- main
deploy_dev:
stage: deploy
tags:
- deploy-alpha
script:
- cd /root/ecolyo-infra-scripts/cicid_scripts
- './update_egl_dev.sh'
environment:
name: dev
url: https://dev.cozy.self-data.alpha.grandlyon.com/
when: manual
deploy_demo:
stage: deploy
tags:
- deploy-alpha
script:
- cd /root/ecolyo-infra-scripts/cicid_scripts
- './update_all_egl_dev.sh'
only:
- master
environment:
name: ecolyodemo
url: https://ecolyodemo.cozy.self-data.alpha.grandlyon.com/
publish:
stage: publish
before_script:
- apk add git
script:
- yarn cozyPublish
only:
- tags
when: manual
[[_TOC_]]
## Contexte
## Objectif
## Ressources
## Tâches
\ No newline at end of file
{
"endOfLine": "auto",
"semi": false,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "es5",
"arrowParens": "avoid"
}
{
"editor.codeActionsOnSave": {
"source.fixAll": true,
"source.organizeImports": true
},
"editor.tabSize": 2,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"cSpell.words": [
"Abonnement",
"acces",
"Agregat",
"Agregats",
"apikey",
"arret",
"Arret",
"backoffice",
"Corrigees",
"cozyclient",
"criteres",
"Derniere",
"Detaillees",
"enedissgegrandlyon",
"Etage",
"etat",
"faultstring",
"firstname",
"Generales",
"grandlyon",
"HISTO",
"insee",
"konnector",
"konnectors",
"lastname",
"maxpower",
"numero",
"Perimetre",
"periodicite",
"PMAX",
"Recurrente",
"Releve",
"resultat",
"Retour",
"soapenv",
"Valeur"
]
}
# Changelog
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
## 1.1.0 (2023-01-05)
### Features
* add protections against EGL bad sorted data + clean code ([ae9d1bd](https://forge.grandlyon.com/web-et-numerique/llle_project/egl-konnector/commit/ae9d1bd9efb20c61dfdb4fa73ecc6605d642e530))
* sentry logging ([6d20cd3](https://forge.grandlyon.com/web-et-numerique/llle_project/egl-konnector/commit/6d20cd3f397a902582ae83cb86043a21c9b40a4f))
### Bug Fixes
* **auth:** issue on bad credentials ([01d28e4](https://forge.grandlyon.com/web-et-numerique/llle_project/egl-konnector/commit/01d28e44d1219af01ec8a5ef97e6152c9296e1d9))
......@@ -11,7 +11,7 @@ What's Cozy?
What is this konnector about ?
------------------------------
This konnector retrieves your daily water consumption from the Eau du Grand Lyon API.
This konnector retrieves your daily water consumption from the "Eau Publique du Grand Lyon" API.
### Open a Pull-Request
......
{
"COZY_URL": "http://cozy.tools:8080/",
"fields": {
"eglBaseURL": "",
"eglAPIAuthKey": "",
"login": 1234567,
"password": ""
}
}
{
"version": "1.0.4",
"version": "1.1.0",
"name": "EGL",
"type": "konnector",
"language": "node",
......@@ -42,11 +42,11 @@
"langs": ["fr"],
"locales": {
"fr": {
"short_description": "Courbe de charge depuis l'API eau du Grand Lyon",
"short_description": "Courbe de charge depuis l'API Eau Publique 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)."
"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 Publique du Grand Lyon (consommations d’eau au jour, mois et année)."
},
"accounts": {
"description": "Utilisé pour accéder à vos données de consommation."
......@@ -54,11 +54,11 @@
}
},
"en": {
"short_description": "Water consumption data fetched from \"Eau du Grand Lyon\" API",
"short_description": "Water consumption data fetched from \"Eau Publique 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)."
"description": "Required to access and store the data collected by the Téléo meter and exposed by Eau Publique du Grand Lyon APIs (daily, monthly and yearly consumption)."
},
"accounts": {
"description": "Used to access your consumption data."
......
{
"name": "egl",
"version": "1.0.3",
"version": "1.1.0",
"description": "",
"repository": {
"type": "git",
......@@ -33,30 +33,34 @@
"clean": "rm -rf ./data",
"build": "webpack",
"lint": "eslint --fix .",
"deploy": "git-directory-deploy --directory build/ --branch ${DEPLOY_BRANCH:-build} --repo=${DEPLOY_REPOSITORY:-https://forge.grandlyon.com/web-et-numerique/llle_project/egl-konnector.git}",
"deploy-dev": "git-directory-deploy --directory build/ --branch ${DEPLOY_BRANCH:-build-dev} --repo=${DEPLOY_REPOSITORY:-https://forge.grandlyon.com/web-et-numerique/llle_project/egl-konnector.git}",
"deploy": "git-directory-deploy --directory build/ --branch ${DEPLOY_BRANCH:-build}",
"deploy-dev": "git-directory-deploy --directory build/ --branch ${DEPLOY_BRANCH:-build-dev}",
"cozyPublish": "cozy-app-publish --token $REGISTRY_TOKEN --build-commit $(git rev-parse ${DEPLOY_BRANCH:-build})",
"travisDeployKey": "./bin/generate_travis_deploy_key"
},
"dependencies": {
"cozy-konnector-libs": "4.42.3",
"@sentry/node": "7.30.0",
"@sentry/tracing": "7.30.0",
"cozy-konnector-libs": "4.56.4",
"moment": "^2.24.0",
"moment-timezone": "^0.5.26"
"moment-timezone": "^0.5.26",
"axios": "1.2.2"
},
"devDependencies": {
"@types/moment-timezone": "^0.5.30",
"copy-webpack-plugin": "6.1.1",
"cozy-app-publish": "0.25.0",
"cozy-jobs-cli": "1.16.2",
"cozy-konnector-build": "1.2.2",
"cozy-jobs-cli": "1.20.2",
"cozy-konnector-build": "1.4.4",
"eslint": "5.16.0",
"eslint-config-cozy-app": "1.6.0",
"eslint-plugin-prettier": "3.0.1",
"git-directory-deploy": "1.5.1",
"husky": "4.3.0",
"konitor": "0.10.2",
"standard-version": "^9.5.0",
"svgo": "1.3.2",
"webpack": "4.44.2",
"webpack-cli": "3.3.12"
"webpack": "5.75.0",
"webpack-cli": "5.0.1"
}
}
function isLocal() {
return (
process.env.NODE_ENV === 'development' ||
process.env.NODE_ENV === 'local' ||
process.env.NODE_ENV === 'standalone'
)
}
/**
* Verify if it's an alpha URL
* @returns {boolean}
*/
function isDev() {
return (
process.env.COZY_URL.includes('alpha') ||
process.env.COZY_URL.includes('cozy.tools')
)
}
module.exports = { isLocal, isDev }
......@@ -4,81 +4,117 @@ const {
errors,
addData,
hydrateAndFilter,
cozyClient
} = require("cozy-konnector-libs");
cozyClient,
} = require('cozy-konnector-libs')
// const fetch = require('node-fetch')
const rp = require("request-promise");
const moment = require("moment");
require("moment-timezone");
const axios = require('axios').default
const moment = require('moment')
require('moment-timezone')
moment.locale("fr"); // set the language
moment.tz.setDefault("Europe/Paris"); // set the timezone
moment.locale('fr') // set the language
moment.tz.setDefault('Europe/Paris') // set the timezone
const Sentry = require('@sentry/node')
// eslint-disable-next-line
const Tracing = require('@sentry/tracing') // Needed for tracking performance in Sentry
const { version } = require('../package.json')
const { isDev } = require('./helpers/env')
const manualExecution =
process.env.COZY_JOB_MANUAL_EXECUTION === "true" ? true : false;
process.env.COZY_JOB_MANUAL_EXECUTION === 'true' ? true : false
const startDate = manualExecution
? moment()
.subtract(1, "year")
.format("MM/DD/YYYY")
.subtract(1, 'year')
.format('MM/DD/YYYY')
: moment()
.subtract(3, "year")
.format("MM/DD/YYYY");
.subtract(3, 'year')
.format('MM/DD/YYYY')
const endDate = moment().format("MM/DD/YYYY");
// const timeRange = ['day', 'month', 'year']
const endDate = moment().format('MM/DD/YYYY')
const rangeDate = {
day: {
doctype: "com.grandlyon.egl.day",
keys: ["year", "month", "day"]
doctype: 'com.grandlyon.egl.day',
keys: ['year', 'month', 'day'],
},
month: {
doctype: "com.grandlyon.egl.month",
keys: ["year", "month"]
doctype: 'com.grandlyon.egl.month',
keys: ['year', 'month'],
},
year: {
doctype: "com.grandlyon.egl.year",
keys: ["year"]
}
};
doctype: 'com.grandlyon.egl.year',
keys: ['year'],
},
}
module.exports = new BaseKonnector(start)
/**
* Sentry
*/
Sentry.init({
dsn:
'https://3f97baf46c2b44c2bd9e0c371abe3e05@grandlyon.errors.cozycloud.cc/2',
module.exports = new BaseKonnector(start);
// Set tracesSampleRate to 1.0 to capture 100%
// of transactions for performance monitoring.
// We recommend adjusting this value in production
tracesSampleRate: 1.0,
release: version,
environment: isDev() ? 'development' : 'production',
debug: isDev(),
integrations: [
// enable HTTP calls tracing
new Sentry.Integrations.Http({ tracing: true }),
],
})
// The start function is run by the BaseKonnector instance only when it got all the account
// information (fields). When you run this connector yourself in "standalone" mode or "dev" mode,
// information (fields). When you run this connector yourself in 'standalone' mode or 'dev' mode,
// the account information come from ./konnector-dev-config.json file
async function start(fields, cozyParameters) {
const transaction = Sentry.startTransaction({
op: 'konnector',
name: 'EGL Konnector',
})
transaction.startChild({ op: 'Konnector starting' })
try {
// Local debug data
// const baseUrl = fields.eglBaseURL
// const apiAuthKey = fields.eglAPIAuthKey
const baseUrl = cozyParameters.secret.eglBaseURL;
const apiAuthKey = cozyParameters.secret.eglAPIAuthKey;
log("info", "Authenticating ...");
const baseUrl = cozyParameters.secret.eglBaseURL
const apiAuthKey = cozyParameters.secret.eglAPIAuthKey
log('info', 'Authenticating ...')
const response = await authenticate(
fields.login,
fields.password,
baseUrl,
apiAuthKey
);
log("info", "Successfully logged in");
)
log('info', 'Successfully logged in')
const eglData = await getData(response, baseUrl, apiAuthKey);
const eglData = await getData(response, baseUrl, apiAuthKey)
if (eglData) {
log("debug", "Process egl daily data");
log('debug', 'Process egl daily data')
const processedLoadData = await processData(
eglData,
rangeDate.day.doctype,
rangeDate.day.keys
);
log("debug", "Agregate egl load data for month and year");
await agregateMonthAndYearData(processedLoadData);
)
log('debug', 'Aggregate egl load data for month and year')
await aggregateMonthAndYearData(processedLoadData)
} else {
log("debug", "No data found");
log('debug', 'No data found')
}
transaction.setStatus(Tracing.SpanStatus.Ok)
transaction.finish()
} catch (error) {
throw new Error(error.message);
log('error', error)
Sentry.captureException(error)
transaction.setStatus(Tracing.SpanStatus.Aborted)
transaction.finish()
await Sentry.flush()
throw error
}
}
......@@ -89,217 +125,217 @@ async function start(fields, cozyParameters) {
* Return the list of filtered data
*/
async function processData(data, doctype, filterKeys) {
// const formatedData = await formateData(data)
log("debug", "processData - data formated");
log('debug', 'processData - data formatted')
// Remove data for existing days into the DB
const filteredData = await hydrateAndFilter(data, doctype, {
keys: filterKeys
});
log("debug", "processData - data filtered");
keys: filterKeys,
})
log('debug', 'processData - data filtered')
// Store new day data
await storeData(filteredData, doctype, filterKeys);
return filteredData;
await storeData(filteredData, doctype, filterKeys)
return filteredData
}
/**
* Agregate data from daily data to monthly and yearly data
* Aggregate data from daily data to monthly and yearly data
*/
async function agregateMonthAndYearData(data) {
async function aggregateMonthAndYearData(data) {
// Sum year and month values into object with year or year-month as keys
if (data && data.length !== 0) {
let monthData = {};
let yearData = {};
let monthData = {}
let yearData = {}
data.forEach(element => {
element.year + "-" + element.month in monthData
? (monthData[element.year + "-" + element.month] += element.load)
: (monthData[element.year + "-" + element.month] = element.load);
element.year in yearData
? (yearData[element.year] += element.load)
: (yearData[element.year] = element.load);
});
// Agregation for Month data
const agregatedMonthData = await buildAgregatedData(
const monthDataKey = element.year + '-' + element.month
if (monthDataKey in monthData) {
monthData[monthDataKey] += element.load
} else {
monthData[monthDataKey] = element.load
}
const yearDataKey = element.year
if (yearDataKey in yearData) {
yearData[yearDataKey] += element.load
} else {
yearData[yearDataKey] = element.load
}
})
// Aggregation for Month data
const aggregatedMonthData = await buildAggregatedData(
monthData,
"com.grandlyon.egl.month"
);
await storeData(agregatedMonthData, "com.grandlyon.egl.month", [
"year",
"month"
]);
// Agregation for Year data
const agregatedYearData = await buildAgregatedData(
'com.grandlyon.egl.month'
)
await storeData(aggregatedMonthData, 'com.grandlyon.egl.month', [
'year',
'month',
])
// Aggregation for Year data
const aggregatedYearData = await buildAggregatedData(
yearData,
"com.grandlyon.egl.year"
);
await storeData(agregatedYearData, "com.grandlyon.egl.year", ["year"]);
'com.grandlyon.egl.year'
)
await storeData(aggregatedYearData, 'com.grandlyon.egl.year', ['year'])
}
}
/**
* Retrieve and remove old data for a specific doctype
* Return an Array of agregated data
* Return an Array of aggregated data
*/
async function buildAgregatedData(data, doctype) {
log("info", "entering buildAgregatedData");
let agregatedData = [];
async function buildAggregatedData(data, doctype) {
log('info', 'entering buildAggregatedData')
let aggregatedData = []
for (let [key, value] of Object.entries(data)) {
const data = await buildDataFromKey(doctype, key, value);
const oldValue = await resetInProgressAggregatedData(data, doctype);
log("info", "Dataload + oldvalue is " + data.load + " + " + oldValue);
data.load += oldValue;
agregatedData.push(data);
const data = await buildDataFromKey(doctype, key, value)
const oldValue = await resetInProgressAggregatedData(data, doctype)
log('info', 'Data load + old value is ' + data.load + ' + ' + oldValue)
data.load += oldValue
aggregatedData.push(data)
}
return agregatedData;
return aggregatedData
}
async function authenticate(login, password, baseUrl, apiAuthKey) {
const authRequest = {
method: "POST",
uri: baseUrl + "/connect.aspx",
method: 'post',
url: baseUrl + '/connect.aspx',
headers: {
AuthKey: apiAuthKey,
"Content-Type": "application/x-www-form-urlencoded"
'Content-Type': 'application/x-www-form-urlencoded',
},
formData: {
data: {
login: login,
pass: password
pass: password,
},
json: true
};
let response = {}
try {
response = await rp(authRequest);
} catch(e) {
log("error", e)
}
if (response.codeRetour === 100) {
return response;
} else {
throw new Error(errors.LOGIN_FAILED);
try {
const resp = await axios(authRequest)
if (resp.data.codeRetour === 100) {
return resp.data
} else {
Sentry.captureException(JSON.stringify(resp.data))
throw new Error()
}
} catch (error) {
throw new Error(errors.LOGIN_FAILED)
}
}
async function getData(response, baseUrl, apiAuthKey) {
log("debug", "Start date : " + startDate);
log("debug", "End date : " + endDate);
log('debug', 'Start date : ' + startDate)
log('debug', 'End date : ' + endDate)
const dataRequest = {
method: "POST",
uri: baseUrl + "/getAllAgregatsByAbonnement.aspx",
method: 'post',
url: baseUrl + '/getAllAgregatsByAbonnement.aspx',
headers: {
AuthKey: apiAuthKey,
"Content-Type": "application/x-www-form-urlencoded"
'Content-Type': 'application/x-www-form-urlencoded',
},
form: {
data: {
token: response.resultatRetour.token,
num_abt: response.resultatRetour.num_abt,
date_debut: startDate,
date_fin: endDate
date_fin: endDate,
},
json: true
};
}
try {
// Sort data by date
const resp = await axios(dataRequest)
resp.data.resultatRetour.sort(function(a, b) {
return new Date(a.DateReleve) - new Date(b.DateReleve)
})
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) {
switch (resp.data.codeRetour) {
case 100:
return format(responseEgl);
return format(resp.data)
case -2:
throw errors.LOGIN_FAILED;
throw errors.LOGIN_FAILED
case -1:
throw errors.VENDOR_DOWN;
throw errors.VENDOR_DOWN
default:
throw errors.UNKNOWN_ERROR;
throw errors.UNKNOWN_ERROR
}
} catch (error) {
log("debug", "Error from getAllAgregatsByAbonnement");
throw new Error(errors.VENDOR_DOWN);
log('debug', 'Error from getAllAgregatsByAbonnement')
throw new Error(errors.VENDOR_DOWN)
}
}
function format(response) {
log("info", "origin response size is : " + response.resultatRetour.length);
log('info', 'origin response size is : ' + response.resultatRetour.length)
// Store first value as reference for index processing
let refValue = response.resultatRetour[0];
let refValue = response.resultatRetour[0]
// Create copy of data without first value
const data = response.resultatRetour
.slice(1)
.filter(value => value.ValeurIndex);
log("info", "filtered size is : " + data.length);
.filter(value => value.ValeurIndex)
log('info', 'filtered size is : ' + data.length)
return data.map(value => {
const time = moment(value.DateReleve, moment.ISO_8601);
const procesedLoad = value.ValeurIndex - refValue.ValeurIndex;
if (procesedLoad < 0) {
const time = moment(value.DateReleve, moment.ISO_8601)
const processedLoad = value.ValeurIndex - refValue.ValeurIndex
if (processedLoad < 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;
'error',
`processing load for day ${parseInt(time.format('D'))}/${parseInt(
time.format('M')
)}/${parseInt(time.format('YYYY'))}, value is : ${processedLoad}`
)
throw errors.VENDOR_DOWN
}
// Change index ref value
refValue = value;
refValue = value
return {
load: procesedLoad,
year: parseInt(time.format("YYYY")),
month: parseInt(time.format("M")),
day: parseInt(time.format("D")),
load: processedLoad,
year: parseInt(time.format('YYYY')),
month: parseInt(time.format('M')),
day: parseInt(time.format('D')),
hour: 0,
minute: 0,
type: value.TypeAgregat
};
});
type: value.TypeAgregat,
}
})
}
/**
* Save data in the right doctype db and prevent duplicated keys
*/
async function storeData(data, doctype, filterKeys) {
log("debug", "Store into " + doctype);
log("debug", "Store into keys : " + filterKeys);
log('debug', 'Store into ' + doctype)
log('debug', 'Store into keys : ' + filterKeys)
// data.map(v => {
// log("info", "Saving data " + v.load + " for " + v.day + "/" + v.month + "/" + v.year);
// });
// log('info', 'Saving data ' + v.load + ' for ' + v.day + '/' + v.month + '/' + v.year)
// })
const filteredDocuments = await hydrateAndFilter(data, doctype, {
keys: filterKeys
});
return await addData(filteredDocuments, doctype);
keys: filterKeys,
})
return await addData(filteredDocuments, doctype)
}
/**
* Format an entry for DB storage
* using key and value
* For year doctype: key = "YYYY"
* For month doctype: key = "YYYY-MM"
* For year doctype: key = 'YYYY'
* For month doctype: key = 'YYYY-MM'
*/
async function buildDataFromKey(doctype, key, value) {
let year, month, day, hour;
if (doctype === "com.grandlyon.egl.year") {
year = key;
month = 1;
day = 0;
hour = 0;
} else if (doctype === "com.grandlyon.egl.month") {
const split = key.split("-");
year = split[0];
month = split[1];
day = 0;
hour = 0;
let year, month, day, hour
if (doctype === 'com.grandlyon.egl.year') {
year = key
month = 1
day = 0
hour = 0
} else if (doctype === 'com.grandlyon.egl.month') {
const split = key.split('-')
year = split[0]
month = split[1]
day = 0
hour = 0
} else {
const split = key.split("-");
year = split[0];
month = split[1];
day = split[2];
hour = split[3];
const split = key.split('-')
year = split[0]
month = split[1]
day = split[2]
hour = split[3]
}
return {
load: Math.round(value * 10000) / 10000,
......@@ -307,8 +343,8 @@ async function buildDataFromKey(doctype, key, value) {
month: parseInt(month),
day: parseInt(day),
hour: parseInt(hour),
minute: 0
};
minute: 0,
}
}
/**
......@@ -320,21 +356,21 @@ async function buildDataFromKey(doctype, key, value) {
*/
async function resetInProgressAggregatedData(data, doctype) {
// /!\ Warning: cannot use mongo queries because not supported for dev by cozy-konnectors-libs
log("debug", "Remove aggregated data for " + doctype);
const result = await cozyClient.data.findAll(doctype);
log('debug', 'Remove aggregated data for ' + doctype)
const result = await cozyClient.data.findAll(doctype)
if (result && result.length > 0) {
// Filter data to remove
var filtered = [];
if (doctype === "com.grandlyon.egl.year") {
let filtered = []
if (doctype === 'com.grandlyon.egl.year') {
// Yearly case
filtered = result.filter(function(el) {
return el.year == data.year;
});
} else if (doctype === "com.grandlyon.egl.month") {
return el.year == data.year
})
} else if (doctype === 'com.grandlyon.egl.month') {
// Monthly case
filtered = result.filter(function(el) {
return el.year == data.year && el.month == data.month;
});
return el.year == data.year && el.month == data.month
})
} else {
// Hourly case
filtered = result.filter(function(el) {
......@@ -343,17 +379,17 @@ async function resetInProgressAggregatedData(data, doctype) {
el.month == data.month &&
el.day == data.day &&
el.hour == data.hour
);
});
)
})
}
// Remove data
let sum = 0.0;
let sum = 0.0
for (const doc of filtered) {
sum += doc.load;
log("debug", "Removing this entry for " + doc.load);
await cozyClient.data.delete(doctype, doc);
sum += doc.load
log('debug', 'Removing this entry for ' + doc.load)
await cozyClient.data.delete(doctype, doc)
}
return sum;
return sum
}
return 0.0;
return 0.0
}
......@@ -12,9 +12,9 @@ const readManifest = () =>
const svgo = new SvgoInstance({
plugins: [
{
inlineStyles: { onlyMatchedOnce: false }
}
]
inlineStyles: { onlyMatchedOnce: false },
},
],
})
let iconName
......@@ -33,30 +33,30 @@ module.exports = {
mode: 'none',
output: {
path: path.join(__dirname, 'build'),
filename: 'index.js'
filename: 'index.js',
},
plugins: [
new CopyPlugin({
patterns: [
{ from: 'manifest.konnector' },
{ from: 'package.json' },
{ from: 'README.md' },
{ from: 'assets', transform: optimizeSVGIcon },
{ from: '.travis.yml' },
{ from: 'LICENSE' }
]
patterns: [
{ from: 'manifest.konnector' },
{ from: 'package.json' },
{ from: 'README.md' },
{ from: 'assets', transform: optimizeSVGIcon },
{ from: '.travis.yml' },
{ from: 'LICENSE' },
],
}),
new webpack.DefinePlugin({
__WEBPACK_PROVIDED_MANIFEST__: JSON.stringify(readManifest())
})
__WEBPACK_PROVIDED_MANIFEST__: JSON.stringify(readManifest()),
}),
],
module: {
// to ignore the warnings like :
// WARNING in ../libs/node_modules/bindings/bindings.js 76:22-40
// Critical dependency: the request of a dependency is an expression
// Since we cannot change this dependency. I think it won't hide more important messages
exprContextCritical: false
}
exprContextCritical: false,
},
}
function optimizeSVGIcon(buffer, path) {
......
This diff is collapsed.