home · contact · privacy
Add expression of summations of efforts in Day display.
authorChristian Heller <c.heller@plomlompom.de>
Sun, 9 Jun 2024 02:31:20 +0000 (04:31 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Sun, 9 Jun 2024 02:31:20 +0000 (04:31 +0200)
plomtask/http.py
plomtask/todos.py
templates/day.html

index 87f600a73c03f55bb3bb51cfbb3d79444d3b687e..44300166f0cc5d91fbdfe0c532dcf01c9d3e87e6 100644 (file)
@@ -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,
index de6438c1e248777f388a1e8217b7fc059c851c2c..af45f720ca6e2011fb52bd5af18582a2feca76f1 100644 (file)
@@ -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."""
 
index 6d927fdb1c09ab1f2d1fc1e9fa48a0bfef814b20..93a430f56ccbc0eca01386482034a7a50f29cdc2 100644 (file)
@@ -109,13 +109,14 @@ O&nbsp;
 {% macro show_node_done(node, indent, path) %}
 {% if node.todo.has_doneness_in_path %}
 <tr{% if not node.todo.is_done %} class="hidden_undone"{% endif %}>
+<td>{{node.todo.performed_effort}}</td>
+<td>{{node.todo.tree_effort|round(1)}}</td>
 <td>
 {% for i in range(indent) %}&nbsp; &nbsp; {% endfor %} +
 {% if not node.todo.is_done %}({% endif %}<a href="todo?id={{node.todo.id_}}">{{node.todo.title_then|e}}</a>{% if not node.todo.is_done %}){% endif %}
 </td>
 <td>{{node.todo.comment|e}}</td>
 </tr>
-
 {% if not node.seen %}
 {% for child in node.children %}
 {{ show_node_done(child, indent+1) }}
@@ -127,7 +128,7 @@ O&nbsp;
 
 
 {% block content %}
-<h3>{{day.date}} / {{day.weekday}}</h3>
+<h3>{{day.date}} / {{day.weekday}} ({{total_effort|round(1)}})</h3>
 <p>
 <a href="day?date={{day.prev_date}}">prev</a> | <a href="day?date={{day.next_date}}">next</a>
 </p>