-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsynthetic_data.sql
More file actions
66 lines (56 loc) · 1.38 KB
/
synthetic_data.sql
File metadata and controls
66 lines (56 loc) · 1.38 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
INSERT INTO vehicles (model, battery_capacity_kwh, manufacture_date)
SELECT
'EV-' || chr(65 + gs),
(40 + (random() * 40))::NUMERIC(5,2),
DATE '2020-01-01' + (random() * 1000)::INT
FROM generate_series(1, 10) gs;
-- Generate charging sessions (6 months)
INSERT INTO charging_sessions (
vehicle_id,
charger_type,
start_time,
end_time,
energy_added_kwh,
avg_current_a,
max_temp_c
)
SELECT
v.vehicle_id,
CASE
WHEN random() < 0.3 THEN 'fast'
ELSE 'slow'
END,
ts,
ts + INTERVAL '1 hour',
(10 + random() * 40)::NUMERIC(5,2),
CASE
WHEN random() < 0.3 THEN (150 + random() * 80)
ELSE (40 + random() * 40)
END::NUMERIC(6,2),
CASE
WHEN random() < 0.3 THEN (45 + random() * 15)
ELSE (30 + random() * 10)
END::NUMERIC(5,2)
FROM vehicles v,
generate_series(
NOW() - INTERVAL '180 days',
NOW(),
INTERVAL '2 days'
) ts;
-- Generate telemetry data
INSERT INTO battery_telemetry (
vehicle_id,
timestamp,
soc_percent,
battery_temp_c,
voltage_v,
current_a
)
SELECT
cs.vehicle_id,
cs.start_time + (random() * INTERVAL '1 hour'),
(20 + random() * 80)::NUMERIC(5,2),
(cs.max_temp_c - random() * 5)::NUMERIC(5,2),
(350 + random() * 70)::NUMERIC(6,2),
cs.avg_current_a + (random() * 10)
FROM charging_sessions cs;