forked from k8pil/TTT25-private
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_eye_database.py
More file actions
67 lines (60 loc) · 1.91 KB
/
Copy pathcreate_eye_database.py
File metadata and controls
67 lines (60 loc) · 1.91 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import os
import sqlite3
from datetime import datetime
# Define the path to the instance directory and database file
instance_path = os.path.join(os.getcwd(), 'instance')
db_path = os.path.join(instance_path, 'eye.sqlite')
# Create the instance directory if it doesn't exist
os.makedirs(instance_path, exist_ok=True)
# Create the database and the eye_metrics table
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
# Create the eye_metrics table
cursor.execute('''
CREATE TABLE IF NOT EXISTS eye_metrics (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER,
session_id TEXT NOT NULL,
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,
hand_detection_count INTEGER DEFAULT 0,
hand_detection_duration REAL DEFAULT 0.0,
loss_eye_contact_count INTEGER DEFAULT 0,
looking_away_duration REAL DEFAULT 0.0,
bad_posture_count INTEGER DEFAULT 0,
bad_posture_duration REAL DEFAULT 0.0,
is_auto_save BOOLEAN DEFAULT 0,
FOREIGN KEY (user_id) REFERENCES user(id)
)
''')
# Insert a test record to verify it's working
cursor.execute('''
INSERT INTO eye_metrics (
user_id,
session_id,
timestamp,
hand_detection_count,
hand_detection_duration,
loss_eye_contact_count,
looking_away_duration,
bad_posture_count,
bad_posture_duration,
is_auto_save
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
''', (
1, # user_id (change if needed)
f"test_session_{datetime.now().strftime('%Y%m%d%H%M%S')}",
datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
5, # hand_detection_count
10.5, # hand_detection_duration
3, # loss_eye_contact_count
8.2, # looking_away_duration
2, # bad_posture_count
6.7, # bad_posture_duration
0 # is_auto_save (0 = False)
))
# Commit and close
conn.commit()
conn.close()
print(f"Database created at: {db_path}")
print("Eye metrics table created with test data.")
print(f"Directory contents: {os.listdir(instance_path)}")