-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_sql_data.py
More file actions
40 lines (33 loc) · 1.28 KB
/
generate_sql_data.py
File metadata and controls
40 lines (33 loc) · 1.28 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
import sqlite3
from datetime import datetime, timedelta
# Function to generate dummy temperature data
def generate_dummy_data(start_date, end_date):
current_date = start_date
while current_date <= end_date:
yield (current_date.strftime('%Y-%m-%d'),
round(20 + 10 * (current_date.day % 31), 2), # Dummy temperature for t1
round(15 + 8 * (current_date.day % 31), 2), # Dummy temperature for t2
round(25 + 5 * (current_date.day % 31), 2)) # Dummy temperature for t3
current_date += timedelta(days=1)
# Connect to SQLite database (creates a new one if not exists)
conn = sqlite3.connect('temperature_data.db')
cursor = conn.cursor()
# Create table
cursor.execute('''
CREATE TABLE IF NOT EXISTS temperature_data (
Date DATE PRIMARY KEY,
t1 REAL,
t2 REAL,
t3 REAL
)
''')
# Generate dummy data for the entire month of December 2023
start_date = datetime(2023, 12, 1)
end_date = datetime(2023, 12, 31)
dummy_data = generate_dummy_data(start_date, end_date)
# Insert dummy data into the table
cursor.executemany('INSERT INTO temperature_data VALUES (?, ?, ?, ?)', dummy_data)
# Commit the changes and close the connection
conn.commit()
conn.close()
print("SQLite database created with dummy data.")