]> apps.delaporte.us Git - matrix-goal-bot.git/commitdiff
List goals by vision
authorEdward Delaporte <edward@delaporte.us>
Sat, 6 Jun 2026 19:10:30 +0000 (14:10 -0500)
committerEdward Delaporte <edward@delaporte.us>
Sat, 6 Jun 2026 19:10:30 +0000 (14:10 -0500)
matrix_goal_bot/db.py
matrix_goal_bot/tasks.py

index 9eabaf4cf7cedb8e2cd40d50f928da1a7ad909ae..9676cc3202c3679fb8a63cd46d95c216d811d4b2 100644 (file)
@@ -2,6 +2,7 @@ import logging
 import os
 from datetime import datetime as dt
 from datetime import timedelta
 import os
 from datetime import datetime as dt
 from datetime import timedelta
+from typing import List
 
 from sqlmodel import Field, Session, SQLModel, create_engine, select, text, Relationship
 
 
 from sqlmodel import Field, Session, SQLModel, create_engine, select, text, Relationship
 
@@ -83,6 +84,22 @@ def _get_with_name(cls, name):
     return select(cls).where(func.lower(cls.name) == func.lower(name))
 
 
     return select(cls).where(func.lower(cls.name) == func.lower(name))
 
 
+def _get_goals_by_vision(goals) -> List[str]:
+    results = []
+    visions = {}
+
+    for goal in goals:
+        vision = str(goal.vision)
+        if not vision in visions:
+            visions[vision] = []
+        visions[vision].append(str(goal))
+    for vision in visions:
+        results.append(f' ## {vision}')
+        for item in visions[vision]:
+            results.append(item)
+    return results
+
+
 class Data():
     def __init__(self, db_file=None):
         if not db_file:
 class Data():
     def __init__(self, db_file=None):
         if not db_file:
@@ -136,26 +153,30 @@ class Data():
             cmd = select(Vision).where(Vision.complete_date == None)
             return session.exec(cmd).all()
 
             cmd = select(Vision).where(Vision.complete_date == None)
             return session.exec(cmd).all()
 
-    def get_all_goals(self):
+    def get_all_goals(self) -> List[str]:
         '''List all goals'''
         '''List all goals'''
+        results = []
         with Session(self.engine) as session:
             cmd = select(Goal).where(Goal.complete_date == None)
         with Session(self.engine) as session:
             cmd = select(Goal).where(Goal.complete_date == None)
-            return session.exec(cmd).all()
+            goals = session.exec(cmd).all()
+            results.append(_get_goals_by_vision(goals))
+        return results
+
 
     def get_current_goals(self):
         '''List current goals'''
         with Session(self.engine) as session:
             cmd = select(Goal).where(Goal.complete_date == None).where(Goal.start_date <= dt.today())
 
     def get_current_goals(self):
         '''List current goals'''
         with Session(self.engine) as session:
             cmd = select(Goal).where(Goal.complete_date == None).where(Goal.start_date <= dt.today())
-            results = session.exec(cmd).all()
-            logger.debug(f'Current goals: {results}')
-            return results
+            goals = session.exec(cmd).all()
+            logger.debug(f'Current goals: {goals}')
+            return _get_goals_by_vision(goals)
 
     def get_done_goals(self):
         '''List completed goals'''
         with Session(self.engine) as session:
             cmd = select(Goal).where(Goal.complete_date != None)
 
     def get_done_goals(self):
         '''List completed goals'''
         with Session(self.engine) as session:
             cmd = select(Goal).where(Goal.complete_date != None)
-            return session.exec(cmd).all()
-
+            goals = session.exec(cmd).all()
+            return _get_goals_by_vision(goals)
 
     def get_goal(self, goal_id):
         self._set_pref_goal_id(goal_id)
 
     def get_goal(self, goal_id):
         self._set_pref_goal_id(goal_id)
@@ -299,6 +320,7 @@ class Data():
             goal = session.exec(cmd).first()
             goal.vision_id = vision_id
             session.commit()
             goal = session.exec(cmd).first()
             goal.vision_id = vision_id
             session.commit()
+        return True
 
     def visionless(self):
         '''Get goals with no vision'''
 
     def visionless(self):
         '''Get goals with no vision'''
index 9784b42ce6af07772d92c19a497e4a90c5a0bc54..61413ec98ae57928e3afabbc5f5924e0422aae47 100644 (file)
@@ -12,6 +12,12 @@ def add_goal(c, name):
     result = Data().add_goal(name)
     print(result)
 
     result = Data().add_goal(name)
     print(result)
 
+@task
+def add_vision(c, name):
+    result = Data().add_vision(name)
+    print(result)
+
+
 @task
 def close_goal(c, goal_id):
     result = Data().complete_goal(goal_id)
 @task
 def close_goal(c, goal_id):
     result = Data().complete_goal(goal_id)
@@ -47,6 +53,14 @@ def list(c):
     for goal in goals:
         print(goal)
 
     for goal in goals:
         print(goal)
 
+
+@task
+def list_visions(c):
+    items = Data().get_all_visions()
+    for item in items:
+        print(item)
+
+
 @task
 def later(c, goal_id):
     result = Data().put_off_goal(goal_id)
 @task
 def later(c, goal_id):
     result = Data().put_off_goal(goal_id)
@@ -104,3 +118,7 @@ def wins(c):
     for line in results:
         print(line)
 
     for line in results:
         print(line)
 
+@task
+def assign_to_vision(c, goal_id, vision_id):
+    result = Data().assign_vision(goal_id, vision_id)
+    print(result)