-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.py
More file actions
43 lines (39 loc) · 991 Bytes
/
Copy pathdb.py
File metadata and controls
43 lines (39 loc) · 991 Bytes
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
import sqlite3
from datetime import datetime
DB_NAME="prediction.db"
def init_db():
conn=sqlite3.connect(DB_NAME)
cursor=conn.cursor()
cursor.execute("""
CREATE TABLE IF NOT EXISTS predictions (
id INTEGER PRIMARY KEY AUTOINCREMENT,
filename TEXT,
top1_class TEXT,
confidence REAL,
latency_ms REAL,
timestamp TEXT
)
""")
conn.commit()
conn.close()
def save_prediction(filename, top1_class, confidence, latency_ms):
conn = sqlite3.connect(DB_NAME)
cursor = conn.cursor()
cursor.execute("""
INSERT INTO predictions (
filename,
top1_class,
confidence,
latency_ms,
timestamp
)
VALUES (?, ?, ?, ?, ?)
""", (
filename,
top1_class,
confidence,
latency_ms,
datetime.now().strftime("%Y-%m-%d %H:%M:%S")
))
conn.commit()
conn.close()