initial working env

This commit is contained in:
Arian Nasr
2025-12-11 03:30:35 -05:00
commit 25469a54b3
11 changed files with 799 additions and 0 deletions

20
db_connector.py Normal file
View File

@@ -0,0 +1,20 @@
import sqlite3
from schemas import DatabaseRecord
def connect_db(db_name):
return sqlite3.connect(db_name)
def initialize_database(conn):
cursor = conn.cursor()
cursor.execute("CREATE TABLE IF NOT EXISTS usage_data (timestamp TEXT PRIMARY KEY, value_kwh REAL, cost REAL, tou INTEGER)")
conn.commit()
def insert_usage_data(conn, record: DatabaseRecord):
cursor = conn.cursor()
cursor.execute(
"INSERT OR REPLACE INTO usage_data (timestamp, value_kwh, cost, tou) VALUES (?, ?, ?, ?)",
(record.timestamp.isoformat(), record.value_kwh, record.cost, record.tou)
)
conn.commit()