diff --git a/.gitignore b/.gitignore index d8884e55e4e9fbb5a830821cc9d8ea13e23e1579..0be88ea4811a1014daf8a38bdacfc6872230fe6b 100644 --- a/.gitignore +++ b/.gitignore @@ -3,10 +3,12 @@ node_modules/ npm-debug.log yarn-error.log -scripts/* +# Scripts +scripts/AAAA* +scripts/config.js scripts/data/ -#Report +# Report public/report.html # Build diff --git a/scripts/config.template.js b/scripts/config.template.js new file mode 100644 index 0000000000000000000000000000000000000000..bf9b3f0e829110b68cfdf9f8eed33a1c11eaa227 --- /dev/null +++ b/scripts/config.template.js @@ -0,0 +1,16 @@ +/* eslint-disable @typescript-eslint/no-var-requires */ +const { DateTime } = require('luxon') + +const authorization = + 'Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' +const cookie = + 'cozysessid=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' + +const startingdate = DateTime.local() + .plus({ days: -120 }) + .startOf('day') +const endingDate = DateTime.local() + .plus({ days: -1 }) + .startOf('day') + +module.exports = { authorization, cookie, startingdate, endingDate } diff --git a/scripts/createConnections.js b/scripts/createConnections.js new file mode 100644 index 0000000000000000000000000000000000000000..6a582108f8a645bcf83e5c4d4cdb98c9f478a64f --- /dev/null +++ b/scripts/createConnections.js @@ -0,0 +1,219 @@ +/* eslint-disable @typescript-eslint/no-var-requires */ +/* eslint-disable @typescript-eslint/camelcase */ +const axios = require('axios') +const config = require('./config') + +const headers = { + Accept: 'application/json', + Authorization: config.authorization, + Cookie: config.cookie, + 'content-type': 'application/json', +} + +const dataEnedisAccount = JSON.stringify({ + account_type: 'enedisgrandlyon', + name: '', + oauth: { + access_token: '', + expires_at: '2020-10-09T08:00:00.285910671+02:00', + refresh_token: '', + token_type: 'Bearer', + }, + oauth_callback_results: { + issued_at: '1592232569642', + refresh_token_issued_at: '1592232569642', + scope: + '/v4/metering_data/production_load_curve.GET /v3/customers/usage_points/addresses.GET /v4/metering_data/consumption_load_curve.GET /v3/customers/usage_points/contracts.GET /v4/metering_data/daily_production.GET /v4/metering_data/daily_consumption.GET /v4/metering_data/daily_consumption_max_power.GET /v3/customers/identity.GET', + usage_points_id: '', + }, +}) + +const dataGrdfAccount = JSON.stringify({ + account_type: 'grdfgrandlyon', + auth: { + credentials_encrypted: + 'bmFjbMKrNCS+4Liakxdu+xNu9I3sSyvda8iAp0o3U3OAymbIeoLhLtxPdsa+3mu/8yTnDudBcJo=', + login: 'test', + }, + id: '89e68b8450cee09fe2f077610901094d', + identifier: 'login', + state: null, +}) + +const dataEglAccount = JSON.stringify({ + account_type: 'eglgrandlyon', + auth: { + credentials_encrypted: + 'bmFjbHI5OoL+VNCT6JDFYea1dNiBGGNJM1zY0M4uWcjhALJcQT9uk9p9WPD7+1OryCAoYf9eaSE=', + login: 'test', + }, + id: '90e68b8450cee09fe2f077610901094d', + identifier: 'login', + state: null, +}) + +const dataEnedisTrigger = JSON.stringify({ + data: { + attributes: { + _id: '3ed832cec67e6e0b2c6382edd30df11c', + domain: 'cozy.tools:8080', + prefix: 'cozy35ba44d2d1749e6f21646edce51e7190', + type: '@cron', + worker: 'konnector', + arguments: '0 47 8 * * *', + debounce: '', + options: null, + message: { + account: '88e68b8450cee09fe2f077610901094d', + konnector: 'enedisgrandlyon', + }, + cozyMetadata: { + doctypeVersion: '1', + metadataVersion: 1, + createdAt: '2020-10-09T08:00:00.6092798Z', + createdByApp: 'ecolyo', + updatedAt: '2020-10-09T08:00:00.6092798Z', + }, + }, + }, +}) + +const dataGrdfTrigger = JSON.stringify({ + data: { + attributes: { + _id: '4ed832cec67e6e0b2c6382edd30df11c', + domain: 'cozy.tools:8080', + prefix: 'cozy35ba44d2d1749e6f21646edce51e7190', + type: '@cron', + worker: 'konnector', + arguments: '0 47 8 * * *', + debounce: '', + options: null, + message: { + account: '89e68b8450cee09fe2f077610901094d', + konnector: 'grdfgrandlyon', + }, + cozyMetadata: { + doctypeVersion: '1', + metadataVersion: 1, + createdAt: '2020-10-09T08:00:00.6092798Z', + createdByApp: 'ecolyo', + updatedAt: '2020-10-09T08:00:00.6092798Z', + }, + }, + }, +}) + +const dataEglTrigger = JSON.stringify({ + data: { + attributes: { + _id: '5ed832cec67e6e0b2c6382edd30df11c', + domain: 'cozy.tools:8080', + prefix: 'cozy35ba44d2d1749e6f21646edce51e7190', + type: '@cron', + worker: 'konnector', + arguments: '0 47 8 * * *', + debounce: '', + options: null, + message: { + account: '90e68b8450cee09fe2f077610901094d', + konnector: 'eglgrandlyon', + }, + cozyMetadata: { + doctypeVersion: '1', + metadataVersion: 1, + createdAt: '2020-10-09T08:00:00.6092798Z', + createdByApp: 'ecolyo', + updatedAt: '2020-10-09T08:00:00.6092798Z', + }, + }, + }, +}) + +async function launch() { + // Enedis + await axios({ + method: 'put', + url: + 'http://cozy.tools:8080/data/io.cozy.accounts/88e68b8450cee09fe2f077610901094d', + headers: headers, + data: dataEnedisAccount, + }) + .then(function(response) { + console.log(JSON.stringify(response.data)) + }) + .catch(function(error) { + console.log(error) + }) + + await axios({ + method: 'post', + url: 'http://cozy.tools:8080/jobs/triggers', + headers: headers, + data: dataEnedisTrigger, + }) + .then(function(response) { + console.log(JSON.stringify(response.data)) + }) + .catch(function(error) { + console.log(error) + }) + + // GRDF + await axios({ + method: 'put', + url: + 'http://cozy.tools:8080/data/io.cozy.accounts/89e68b8450cee09fe2f077610901094d', + headers: headers, + data: dataGrdfAccount, + }) + .then(function(response) { + console.log(JSON.stringify(response.data)) + }) + .catch(function(error) { + console.log(error) + }) + + await axios({ + method: 'post', + url: 'http://cozy.tools:8080/jobs/triggers', + headers: headers, + data: dataGrdfTrigger, + }) + .then(function(response) { + console.log(JSON.stringify(response.data)) + }) + .catch(function(error) { + console.log(error) + }) + + // EGL + await axios({ + method: 'put', + url: + 'http://cozy.tools:8080/data/io.cozy.accounts/90e68b8450cee09fe2f077610901094d', + headers: headers, + data: dataEglAccount, + }) + .then(function(response) { + console.log(JSON.stringify(response.data)) + }) + .catch(function(error) { + console.log(error) + }) + + await axios({ + method: 'post', + url: 'http://cozy.tools:8080/jobs/triggers', + headers: headers, + data: dataEglTrigger, + }) + .then(function(response) { + console.log(JSON.stringify(response.data)) + }) + .catch(function(error) { + console.log(error) + }) +} + +launch() diff --git a/scripts/createDayDataFiles.js b/scripts/createDayDataFiles.js new file mode 100644 index 0000000000000000000000000000000000000000..f1b98f8e3467cd3964fdc83e3a7106f3c711b01d --- /dev/null +++ b/scripts/createDayDataFiles.js @@ -0,0 +1,160 @@ +/* eslint-disable @typescript-eslint/no-var-requires */ +/* + * Create dummy data files for each fluid. + * Hourly data is not generated + */ +const fs = require('fs') +const { DateTime } = require('luxon') +const config = require('./config') + +function getRandomInt(min, max) { + const minValue = Math.ceil(min * 100) + const maxValue = Math.floor(max * 100) + // NOSONAR + const result = + (Math.floor(Math.random() * (maxValue - minValue)) + minValue) / 100 + return result +} + +const generateData = (_startingdate, _endingDate, min, max) => { + let parsingDate = DateTime.local( + _startingdate.year, + _startingdate.month, + _startingdate.day + ) + + const dayDumpArray = [] + + let lastMonth = parsingDate.month + const monthDumpArray = [] + + let lastYear = parsingDate.year + const yearDumpArray = [] + + let monthlyLoad = 0 + let yearlyLoad = 0 + + while (parsingDate <= _endingDate) { + const load = getRandomInt(min, max) + + monthlyLoad += load + yearlyLoad += load + + dayDumpArray.push({ + load: load, + year: parsingDate.year, + month: parsingDate.month, + day: parsingDate.day, + hour: 0, + minute: 0, + }) + + if (parsingDate.month !== lastMonth) { + monthDumpArray.push({ + load: Math.round(monthlyLoad * 100) / 100, + year: lastYear, + month: lastMonth, + day: 0, + hour: 0, + minute: 0, + }) + monthlyLoad = 0 + lastMonth = parsingDate.month + } + + if (parsingDate.year !== lastYear) { + yearDumpArray.push({ + load: Math.round(yearlyLoad * 100) / 100, + year: lastYear, + month: 1, + day: 1, + hour: 0, + minute: 0, + }) + yearlyLoad = 0 + lastYear = parsingDate.year + } + parsingDate = parsingDate.plus({ days: 1 }) + } + + monthDumpArray.push({ + load: Math.round(monthlyLoad * 100) / 100, + year: lastYear, + month: lastMonth, + day: 1, + hour: 0, + minute: 0, + }) + + yearDumpArray.push({ + load: Math.round(yearlyLoad * 100) / 100, + year: lastYear, + month: 1, + day: 1, + hour: 0, + minute: 0, + }) + + return { + dailyLoad: dayDumpArray, + monthlyLoad: monthDumpArray, + yearlyLoad: yearDumpArray, + } +} + +const startingdate = config.startingdate +const endingDate = config.endingDate + +const Elec = generateData(startingdate, endingDate, 3, 10) +const Gaz = generateData(startingdate, endingDate, 16, 68) +const Eau = generateData(startingdate, endingDate, 200, 300) + +const dumpElec = { + 'com.grandlyon.enedis.day': Elec.dailyLoad, + 'com.grandlyon.enedis.month': Elec.monthlyLoad, + 'com.grandlyon.enedis.year': Elec.yearlyLoad, +} +const dumpStringElec = JSON.stringify(dumpElec) +fs.writeFile('data/dayData-elec.json', dumpStringElec, function(err) { + if (err) console.log('error', err) +}) + +const dumpGas = { + 'com.grandlyon.grdf.day': Gaz.dailyLoad, + 'com.grandlyon.grdf.month': Gaz.monthlyLoad, + 'com.grandlyon.grdf.year': Gaz.yearlyLoad, +} +const dumpStringGas = JSON.stringify(dumpGas) +fs.writeFile('data/dayData-gas.json', dumpStringGas, function(err) { + if (err) console.log('error', err) +}) + +const dumpWater = { + 'com.grandlyon.egl.day': Eau.dailyLoad, + 'com.grandlyon.egl.month': Eau.monthlyLoad, + 'com.grandlyon.egl.year': Eau.yearlyLoad, +} +const dumpStringWater = JSON.stringify(dumpWater) +fs.writeFile('data/dayData-water.json', dumpStringWater, function(err) { + if (err) console.log('error', err) +}) + +const dump = { + 'com.grandlyon.enedis.day': Elec.dailyLoad, + 'com.grandlyon.enedis.month': Elec.monthlyLoad, + 'com.grandlyon.enedis.year': Elec.yearlyLoad, + + 'com.grandlyon.grdf.day': Gaz.dailyLoad, + 'com.grandlyon.grdf.month': Gaz.monthlyLoad, + 'com.grandlyon.grdf.year': Gaz.yearlyLoad, + + 'com.grandlyon.egl.day': Eau.dailyLoad, + 'com.grandlyon.egl.month': Eau.monthlyLoad, + 'com.grandlyon.egl.year': Eau.yearlyLoad, +} + +const dumpString = JSON.stringify(dump) + +fs.writeFile('data/dayData.json', dumpString, function(err) { + if (err) console.log('error', err) +}) diff --git a/scripts/importData.bat b/scripts/importData.bat new file mode 100644 index 0000000000000000000000000000000000000000..7e88f9f12e8fc6799a5429e6c30f413bfb01c012 --- /dev/null +++ b/scripts/importData.bat @@ -0,0 +1,4 @@ +@echo off +echo Please provide cozysessid (can be found after connection in browser dev tool) +set /p token="CozySessid ? : " +ACH -t %token% import ./data/dayData.json