| import sqlite3 |
| import random |
| from datetime import datetime, timedelta |
| import json |
|
|
| def seed_emergency_data(): |
| conn = sqlite3.connect('sentinel.db') |
| c = conn.cursor() |
| |
| |
| c.execute("SELECT COUNT(*) FROM sessions WHERE student_id IN ('101', '1430', '2024')") |
| count = c.fetchone()[0] |
| |
| if count == 0: |
| print("Seeding emergency data for demo...") |
| |
| student_ids = ['101', '1430', '2024'] |
| emotions = ['Happy', 'Neutral', 'Surprise', 'Calm'] |
| |
| now = datetime.now() |
| |
| for s_id in student_ids: |
| |
| for i in range(10): |
| |
| days_ago = random.randint(0, 30) |
| hours_ago = random.randint(0, 23) |
| session_time = now - timedelta(days=days_ago, hours=hours_ago) |
| |
| |
| engagement = round(random.uniform(40.0, 95.0), 1) |
| dom_emotion = random.choice(emotions) |
| |
| |
| c.execute( |
| "INSERT INTO sessions (student_id, start_time, end_time, avg_engagement, dominant_emotion) VALUES (?, ?, ?, ?, ?)", |
| (s_id, session_time.strftime("%Y-%m-%d %H:%M:%S"), (session_time + timedelta(minutes=10)).strftime("%Y-%m-%d %H:%M:%S"), engagement, dom_emotion) |
| ) |
| |
| session_id = c.lastrowid |
| |
| |
| c.execute( |
| "INSERT INTO student_performance (student_id, session_id, date, engagement_score, face_emotion, speech_emotion, text_sentiment, overall_summary) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", |
| (s_id, session_id, session_time.strftime("%Y-%m-%d"), engagement, |
| json.dumps({"Happy": 80}), json.dumps({"Happy": 70}), json.dumps({"positive": 90}), "Good session") |
| ) |
| |
| conn.commit() |
| print("Emergency data seeded successfully! Student IDs: 101, 1430, 2024 are ready.") |
| else: |
| print("Demo data already exists.") |
| |
| conn.close() |
|
|
| if __name__ == "__main__": |
| seed_emergency_data() |
|
|