From: Christian Heller Date: Fri, 14 Jun 2024 12:26:11 +0000 (+0200) Subject: Refactor total-effort day summation. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/static/templates?a=commitdiff_plain;h=81e1ac998001bedd8a739e6458c7ed30e474c0da;p=plomtask Refactor total-effort day summation. --- diff --git a/plomtask/http.py b/plomtask/http.py index 3d507be..5ad3dd4 100644 --- a/plomtask/http.py +++ b/plomtask/http.py @@ -209,9 +209,6 @@ class TaskHandler(BaseHTTPRequestHandler): date = self._params.get_str('date', date_in_n_days(0)) make_type = self._params.get_str('make_type') todays_todos = Todo.by_date(self.conn, date) - total_effort = 0.0 - for todo in todays_todos: - total_effort += todo.performed_effort conditions_present = [] enablers_for = {} disablers_for = {} @@ -229,7 +226,7 @@ class TaskHandler(BaseHTTPRequestHandler): top_nodes = [t.get_step_tree(seen_todos) for t in todays_todos if not t.parents] return {'day': Day.by_id(self.conn, date, create=True), - 'total_effort': total_effort, + 'total_effort': Todo.total_effort_at_date(self.conn, date), 'top_nodes': top_nodes, 'make_type': make_type, 'enablers_for': enablers_for, diff --git a/plomtask/todos.py b/plomtask/todos.py index 0125b97..008f7a2 100644 --- a/plomtask/todos.py +++ b/plomtask/todos.py @@ -23,6 +23,7 @@ class TodoNode: class Todo(BaseModel[int], ConditionsRelations): """Individual actionable.""" # pylint: disable=too-many-instance-attributes + # pylint: disable=too-many-public-methods table_name = 'todos' to_save = ['process_id', 'is_done', 'date', 'comment', 'effort', 'calendarize'] @@ -154,6 +155,16 @@ class Todo(BaseModel[int], ConditionsRelations): """Collect all Todos for Day of date.""" return cls.by_date_range(db_conn, (date, date)) + @classmethod + def total_effort_at_date(cls, db_conn: DatabaseConnection, date: str + ) -> float: + """Sum all .performed_effort of Todos at Day of date.""" + total_effort = 0.0 + days_todos = cls.by_date(db_conn, date) + for todo in days_todos: + total_effort += todo.performed_effort + return total_effort + @property def is_doable(self) -> bool: """Decide whether .is_done settable based on children, Conditions."""