Leonydis137 commited on
Commit
17b28b4
·
verified ·
1 Parent(s): 8fb51c4

Upload goal_tracker.py

Browse files
Files changed (1) hide show
  1. goal_tracker.py +41 -0
goal_tracker.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import uuid
3
+ from datetime import datetime
4
+
5
+ class GoalTracker:
6
+ def __init__(self):
7
+ self.goals = {}
8
+
9
+ def add_goal(self, user_id: str, goal_text: str):
10
+ goal_id = str(uuid.uuid4())
11
+ self.goals[goal_id] = {
12
+ "user_id": user_id,
13
+ "goal": goal_text,
14
+ "created": datetime.utcnow().isoformat(),
15
+ "subtasks": [],
16
+ "completed": False
17
+ }
18
+ return goal_id
19
+
20
+ def add_subtask(self, goal_id: str, task_text: str):
21
+ if goal_id in self.goals:
22
+ self.goals[goal_id]["subtasks"].append({"task": task_text, "done": False})
23
+
24
+ def complete_subtask(self, goal_id: str, index: int):
25
+ if goal_id in self.goals and 0 <= index < len(self.goals[goal_id]["subtasks"]):
26
+ self.goals[goal_id]["subtasks"][index]["done"] = True
27
+
28
+ def list_goals(self, user_id: str):
29
+ return {gid: g for gid, g in self.goals.items() if g["user_id"] == user_id}
30
+
31
+ def mark_complete(self, goal_id: str):
32
+ if goal_id in self.goals:
33
+ self.goals[goal_id]["completed"] = True
34
+
35
+ def summarize_goal(self, goal_id: str):
36
+ g = self.goals.get(goal_id, {})
37
+ summary = f"🎯 Goal: {g.get('goal')}\n"
38
+ for i, task in enumerate(g.get("subtasks", [])):
39
+ check = "✅" if task["done"] else "🔲"
40
+ summary += f"{check} {i+1}. {task['task']}\n"
41
+ return summary.strip()