Spaces:
Runtime error
Runtime error
| import uuid | |
| from datetime import datetime | |
| class GoalTracker: | |
| def __init__(self): | |
| self.goals = {} | |
| def add_goal(self, user_id: str, goal_text: str): | |
| goal_id = str(uuid.uuid4()) | |
| self.goals[goal_id] = { | |
| "user_id": user_id, | |
| "goal": goal_text, | |
| "created": datetime.utcnow().isoformat(), | |
| "subtasks": [], | |
| "completed": False | |
| } | |
| return goal_id | |
| def add_subtask(self, goal_id: str, task_text: str): | |
| if goal_id in self.goals: | |
| self.goals[goal_id]["subtasks"].append({"task": task_text, "done": False}) | |
| def complete_subtask(self, goal_id: str, index: int): | |
| if goal_id in self.goals and 0 <= index < len(self.goals[goal_id]["subtasks"]): | |
| self.goals[goal_id]["subtasks"][index]["done"] = True | |
| def list_goals(self, user_id: str): | |
| return {gid: g for gid, g in self.goals.items() if g["user_id"] == user_id} | |
| def mark_complete(self, goal_id: str): | |
| if goal_id in self.goals: | |
| self.goals[goal_id]["completed"] = True | |
| def summarize_goal(self, goal_id: str): | |
| g = self.goals.get(goal_id, {}) | |
| summary = f"π― Goal: {g.get('goal')}\n" | |
| for i, task in enumerate(g.get("subtasks", [])): | |
| check = "β " if task["done"] else "π²" | |
| summary += f"{check} {i+1}. {task['task']}\n" | |
| return summary.strip() | |