-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataGenerator.js
109 lines (102 loc) · 2.67 KB
/
dataGenerator.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import faker from "faker";
import fs from 'fs';
const segments = {
"Segment A": "SEGA",
"Segment B": "SEGB",
"Segment C": "SEGC",
"Segment D": "SEGD",
};
const employees = {};
for (let i = 1; i <= 10; i += 1) {
const randomNumber = faker.datatype.number({ min: 10000, max: 99999 });
employees[`x${randomNumber}`] = faker.name.findName();
}
const generateArray = (valueCallback, count) => {
const array = [];
for (let i = 1; i <= count; i += 1) {
array.push(valueCallback());
}
return array;
};
const data = [];
for (let i = 0; i < 200000; i++) {
const row = {
kisMother: faker.company.companyName(),
cvr: faker.unique(() =>
faker.datatype.number({ min: 1000000000, max: 9999999999 })
),
segment: faker.random.arrayElement(Object.keys(segments)),
kisMotherId: faker.datatype.uuid(),
onHoldStatus: faker.random.arrayElement(["Ingen", "Alle", "Delvis"]),
sumNotDue: faker.datatype.number({
min: 1000,
max: 10000,
precision: 0.1,
}),
sum10Days: faker.random.arrayElement([
faker.datatype.number({ min: -10000, max: 100000, precision: 0.1 }),
0,
]),
sum1stMonth: faker.datatype.number({
min: 10000,
max: 100000,
precision: 0.1,
}),
sum2ndMonth: faker.datatype.number({
min: 10000,
max: 100000,
precision: 0.1,
}),
sum3rdMonth: faker.datatype.number({
min: 10000,
max: 100000,
precision: 0.1,
}),
sum4thMonth: faker.datatype.number({
min: 10000,
max: 100000,
precision: 0.1,
}),
sum5thMonth: faker.datatype.number({
min: 10000,
max: 100000,
precision: 0.1,
}),
sum6thMonth: faker.datatype.number({
min: 10000,
max: 100000,
precision: 0.1,
}),
sum7thMonthUp: faker.datatype.number({
min: 10000,
max: 200000,
precision: 0.1,
}),
sumOfAll: faker.datatype.number({
min: 50000,
max: 300000,
precision: 0.1,
}),
sumDue: faker.datatype.number({
min: 10000,
max: 100000,
precision: 0.1,
}),
assignedEmployee: faker.random.arrayElement(Object.keys(employees)),
hasData: faker.datatype.boolean(),
customerId: faker.unique(() =>
faker.datatype.number({ min: 1, max: 10000000 })
),
change: generateArray(() => faker.datatype.number({ min: -1, max: 1, precision: 0.01 }), 15)
};
row.segmentCode = segments[row.segment];
data.push(row);
}
console.log("data.length", data.length);
fs.writeFile('data.json', JSON.stringify(data), 'utf8', (err, data) => {
if (err) {
console.err('Error: ', err);
} else {
console.log('Data successfully stored in `data.json`');
}
})