Skip to content
Snippets Groups Projects
Commit 015be53a authored by Bastien DUMONT's avatar Bastien DUMONT :angel:
Browse files

Merge remote-tracking branch 'origin/dev' into ui/v4

parents c6b14e9c d3e76259
No related branches found
No related tags found
1 merge request!1263feat(ui)!: new design
...@@ -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,11 +60,10 @@ const dataEglAccount = JSON.stringify({ ...@@ -57,11 +60,10 @@ const dataEglAccount = JSON.stringify({
}, },
identifier: 'login', identifier: 'login',
state: null, state: null,
}) }
const dataEglAccount = JSON.stringify(EGL_ACCOUNT)
const dataEnedisTrigger = JSON.stringify({ const ENEDIS_TRIGGER: Trigger = {
data: {
attributes: {
_id: '3ed832cec67e6e0b2c6382edd30df11c', _id: '3ed832cec67e6e0b2c6382edd30df11c',
domain: 'cozy.tools:8080', domain: 'cozy.tools:8080',
prefix: COZY_PREFIX, prefix: COZY_PREFIX,
...@@ -81,13 +83,14 @@ const dataEnedisTrigger = JSON.stringify({ ...@@ -81,13 +83,14 @@ const dataEnedisTrigger = JSON.stringify({
createdByApp: 'ecolyo', createdByApp: 'ecolyo',
updatedAt: '2020-10-09T08:00:00.6092798Z', updatedAt: '2020-10-09T08:00:00.6092798Z',
}, },
}, }
const dataEnedisTrigger = JSON.stringify({
data: {
attributes: ENEDIS_TRIGGER,
}, },
}) })
const dataGrdfTrigger = JSON.stringify({ const GRDF_TRIGGER: Trigger = {
data: {
attributes: {
_id: '4ed832cec67e6e0b2c6382edd30df11c', _id: '4ed832cec67e6e0b2c6382edd30df11c',
domain: 'cozy.tools:8080', domain: 'cozy.tools:8080',
prefix: COZY_PREFIX, prefix: COZY_PREFIX,
...@@ -107,13 +110,14 @@ const dataGrdfTrigger = JSON.stringify({ ...@@ -107,13 +110,14 @@ const dataGrdfTrigger = JSON.stringify({
createdByApp: 'ecolyo', createdByApp: 'ecolyo',
updatedAt: '2020-10-09T08:00:00.6092798Z', updatedAt: '2020-10-09T08:00:00.6092798Z',
}, },
}, }
const dataGrdfTrigger = JSON.stringify({
data: {
attributes: GRDF_TRIGGER,
}, },
}) })
const dataEglTrigger = JSON.stringify({ const EGL_TRIGGER: Trigger = {
data: {
attributes: {
_id: '5ed832cec67e6e0b2c6382edd30df11c', _id: '5ed832cec67e6e0b2c6382edd30df11c',
domain: 'cozy.tools:8080', domain: 'cozy.tools:8080',
prefix: COZY_PREFIX, prefix: COZY_PREFIX,
...@@ -133,7 +137,10 @@ const dataEglTrigger = JSON.stringify({ ...@@ -133,7 +137,10 @@ const dataEglTrigger = JSON.stringify({
createdByApp: 'ecolyo', createdByApp: 'ecolyo',
updatedAt: '2020-10-09T08:00:00.6092798Z', updatedAt: '2020-10-09T08:00:00.6092798Z',
}, },
}, }
const dataEglTrigger = JSON.stringify({
data: {
attributes: EGL_TRIGGER,
}, },
}) })
......
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/**/*"]
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment