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:
- merge_requests
environment:
name: dev
url: https://ecolyo.dev.cozy.self-data.alpha.grandlyon.com/
url: https://dev-ecolyo.cozy.self-data.alpha.grandlyon.com/
needs:
- deploy-dev
......@@ -228,7 +228,7 @@ update-demo:
- dev
environment:
name: ecolyodemo
url: https://ecolyo.ecolyodemo.cozy.self-data.alpha.grandlyon.com/
url: https://ecolyodemo-dev.cozy.self-data.alpha.grandlyon.com/
needs:
- deploy-test
......
......@@ -25,7 +25,12 @@
"test": "cs test --verbose --coverage",
"tx": "tx pull --all || true",
"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": {
"type": "git",
......
/* eslint-disable camelcase */
const axios = require('axios')
const config = require('./config')
import axios from 'axios'
import { Account, Trigger } from 'models'
import config from './config'
const headers = {
Accept: 'application/json',
......@@ -12,7 +13,7 @@ const headers = {
const COZY_PREFIX = 'cozy35ba44d2d1749e6f21646edce51e7190'
const ENEDIS_ACCOUNT_ID = '70e68b8450cee09fe2f077610901094d'
const dataEnedisAccount = JSON.stringify({
const ENEDIS_ACCOUNT: Partial<Account> = {
id: ENEDIS_ACCOUNT_ID,
account_type: 'enedissgegrandlyon',
name: '',
......@@ -31,10 +32,11 @@ const dataEnedisAccount = JSON.stringify({
},
identifier: 'address',
state: null,
})
}
const dataEnedisAccount = JSON.stringify(ENEDIS_ACCOUNT)
const GRDF_ACCOUNT_ID = '89e68b8450cee09fe2f077610901094d'
const dataGrdfAccount = JSON.stringify({
const GRDF_ACCOUNT: Partial<Account> = {
id: GRDF_ACCOUNT_ID,
account_type: 'grdfgrandlyon',
auth: {
......@@ -44,10 +46,11 @@ const dataGrdfAccount = JSON.stringify({
},
identifier: 'login',
state: null,
})
}
const dataGrdfAccount = JSON.stringify(GRDF_ACCOUNT)
const EGL_ACCOUNT_ID = '90e68b8450cee09fe2f077610901094d'
const dataEglAccount = JSON.stringify({
const EGL_ACCOUNT: Partial<Account> = {
id: EGL_ACCOUNT_ID,
account_type: 'eglgrandlyon',
auth: {
......@@ -57,83 +60,87 @@ const dataEglAccount = JSON.stringify({
},
identifier: 'login',
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({
data: {
attributes: {
_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',
},
},
attributes: ENEDIS_TRIGGER,
},
})
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({
data: {
attributes: {
_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',
},
},
attributes: GRDF_TRIGGER,
},
})
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({
data: {
attributes: {
_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',
},
},
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.
* 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) {
// Generate a random float between min and max
type IMockData = Omit<DataloadEntity, 'id'>
/** Generate a random float between min and max */
function getRandomNumber(min: number, max: number) {
let randomFloat = Math.random() * (max - min) + min
// Round to two decimal places
randomFloat = Math.round(randomFloat * 100) / 100
return randomFloat
}
const generateHalfAnHourData = (startingDate, endingDate, min, max) => {
const generateHalfAnHourData = (
startingDate: DateTime,
endingDate: DateTime,
min: number,
max: number
) => {
let parsingDate = DateTime.local(
startingDate.year,
startingDate.month,
......@@ -23,7 +33,7 @@ const generateHalfAnHourData = (startingDate, endingDate, min, max) => {
0,
0
)
const halfAnHourDumpArray = []
const halfAnHourDumpArray: IMockData[] = []
while (parsingDate <= endingDate) {
const load = getRandomNumber(min, max)
halfAnHourDumpArray.push({
......@@ -40,13 +50,19 @@ const generateHalfAnHourData = (startingDate, endingDate, min, max) => {
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(
startingDate.year,
startingDate.month,
startingDate.day
)
const dayDumpArray = []
const dayDumpArray: IMockData[] = []
while (parsingDate <= endingDate) {
const load = getRandomNumber(min, max)
dayDumpArray.push({
......@@ -63,11 +79,11 @@ const generateData = (startingDate, endingDate, min, max, fluidType) => {
return dayDumpArray
}
// Function to aggregate load data for a specific period
function aggregateLoadData(data, period) {
const aggregatedData = {}
/** Function to aggregate load data for a specific period */
function aggregateLoadData(data: IMockData[], period: string) {
const aggregatedData: Record<string, IMockData> = {}
data.forEach(entry => {
let key
let key = ''
const entryCopy = { ...entry }
switch (period) {
case 'day':
......@@ -101,9 +117,12 @@ function aggregateLoadData(data, period) {
}
} else {
aggregatedData[key].load += entryCopy.load
aggregatedData[key].price += entryCopy.price
if (aggregatedData[key].price !== undefined) {
aggregatedData[key].price = 0
}
}
})
return Object.values(aggregatedData)
}
......@@ -162,6 +181,6 @@ const 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)
})
......@@ -20,5 +20,5 @@
"*": ["src/*", "../node_modules/*", "types/*"]
}
},
"include": ["src/**/*", "tests/**/*"]
"include": ["src/**/*", "tests/**/*", "scripts/**/*"]
}