Newer
Older
/*
* 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 // NOSONAR
const generateHalfAnHourData = (_startingdate, _endingDate, min, max) => {
let parsingDate

Rémi PAILHAREY
committed
parsingDate = DateTime.local(
_startingdate.year,
_startingdate.month,
_startingdate.day,
0,
0
)

Rémi PAILHAREY
committed
let lastDay = parsingDate.day
const dayDumpArray = []
let lastMonth = parsingDate.month
const monthDumpArray = []
let lastYear = parsingDate.year
const yearDumpArray = []
let dailyLoad = 0
let monthlyLoad = 0
let yearlyLoad = 0
while (parsingDate <= _endingDate) {
const load = getRandomInt(min, max)

Rémi PAILHAREY
committed
dailyLoad += load
monthlyLoad += load
yearlyLoad += load
halfAnHourDumpArray.push({
load: load,
year: parsingDate.year,
month: parsingDate.month,
day: parsingDate.day,
hour: parsingDate.hour,
minute: parsingDate.minute,
})

Rémi PAILHAREY
committed
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
if (parsingDate.day !== lastDay) {
dayDumpArray.push({
load: Math.round(dailyLoad * 100) / 100,
year: lastYear,
month: lastMonth,
day: lastDay,
hour: 0,
minute: 0,
})
dailyLoad = 0
lastDay = parsingDate.day
}
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({ minute: 30 })
}

Rémi PAILHAREY
committed
dayDumpArray.push({
load: Math.round(dailyLoad * 100) / 100,
year: lastYear,
month: lastMonth,
day: lastDay,
hour: 0,
minute: 0,
})

Rémi PAILHAREY
committed
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 {
halfAnHourLoad: halfAnHourDumpArray,
dailyLoad: dayDumpArray,
monthlyLoad: monthDumpArray,
yearlyLoad: yearDumpArray,
}
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
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,
}
}
// Create data folder
const dir = './data'
if (!fs.existsSync(dir)) {
console.log('Create data folder...')
fs.mkdirSync(dir)
}
const startingdate = config.startingdate
const endingDate = config.endingDate
const halfHourStartingdate = config.halfHourStartingdate

Rémi PAILHAREY
committed
const Elec = generateHalfAnHourData(

Rémi PAILHAREY
committed
0.12,
0.36
const Gaz = generateData(startingdate, endingDate, 16, 68)
const Eau = generateData(startingdate, endingDate, 200, 300)
const dumpElec = {

Rémi PAILHAREY
committed
'com.grandlyon.enedis.minute': Elec.halfAnHourLoad,
'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 = {

Rémi PAILHAREY
committed
'com.grandlyon.enedis.minute': Elec.halfAnHourLoad,
'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) {