Skip to content
Snippets Groups Projects
Commit d25e7d32 authored by Yoan VALLET's avatar Yoan VALLET
Browse files

set NOSONAR for random in test file

parent 4a376822
No related branches found
No related tags found
No related merge requests found
......@@ -8,6 +8,7 @@ const { DateTime } = require('luxon')
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 fs = require('fs')
const { DateTime } = require('luxon')
const generateData = (startingdate, endingDate) => {
let parsingDate = DateTime.local(
startingdate.year,
startingdate.month,
startingdate.day
)
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
const dumpArray = []
while (parsingDate <= endingDate) {
const load = parseInt(Math.random() * 1000) / 100
dailyLoad += load
monthlyLoad += load
yearlyLoad += load
dumpArray.push({
load: load,
year: parsingDate.year,
month: parsingDate.month,
day: parsingDate.day,
hour: parsingDate.hour,
minute: parsingDate.minute,
})
if (parsingDate.day !== lastDay) {
dayDumpArray.push({
load: Math.round(dailyLoad * 100) / 100,
year: parsingDate.year,
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: 0,
day: 0,
hour: 0,
minute: 0,
})
yearlyLoadLoad = 0
lastYear = parsingDate.year
}
parsingDate = parsingDate.plus({ minutes: 30 })
}
return {
hourlyLoad: dumpArray,
dailyLoad: dayDumpArray,
monthlyLoad: monthDumpArray,
yearlyLoad: yearDumpArray,
}
}
const startingdate = DateTime.local(2020, 1, 1)
const endingDate = DateTime.local(2020, 4, 15)
const Eelec = generateData(startingdate, endingDate)
const Gaz = generateData(startingdate, endingDate)
const Eau = generateData(startingdate, endingDate)
//const dt2 = dt.plus({days:1})
/*
fetchData = (y1,y2,withHourlyDetail) =>
{
const dumpArray =[];
for (year = y1; year <= y2; year++) {
for (month = 1; month <= 12; month++) {
for (day = 1; day <= 30; day++) {
if (withHourlyDetail)
{
for(h = 0; h<=23;h++)
{
for(m=0;m<=1;m++)
{
const date =
{
year: year,
month: month,
day: day,
hour: h,
minute: m*30,
load: (parseInt(Math.random() * 10000) / 100)
}
dumpArray.push(date);
}
}
}
else
{
const date =
{
year: year,
month: month,
day: day,
hour: 0,
minute: 0,
load: (parseInt(Math.random() * 10000) / 100)
}
dumpArray.push(date);
}
}
}
}
return dumpArray;
}
*/
const dump = {
'com.grandlyon.enedis.minute': Eelec.hourlyLoad,
'com.grandlyon.enedis.day': Eelec.dailyLoad,
'com.grandlyon.enedis.month': Eelec.monthlyLoad,
'com.grandlyon.enedis.year': Eelec.yearlyLoad,
'com.grandlyon.grdf.hour': Gaz.hourlyLoad,
'com.grandlyon.grdf.day': Gaz.dailyLoad,
'com.grandlyon.grdf.month': Gaz.monthlyLoad,
'com.grandlyon.grdf.year': Gaz.yearlyLoad,
//"com.grandlyon.egl.hour": Eau.hourlyLoad,
'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('dayData.json', dumpString, function(err) {
if (err) console.log('error', err)
})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment