Autonomous-AI / goal_tracker.py
Leonydis137's picture
Upload goal_tracker.py
17b28b4 verified
raw
history blame
1.43 kB
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()