Repository navigation
Expand file tree
/
Copy pathseed.py
More file actions
95 lines (84 loc) · 2.25 KB
/
Copy pathseed.py
File metadata and controls
95 lines (84 loc) · 2.25 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
import psycopg2
import random
from faker import Faker
from datetime import datetime, timedelta
fake = Faker()
conn = psycopg2.connect(
dbname="SmartCityLogistics",
user="postgres",
password="LA_TUA_PASSWORD",
host="localhost",
port="PORT"
)
cur = conn.cursor()
# -------------------------
# CREATE VEHICLES
# -------------------------
vehicle_types = ["DRONE", "VAN", "CARGO_BIKE"]
for i in range(20):
v_type = random.choice(vehicle_types)
cur.execute("""
INSERT INTO Vehicle (model, km_total, created_at, vehicle_type)
VALUES (%s, %s, %s, %s)
RETURNING vehicle_id
""", (
fake.word(),
random.randint(100, 5000),
fake.date_between(start_date='-2y', end_date='today'),
v_type
))
# -------------------------
# CREATE STAFF
# -------------------------
for i in range(5):
cur.execute("""
INSERT INTO Staff (name, role)
VALUES (%s, %s)
""", (
fake.name(),
random.choice(["driver", "technician"])
))
# -------------------------
# CREATE MISSIONS
# -------------------------
for i in range(50):
cur.execute("""
INSERT INTO Mission (
vehicle_id,
staff_id,
start_time,
end_time,
distance_km,
status
)
VALUES (%s,%s,%s,%s,%s,%s)
""", (
random.randint(1, 20),
random.randint(1, 5),
fake.date_time_between(start_date='-3m', end_date='now'),
fake.date_time_between(start_date='-3m', end_date='now'),
round(random.uniform(1, 50), 2),
random.choice(["COMPLETED", "FAILED", "CANCELLED"])
))
# -------------------------
# CREATE MAINTENANCE
# -------------------------
for i in range(10):
cur.execute("""
INSERT INTO Maintenance (
vehicle_id,
staff_id,
maintenance_date,
description
)
VALUES (%s,%s,%s,%s)
""", (
random.randint(1, 20),
random.randint(1, 5),
fake.date_between(start_date='-6m', end_date='today'),
fake.sentence()
))
conn.commit()
cur.close()
conn.close()
print("Database popolato con successo!")