From: Christian Heller Date: Sun, 9 Jun 2024 02:31:20 +0000 (+0200) Subject: Add expression of summations of efforts in Day display. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/decks/%7B%7Bprefix%7D%7D/add_free?a=commitdiff_plain;h=f0f10048714c1bbcf23a7fa6a934d126408845f3;p=plomtask Add expression of summations of efforts in Day display. --- diff --git a/plomtask/http.py b/plomtask/http.py index 87f600a..4430016 100644 --- a/plomtask/http.py +++ b/plomtask/http.py @@ -144,6 +144,9 @@ class TaskHandler(BaseHTTPRequestHandler): """Show single Day of ?date=.""" date = self.params.get_str('date', date_in_n_days(0)) todays_todos = Todo.by_date(self.conn, date) + total_effort = 0 + for todo in todays_todos: + total_effort += todo.performed_effort conditions_present = [] enablers_for = {} disablers_for = {} @@ -161,6 +164,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, 'top_nodes': top_nodes, 'enablers_for': enablers_for, 'disablers_for': disablers_for, diff --git a/plomtask/todos.py b/plomtask/todos.py index de6438c..af45f72 100644 --- a/plomtask/todos.py +++ b/plomtask/todos.py @@ -177,6 +177,15 @@ class Todo(BaseModel[int], ConditionsRelations): return False return True + @property + def performed_effort(self) -> float: + """Return performed effort, i.e. self.effort or default if done..""" + if self.effort is not None: + return self.effort + if self.is_done: + return self.effort_then + return 0 + @property def process_id(self) -> int | str | None: """Needed for super().save to save Processes as attributes.""" @@ -244,6 +253,18 @@ class Todo(BaseModel[int], ConditionsRelations): return make_node(self) + @property + def tree_effort(self) -> float: + """Return sum of performed efforts of self and all descendants.""" + + def walk_tree(node: Todo) -> float: + local_effort = 0 + for child in node.children: + local_effort += walk_tree(child) + return node.performed_effort + local_effort + + return walk_tree(self) + def add_child(self, child: Todo) -> None: """Add child to self.children, avoid recursion, update parenthoods.""" diff --git a/templates/day.html b/templates/day.html index 6d927fd..93a430f 100644 --- a/templates/day.html +++ b/templates/day.html @@ -109,13 +109,14 @@ O  {% macro show_node_done(node, indent, path) %} {% if node.todo.has_doneness_in_path %} +{{node.todo.performed_effort}} +{{node.todo.tree_effort|round(1)}} {% for i in range(indent) %}    {% endfor %} + {% if not node.todo.is_done %}({% endif %}{{node.todo.title_then|e}}{% if not node.todo.is_done %}){% endif %} {{node.todo.comment|e}} - {% if not node.seen %} {% for child in node.children %} {{ show_node_done(child, indent+1) }} @@ -127,7 +128,7 @@ O  {% block content %} -

{{day.date}} / {{day.weekday}}

+

{{day.date}} / {{day.weekday}} ({{total_effort|round(1)}})

prev | next