-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsert_sample_data.py
More file actions
38 lines (31 loc) · 1.12 KB
/
insert_sample_data.py
File metadata and controls
38 lines (31 loc) · 1.12 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
from google.cloud import bigquery
import datetime
import random
import time
project_id = "hack-4-viksit-bharat"
table_id = f"{project_id}.vision_speed_smoothing_ai.metrics"
print(f"Connecting to {table_id}...")
client = bigquery.Client(project=project_id)
# Generate 100 points of data
rows = []
now = datetime.datetime.now(datetime.timezone.utc)
print("Generating sample data...")
for i in range(100):
# Create a nice sine wave for speed
t = float(i)
base_speed = 15.0 + 5.0 * (random.random() - 0.5)
rows.append({
"timestamp": (now - datetime.timedelta(seconds=100-i)).isoformat(),
"relative_time": t,
"mode": "smoothed" if i > 50 else "reactive",
"speed": base_speed,
"acceleration": random.uniform(-2.0, 2.0),
"brake_pressure": max(0.0, random.uniform(-0.5, 0.5))
})
print(f"Inserting {len(rows)} rows to BigQuery...")
errors = client.insert_rows_json(table_id, rows)
if not errors:
print("✅ Success! New rows have been added.")
print("The Dashboard should now show this data instead of 'Mock Data'.")
else:
print(f"❌ Encountered errors: {errors}")