-
Notifications
You must be signed in to change notification settings - Fork 1
/
newDataGenerator.js
86 lines (79 loc) · 2.68 KB
/
newDataGenerator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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
const fs = require('fs');
const csvWriter = require ('csv-write-stream');
var writer = csvWriter();
var faker = require('faker');
const hardData = require('./database/hardData.js');
var counter = 0;
const getRandomItem = function (array) {
return array[Math.floor(Math.random() * array.length)];
};
const randomScore = function () {
return (((Math.round(Math.random() * 50)) / 10)).toFixed(1);
};
const dataGen = (writer, data) =>{
writer.pipe(fs.createWriteStream('data.csv'));
let i = 10000000
write();
function write(){
let ok = true;
do {
i--;
if(i===0){
writer.write({
name : getRandomItem(hardData.names).toUpperCase() + i,
type : getRandomItem(hardData.types),
price : getRandomItem(hardData.prices),
location : getRandomItem(hardData.locations),
description : getRandomItem(hardData.descriptions),
foodScore : randomScore(),
decorScore : randomScore(),
serviceScore : randomScore(),
review : faker.lorem.paragraph(),
});
} else{
ok=writer.write({
id: i + 1,
name : getRandomItem(hardData.names).toUpperCase() + (i + 1),
type : getRandomItem(hardData.types),
price : getRandomItem(hardData.prices),
location : getRandomItem(hardData.locations),
description : getRandomItem(hardData.descriptions),
foodScore : randomScore(),
decorScore : randomScore(),
serviceScore : randomScore(),
review : faker.lorem.paragraph(),
});
}
} while (i > 0 && ok);
if(i>0){
writer.once('drain', write);
}
}
}
// const dataGen = () =>{
// writer.pipe(fs.createWriteStream('data2.csv'));
// for(var i = 0; i<5000000; i++){
// writer.write({
// name : getRandomItem(hardData.names).toUpperCase(),
// type : getRandomItem(hardData.types),
// price : getRandomItem(hardData.prices),
// location : getRandomItem(hardData.locations),
// description : getRandomItem(hardData.descriptions),
// foodScore : randomScore(),
// decorScore : randomScore(),
// serviceScore : randomScore(),
// review : faker.lorem.paragraph(),
// })
// }
// writer.end();
// }
dataGen(writer, hardData);
// const name = getRandomItem(hardData.names).toUpperCase();
// const type = getRandomItem(hardData.types);
// const price = getRandomItem(hardData.prices);
// const location = getRandomItem(hardData.locations);
// const description = getRandomItem(hardData.descriptions);
// const foodScore = randomScore();
// const decorScore = randomScore();
// const serviceScore = randomScore();
// const review = faker.lorem.paragraph();