-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_data_now.py
More file actions
48 lines (40 loc) · 1.18 KB
/
Copy pathgenerate_data_now.py
File metadata and controls
48 lines (40 loc) · 1.18 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
import pandas as pd
import random
import numpy as np
# Generate 2000 traffic records
random.seed(42)
np.random.seed(42)
data = []
for i in range(2000):
road_id = random.randint(1, 20)
hour = random.randint(0, 23)
day_of_week = random.randint(0, 6)
# Base traffic pattern
base_traffic = 200 + (road_id * 15)
# Rush hour factor
if hour in [7, 8, 17, 18, 19]:
rush_factor = 2.5
elif hour in [9, 10, 16, 20]:
rush_factor = 1.8
elif hour in [11, 12, 13, 14, 15]:
rush_factor = 1.3
elif hour in [0, 1, 2, 3, 4, 5]:
rush_factor = 0.3
else:
rush_factor = 0.8
# Weekend factor
weekend_factor = 0.7 if day_of_week >= 5 else 1.0
# Calculate traffic with noise
traffic = base_traffic * rush_factor * weekend_factor
noise = random.gauss(0, traffic * 0.1)
traffic = max(0, traffic + noise)
data.append({
'road_id': road_id,
'time_of_day': hour,
'day_of_week': day_of_week,
'traffic_volume': round(traffic, 2)
})
df = pd.DataFrame(data)
df.to_csv('data/traffic_data.csv', index=False)
print(f"Generated {len(df)} traffic records")
print(df.head())