-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseed_data.py
More file actions
96 lines (81 loc) · 4.09 KB
/
seed_data.py
File metadata and controls
96 lines (81 loc) · 4.09 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import random
import logging
from datetime import datetime, timedelta
from focusguard.db.database_manager import DatabaseManager
from focusguard.db.user_repo import UserRepo
from focusguard.db.session_repo import SessionRepo
from focusguard.db.app_usage_repo import AppUsageRepo, DistractionRepo
from focusguard.db.score_repo import ScoreRepo, TipRepo
from focusguard.config import SESSION
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("FocusGuard-Seeder")
def generate_dummy_data(num_users=5, sessions_per_user=15):
db_manager = DatabaseManager()
user_repo = UserRepo()
session_repo = SessionRepo()
usage_repo = AppUsageRepo()
distraction_repo = DistractionRepo()
score_repo = ScoreRepo()
tip_repo = TipRepo()
# 1. Seed Tips
tips = [
("The Pomodoro Technique: 25m focus, 5m break.", "Method"),
("Deep Work: Eliminate all distractions for 90m.", "Method"),
("Stay hydrated: Drink a glass of water every hour.", "Health"),
("Stretch your back and neck every 30 minutes.", "Health"),
("The 2-minute rule: If it takes < 2m, do it now.", "Productivity"),
("Use 'Eat the Frog': Do the hardest task first.", "Productivity"),
("Binaural beats can help increase concentration.", "Audio"),
("A clean workspace leads to a clear mind.", "Environment"),
]
for content, cat in tips:
tip_repo.add_tip(content, cat)
# 2. Seed Users
usernames = ["FocusMaster", "DeepWorkPro", "ZenCoder", "Sushant", "ProductivityNinja"]
for name in usernames:
try:
user_repo.create_user(name)
except Exception:
pass # User already exists
# 3. Generate Sessions and related data
for name in usernames:
user = user_repo.get_user_by_username(name)
if not user: continue
# Generate sessions over the last 30 days
for i in range(sessions_per_user):
# Random date in last 30 days
days_offset = random.randint(0, 30)
hours_offset = random.randint(8, 20) # Between 8am and 8pm
start_dt = datetime.now() - timedelta(days=days_offset)
start_time = start_dt.replace(hour=hours_offset, minute=random.randint(0, 59)).strftime("%Y-%m-%d %H:%M:%S")
# Session details
duration = random.randint(600, 3600) # 10 to 60 mins
state = "COMPLETED" if random.random() > 0.2 else "ABANDONED"
score = float(random.randint(40, 100)) if state == "COMPLETED" else None
session = session_repo.create_session(user.id, start_time, state)
session_repo.update_session(
session.id,
end_time=(datetime.strptime(start_time, "%Y-%m-%d %H:%M:%S") + timedelta(seconds=duration)).strftime("%Y-%m-%d %H:%M:%S"),
duration=duration,
state=state,
score=score
)
# Log usage and distractions for this session
# Focused app vs Distraction app
focused_app = random.choice(["VS Code", "PyCharm", "Notion", "Obsidian", "Terminal"])
distraction_app = random.choice(["Chrome", "Discord", "Twitter", "YouTube", "Instagram"])
# Add focused usage
usage_repo.log_usage(session.id, focused_app, duration * 0.8, start_time)
# Add a few distractions
num_distractions = random.randint(0, 5) if state == "COMPLETED" else random.randint(3, 10)
for _ in range(num_distractions):
distraction_repo.log_distraction(session.id, distraction_app, "BLOCKED_APP")
usage_repo.log_usage(session.id, distraction_app, 60, start_time) # each distraction 1 min
# Log the score
if score:
score_repo.add_score(user.id, session.id, score)
# Update user points based on session (simplified)
user_repo.update_points(user.id, 10 if state == "COMPLETED" else -5)
logger.info(f"Successfully seeded data for {num_users} users and approx {num_users * sessions_per_user} sessions.")
if __name__ == "__main__":
generate_dummy_data()