-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_data.js
More file actions
135 lines (128 loc) · 3.22 KB
/
generate_data.js
File metadata and controls
135 lines (128 loc) · 3.22 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
126
127
128
129
130
131
132
133
134
135
const fs = require("fs");
// Générer les utilisateurs
const users = Array.from({ length: 50 }, (_, i) => ({
_id: `user-${i}`,
name: [
"Thomas",
"Marie",
"Lucas",
"Sophie",
"Antoine",
"Emma",
"Hugo",
"Léa",
"Noah",
"Chloé",
][Math.floor(Math.random() * 10)],
surname: [
"Martin",
"Bernard",
"Dubois",
"Petit",
"Robert",
"Richard",
"Durand",
"Leroy",
"Moreau",
"Simon",
][Math.floor(Math.random() * 10)],
email: `user${i}@ecovoit.fr`,
phone: `06-${String(Math.floor(Math.random() * 100)).padStart(
2,
"0"
)}-${String(Math.floor(Math.random() * 100)).padStart(2, "0")}-${String(
Math.floor(Math.random() * 100)
).padStart(2, "0")}-${String(Math.floor(Math.random() * 100)).padStart(
2,
"0"
)}`,
avatar: `https://i.pravatar.cc/150?img=${Math.floor(Math.random() * 70) + 1}`,
totalTrips: Math.floor(Math.random() * 100),
rating: parseFloat((3 + Math.random() * 2).toFixed(1)),
}));
// Générer les trajets
const villes = [
"Paris",
"Lyon",
"Marseille",
"Toulouse",
"Bordeaux",
"Nice",
"Nantes",
"Strasbourg",
"Lille",
"Rennes",
];
const voitures = [
"Renault Clio",
"Peugeot 208",
"Tesla Model 3",
"VW Golf",
"Citroën C3",
"Dacia Sandero",
];
const trips = Array.from({ length: 100 }, (_, i) => ({
_id: `trip-${i}`,
conductorId: `user-${Math.floor(Math.random() * 50)}`,
villeDepart: villes[Math.floor(Math.random() * villes.length)],
villeArrivee: villes[Math.floor(Math.random() * villes.length)],
price: Math.floor(Math.random() * 70) + 10,
nbPlacesVides: Math.floor(Math.random() * 4) + 1,
meetingPoint: `Point de rendez-vous ${i}`,
carModel: voitures[Math.floor(Math.random() * voitures.length)],
status: ["available", "full", "completed", "cancelled"][
Math.floor(Math.random() * 4)
],
departureTime: new Date(
2025,
11,
Math.floor(Math.random() * 30) + 1,
Math.floor(Math.random() * 24),
0,
0
)
.toISOString()
.slice(0, 19),
}));
// Générer les réservations avec références VALIDES
const bookings = Array.from({ length: 150 }, (_, i) => {
const tripIndex = Math.floor(Math.random() * 100);
return {
_id: `booking-${Date.now()}-${i}`,
tripId: `trip-${tripIndex}`,
passengerId: `user-${Math.floor(Math.random() * 50)}`,
price: trips[tripIndex].price,
nbPlacesLouees: Math.floor(Math.random() * 3) + 1,
dateBooking: new Date(
2025,
10,
Math.floor(Math.random() * 24) + 1,
Math.floor(Math.random() * 24),
30,
0
)
.toISOString()
.slice(0, 19),
};
});
// Créer le dossier public s'il n'existe pas
if (!fs.existsSync("public")) {
fs.mkdirSync("public");
}
// Sauvegarder les fichiers
fs.writeFileSync(
"public/users_data.json",
JSON.stringify({ docs: users }, null, 2)
);
fs.writeFileSync(
"public/trips_data.json",
JSON.stringify({ docs: trips }, null, 2)
);
fs.writeFileSync(
"public/bookings_data.json",
JSON.stringify({ docs: bookings }, null, 2)
);
console.log("✅ Fichiers générés avec relations cohérentes!");
console.log(` • ${users.length} utilisateurs`);
console.log(` • ${trips.length} trajets`);
console.log(` • ${bookings.length} réservations`);