forked from airfec/Booking-Service
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenerate.js
More file actions
125 lines (106 loc) · 2.82 KB
/
generate.js
File metadata and controls
125 lines (106 loc) · 2.82 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
const fs = require('fs');
const faker = require('faker');
const createDataJSON = (id) => {
const dataItem = {};
dataItem.roomId = id;
dataItem.price = faker.random.number({
min: 50,
max: 400,
});
dataItem.numberOfBookings = faker.random.number({
min: 1,
max: 25,
});
dataItem.bookings = [];
for (let i = 0; i < dataItem.numberOfBookings; i++) {
const booking = {};
booking.checkIn = faker.date.between('2018-07-24', '2019-12-31');
booking.duration = faker.random.number({
min: 1,
max: 31,
});
dataItem.bookings.push(booking);
}
dataItem.serviceFee = faker.random.number({
min: 15,
max: 50,
});
dataItem.cleaningFee = faker.random.number({
min: 5,
max: 35,
});
dataItem.minimumStay = faker.random.number({
max: 3,
});
dataItem.maxAdults = faker.random.number({
min: 2,
max: 8,
});
dataItem.maxChildren = faker.random.number({
min: 2,
max: 8,
});
dataItem.maxInfants = faker.random.number({
min: 2,
max: 4,
});
dataItem.taxes = faker.random.number({
min: 5,
max: 40,
});
const num1 = faker.random.number({
max: 5,
});
const num2 = faker.random.number({
max: 7,
});
const funFactTitles = [
'This house is haunted.',
"This was Elon Musk's first apartment.",
'This place has a great view of the park.',
'This place has amazing air conditioning.',
'This is a very popular booking.',
'People are talking about this place.',
];
const funFacts = [
'It’s been viewed 500+ times in the past week.',
`It’s been booked ${dataItem.taxes} times in the past year.`,
'The owner takes pictures of all the tenants.',
'This is a top rated listing.',
'The owner is a gentleman and a scholar.',
'The owner is well-liked in his community.',
"It's rated in the top 5% for hospitality.",
"It's rated in the top 5% for cleanliness.",
];
dataItem.funFactTitles = funFactTitles[num1];
dataItem.funFacts = funFacts[num2];
// Shape of dataItem object
// {
// roomId: Number
// numberOfBookings: Number
// bookings: Array [{checkIn: Date, duration: Number}]
// price: Number
// cleaningFee: Number
// serviceFee: Number
// minimumStay: Number
// maxAdults: Number,
// maxChildren: Number,
// maxInfants: Number,
// taxes: Number
// }
return dataItem;
};
const data = [];
const writeJSON = () => {
// fs.appendFileSync('./bookings.json');
// const records = Array(2000000)
// .fill()
// .map((e, i) => JSON.stringify(createDataJSON(i)));
// records.forEach((data) => {
// out.write(`${data}\n`);
// });
for (let i = 1; i <= 10000000; i++) {
fs.appendFileSync('./bookings.json', `${JSON.stringify(createDataJSON(i))}\n`);
}
};
writeJSON();