-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.py
More file actions
49 lines (45 loc) · 1.54 KB
/
database.py
File metadata and controls
49 lines (45 loc) · 1.54 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
import sqlite3
import os
from datetime import datetime
# Define the database file path
DB_FILE = os.path.join("results", "latency_metrics.db")
def init_db():
"""Initializes the database and creates the latency_metrics table if it doesn't exist."""
os.makedirs("results", exist_ok=True)
conn = sqlite3.connect(DB_FILE)
cursor = conn.cursor()
cursor.execute("""
CREATE TABLE IF NOT EXISTS latency_metrics (
id INTEGER PRIMARY KEY AUTOINCREMENT,
timestamp TEXT NOT NULL,
room_name TEXT NOT NULL,
transport_latency_ms INTEGER,
stt_latency_ms INTEGER,
llm_latency_ms INTEGER,
tts_latency_ms INTEGER,
total_roundtrip_ms INTEGER
)
""")
conn.commit()
conn.close()
print(f"Database initialized at {DB_FILE}")
def log_latency(room_name, metrics):
"""Logs a new set of latency metrics to the database."""
conn = sqlite3.connect(DB_FILE)
cursor = conn.cursor()
cursor.execute("""
INSERT INTO latency_metrics (timestamp, room_name, transport_latency_ms, stt_latency_ms, llm_latency_ms, tts_latency_ms, total_roundtrip_ms)
VALUES (?, ?, ?, ?, ?, ?, ?)
""", (
datetime.utcnow().isoformat(),
room_name,
metrics.get("transport_latency_ms"),
metrics.get("stt_latency_ms"),
metrics.get("llm_latency_ms"),
metrics.get("tts_latency_ms"),
metrics.get("total_roundtrip_ms")
))
conn.commit()
conn.close()
if __name__ == "__main__":
init_db()