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/ecolyo
1 result
Show changes
Commits on Source (3)
...@@ -201,7 +201,7 @@ update-dev: ...@@ -201,7 +201,7 @@ update-dev:
- merge_requests - merge_requests
environment: environment:
name: dev name: dev
url: https://ecolyo.dev.cozy.self-data.alpha.grandlyon.com/ url: https://dev-ecolyo.cozy.self-data.alpha.grandlyon.com/
needs: needs:
- deploy-dev - deploy-dev
...@@ -228,7 +228,7 @@ update-demo: ...@@ -228,7 +228,7 @@ update-demo:
- dev - dev
environment: environment:
name: ecolyodemo name: ecolyodemo
url: https://ecolyo.ecolyodemo.cozy.self-data.alpha.grandlyon.com/ url: https://ecolyodemo-dev.cozy.self-data.alpha.grandlyon.com/
needs: needs:
- deploy-test - deploy-test
......
...@@ -25,7 +25,12 @@ ...@@ -25,7 +25,12 @@
"test": "cs test --verbose --coverage", "test": "cs test --verbose --coverage",
"tx": "tx pull --all || true", "tx": "tx pull --all || true",
"watch": "yarn watch:browser", "watch": "yarn watch:browser",
"watch:browser": "cs watch --browser" "watch:browser": "cs watch --browser",
"clean": "rm -rf ./data",
"data:create": "npx tsx scripts/createDayDataFiles.ts",
"data:import": "./scripts/importData.sh",
"data:seed": "yarn data:create && yarn data:import",
"data:connections": "npx tsx scripts/createConnections.ts"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
......
/* eslint-disable camelcase */ /* eslint-disable camelcase */
const axios = require('axios') import axios from 'axios'
const config = require('./config') import { Account, Trigger } from 'models'
import config from './config'
const headers = { const headers = {
Accept: 'application/json', Accept: 'application/json',
...@@ -12,7 +13,7 @@ const headers = { ...@@ -12,7 +13,7 @@ const headers = {
const COZY_PREFIX = 'cozy35ba44d2d1749e6f21646edce51e7190' const COZY_PREFIX = 'cozy35ba44d2d1749e6f21646edce51e7190'
const ENEDIS_ACCOUNT_ID = '70e68b8450cee09fe2f077610901094d' const ENEDIS_ACCOUNT_ID = '70e68b8450cee09fe2f077610901094d'
const dataEnedisAccount = JSON.stringify({ const ENEDIS_ACCOUNT: Partial<Account> = {
id: ENEDIS_ACCOUNT_ID, id: ENEDIS_ACCOUNT_ID,
account_type: 'enedissgegrandlyon', account_type: 'enedissgegrandlyon',
name: '', name: '',
...@@ -31,10 +32,11 @@ const dataEnedisAccount = JSON.stringify({ ...@@ -31,10 +32,11 @@ const dataEnedisAccount = JSON.stringify({
}, },
identifier: 'address', identifier: 'address',
state: null, state: null,
}) }
const dataEnedisAccount = JSON.stringify(ENEDIS_ACCOUNT)
const GRDF_ACCOUNT_ID = '89e68b8450cee09fe2f077610901094d' const GRDF_ACCOUNT_ID = '89e68b8450cee09fe2f077610901094d'
const dataGrdfAccount = JSON.stringify({ const GRDF_ACCOUNT: Partial<Account> = {
id: GRDF_ACCOUNT_ID, id: GRDF_ACCOUNT_ID,
account_type: 'grdfgrandlyon', account_type: 'grdfgrandlyon',
auth: { auth: {
...@@ -44,10 +46,11 @@ const dataGrdfAccount = JSON.stringify({ ...@@ -44,10 +46,11 @@ const dataGrdfAccount = JSON.stringify({
}, },
identifier: 'login', identifier: 'login',
state: null, state: null,
}) }
const dataGrdfAccount = JSON.stringify(GRDF_ACCOUNT)
const EGL_ACCOUNT_ID = '90e68b8450cee09fe2f077610901094d' const EGL_ACCOUNT_ID = '90e68b8450cee09fe2f077610901094d'
const dataEglAccount = JSON.stringify({ const EGL_ACCOUNT: Partial<Account> = {
id: EGL_ACCOUNT_ID, id: EGL_ACCOUNT_ID,
account_type: 'eglgrandlyon', account_type: 'eglgrandlyon',
auth: { auth: {
...@@ -57,83 +60,87 @@ const dataEglAccount = JSON.stringify({ ...@@ -57,83 +60,87 @@ const dataEglAccount = JSON.stringify({
}, },
identifier: 'login', identifier: 'login',
state: null, state: null,
}) }
const dataEglAccount = JSON.stringify(EGL_ACCOUNT)
const ENEDIS_TRIGGER: Trigger = {
_id: '3ed832cec67e6e0b2c6382edd30df11c',
domain: 'cozy.tools:8080',
prefix: COZY_PREFIX,
type: '@cron',
worker: 'konnector',
arguments: '0 47 8 * * *',
debounce: '',
options: null,
message: {
account: ENEDIS_ACCOUNT_ID,
konnector: 'enedissgegrandlyon',
},
cozyMetadata: {
doctypeVersion: '1',
metadataVersion: 1,
createdAt: '2020-10-09T08:00:00.6092798Z',
createdByApp: 'ecolyo',
updatedAt: '2020-10-09T08:00:00.6092798Z',
},
}
const dataEnedisTrigger = JSON.stringify({ const dataEnedisTrigger = JSON.stringify({
data: { data: {
attributes: { attributes: ENEDIS_TRIGGER,
_id: '3ed832cec67e6e0b2c6382edd30df11c',
domain: 'cozy.tools:8080',
prefix: COZY_PREFIX,
type: '@cron',
worker: 'konnector',
arguments: '0 47 8 * * *',
debounce: '',
options: null,
message: {
account: ENEDIS_ACCOUNT_ID,
konnector: 'enedissgegrandlyon',
},
cozyMetadata: {
doctypeVersion: '1',
metadataVersion: 1,
createdAt: '2020-10-09T08:00:00.6092798Z',
createdByApp: 'ecolyo',
updatedAt: '2020-10-09T08:00:00.6092798Z',
},
},
}, },
}) })
const GRDF_TRIGGER: Trigger = {
_id: '4ed832cec67e6e0b2c6382edd30df11c',
domain: 'cozy.tools:8080',
prefix: COZY_PREFIX,
type: '@cron',
worker: 'konnector',
arguments: '0 47 8 * * *',
debounce: '',
options: null,
message: {
account: GRDF_ACCOUNT_ID,
konnector: 'grdfgrandlyon',
},
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({ const dataGrdfTrigger = JSON.stringify({
data: { data: {
attributes: { attributes: GRDF_TRIGGER,
_id: '4ed832cec67e6e0b2c6382edd30df11c',
domain: 'cozy.tools:8080',
prefix: COZY_PREFIX,
type: '@cron',
worker: 'konnector',
arguments: '0 47 8 * * *',
debounce: '',
options: null,
message: {
account: GRDF_ACCOUNT_ID,
konnector: 'grdfgrandlyon',
},
cozyMetadata: {
doctypeVersion: '1',
metadataVersion: 1,
createdAt: '2020-10-09T08:00:00.6092798Z',
createdByApp: 'ecolyo',
updatedAt: '2020-10-09T08:00:00.6092798Z',
},
},
}, },
}) })
const EGL_TRIGGER: Trigger = {
_id: '5ed832cec67e6e0b2c6382edd30df11c',
domain: 'cozy.tools:8080',
prefix: COZY_PREFIX,
type: '@cron',
worker: 'konnector',
arguments: '0 47 8 * * *',
debounce: '',
options: null,
message: {
account: EGL_ACCOUNT_ID,
konnector: 'eglgrandlyon',
},
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({ const dataEglTrigger = JSON.stringify({
data: { data: {
attributes: { attributes: EGL_TRIGGER,
_id: '5ed832cec67e6e0b2c6382edd30df11c',
domain: 'cozy.tools:8080',
prefix: COZY_PREFIX,
type: '@cron',
worker: 'konnector',
arguments: '0 47 8 * * *',
debounce: '',
options: null,
message: {
account: EGL_ACCOUNT_ID,
konnector: 'eglgrandlyon',
},
cozyMetadata: {
doctypeVersion: '1',
metadataVersion: 1,
createdAt: '2020-10-09T08:00:00.6092798Z',
createdByApp: 'ecolyo',
updatedAt: '2020-10-09T08:00:00.6092798Z',
},
},
}, },
}) })
......
import { FluidType } from 'enums'
import fs from 'fs'
import { DateTime } from 'luxon'
import { DataloadEntity } from 'models'
import config from './config'
const fluidConfig = require('../src/constants/config.json').fluidConfig
/* /*
* Create dummy data files for each fluid. * Create dummy data files for each fluid.
* Hourly data is not generated * Hourly data is not generated
*/ */
const fs = require('fs')
const { DateTime } = require('luxon')
const config = require('./config')
const fluidConfig = require('../src/constants/config.json').fluidConfig
function getRandomNumber(min, max) { type IMockData = Omit<DataloadEntity, 'id'>
// Generate a random float between min and max
/** Generate a random float between min and max */
function getRandomNumber(min: number, max: number) {
let randomFloat = Math.random() * (max - min) + min let randomFloat = Math.random() * (max - min) + min
// Round to two decimal places // Round to two decimal places
randomFloat = Math.round(randomFloat * 100) / 100 randomFloat = Math.round(randomFloat * 100) / 100
return randomFloat return randomFloat
} }
const generateHalfAnHourData = (startingDate, endingDate, min, max) => { const generateHalfAnHourData = (
startingDate: DateTime,
endingDate: DateTime,
min: number,
max: number
) => {
let parsingDate = DateTime.local( let parsingDate = DateTime.local(
startingDate.year, startingDate.year,
startingDate.month, startingDate.month,
...@@ -23,7 +33,7 @@ const generateHalfAnHourData = (startingDate, endingDate, min, max) => { ...@@ -23,7 +33,7 @@ const generateHalfAnHourData = (startingDate, endingDate, min, max) => {
0, 0,
0 0
) )
const halfAnHourDumpArray = [] const halfAnHourDumpArray: IMockData[] = []
while (parsingDate <= endingDate) { while (parsingDate <= endingDate) {
const load = getRandomNumber(min, max) const load = getRandomNumber(min, max)
halfAnHourDumpArray.push({ halfAnHourDumpArray.push({
...@@ -40,13 +50,19 @@ const generateHalfAnHourData = (startingDate, endingDate, min, max) => { ...@@ -40,13 +50,19 @@ const generateHalfAnHourData = (startingDate, endingDate, min, max) => {
return halfAnHourDumpArray return halfAnHourDumpArray
} }
const generateData = (startingDate, endingDate, min, max, fluidType) => { const generateData = (
startingDate: DateTime,
endingDate: DateTime,
min: number,
max: number,
fluidType: FluidType
) => {
let parsingDate = DateTime.local( let parsingDate = DateTime.local(
startingDate.year, startingDate.year,
startingDate.month, startingDate.month,
startingDate.day startingDate.day
) )
const dayDumpArray = [] const dayDumpArray: IMockData[] = []
while (parsingDate <= endingDate) { while (parsingDate <= endingDate) {
const load = getRandomNumber(min, max) const load = getRandomNumber(min, max)
dayDumpArray.push({ dayDumpArray.push({
...@@ -63,11 +79,11 @@ const generateData = (startingDate, endingDate, min, max, fluidType) => { ...@@ -63,11 +79,11 @@ const generateData = (startingDate, endingDate, min, max, fluidType) => {
return dayDumpArray return dayDumpArray
} }
// Function to aggregate load data for a specific period /** Function to aggregate load data for a specific period */
function aggregateLoadData(data, period) { function aggregateLoadData(data: IMockData[], period: string) {
const aggregatedData = {} const aggregatedData: Record<string, IMockData> = {}
data.forEach(entry => { data.forEach(entry => {
let key let key = ''
const entryCopy = { ...entry } const entryCopy = { ...entry }
switch (period) { switch (period) {
case 'day': case 'day':
...@@ -101,9 +117,12 @@ function aggregateLoadData(data, period) { ...@@ -101,9 +117,12 @@ function aggregateLoadData(data, period) {
} }
} else { } else {
aggregatedData[key].load += entryCopy.load aggregatedData[key].load += entryCopy.load
aggregatedData[key].price += entryCopy.price if (aggregatedData[key].price !== undefined) {
aggregatedData[key].price = 0
}
} }
}) })
return Object.values(aggregatedData) return Object.values(aggregatedData)
} }
...@@ -162,6 +181,6 @@ const dump = { ...@@ -162,6 +181,6 @@ const dump = {
const dumpString = JSON.stringify(dump) const dumpString = JSON.stringify(dump)
fs.writeFile('data/loads.json', dumpString, function (err) { fs.writeFile('data/loads.json', dumpString, function (err: unknown) {
if (err) console.log('error', err) if (err) console.log('error', err)
}) })
...@@ -20,5 +20,5 @@ ...@@ -20,5 +20,5 @@
"*": ["src/*", "../node_modules/*", "types/*"] "*": ["src/*", "../node_modules/*", "types/*"]
} }
}, },
"include": ["src/**/*", "tests/**/*"] "include": ["src/**/*", "tests/**/*", "scripts/**/*"]
} }