X-Git-Url: https://us-delaporte.pagekite.me/gitweb/matrix-goal-bot.git/blobdiff_plain/4e1a9fea349dbabc177afde73208434130c16d13..3f63c010b3b94ebbad905c7bbf32196a31e58afa:/matrix_goal_bot/db.py diff --git a/matrix_goal_bot/db.py b/matrix_goal_bot/db.py index 533b684..9eabaf4 100644 --- a/matrix_goal_bot/db.py +++ b/matrix_goal_bot/db.py @@ -1,6 +1,7 @@ import logging import os from datetime import datetime as dt +from datetime import timedelta from sqlmodel import Field, Session, SQLModel, create_engine, select, text, Relationship @@ -28,7 +29,7 @@ class PreferGoal(SQLModel, table=True): class Goal(SQLModel, table=True): id: int | None = Field(default=None, primary_key=True) name: str = Field(default=None, unique=True) - start_date: dt | None = Field(default=today()) + start_date: dt | None = Field(default=dt.today()) complete_date: dt | None = Field(default=None) vision_id: int | None = Field(default=None, foreign_key="vision.id") notes: str | None = Field(default=None) @@ -41,6 +42,7 @@ class Goal(SQLModel, table=True): completed = self.complete_date.strftime(DATE_FORMAT) return f'(Done {completed}) {self.name} (Goal {self.id})' + class Task(SQLModel, table=True): id: int | None = Field(default=None, primary_key=True) name: str = Field(default=None, unique=True) @@ -51,6 +53,15 @@ class Task(SQLModel, table=True): return f'{self.name} ({self.id})' +class Win(SQLModel, table=True): + id: int | None = Field(default=None, primary_key=True) + goal: str = Field(default=None, unique=False) + vision: str | None = Field(default=None, unique=False) + complete_date: dt | None = Field(default=dt.today()) + def __str__(self): + completed = self.complete_date.strftime(DATE_FORMAT) + return f'{self.goal} ({completed} {self.vision})' + def pretty_print(goal, tasks): results = [] results.append(f' ## {goal}') @@ -134,9 +145,10 @@ class Data(): 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 <= today()) - # cmd = select(Goal).where(Goal.complete_date == None) - return session.exec(cmd).all() + 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 def get_done_goals(self): '''List completed goals''' @@ -177,6 +189,16 @@ class Data(): goal = session.exec(cmd).first() goal.complete_date = dt.today() vision_id = goal.vision_id + + cmd = select(Vision).where(Vision.id == vision_id) + win = Win() + win.goal = goal.name + + vision = session.exec(cmd).first() + if vision: + win.vision = vision.name + + session.add(win) session.commit() return vision_id @@ -281,7 +303,7 @@ class Data(): def visionless(self): '''Get goals with no vision''' with Session(self.engine) as session: - cmd = select(Goal).where(Goal.vision_id == None) + cmd = select(Goal).where(Goal.vision_id == None).where(Goal.complete_date == None) return session.exec(cmd).all() @@ -289,5 +311,12 @@ class Data(): '''Notes print with the goal.''' pass + + def wins(self): + results = [] + with Session(self.engine) as session: + results = session.exec(select(Win)).all() + return results + # Someday: Notes on each