X-Git-Url: https://plomlompom.com/repos/berlin_corona.txt?a=blobdiff_plain;f=plomtask%2Ftodos.py;h=fa009b12b8fb64e42b8a42f728fd0d4fb1740367;hb=344d6c234e50953b36ac9fed2cfce8d4ba64a5b3;hp=de6438c1e248777f388a1e8217b7fc059c851c2c;hpb=48ed70167c50303f46309c5808f93f2ba169b34f;p=plomtask diff --git a/plomtask/todos.py b/plomtask/todos.py index de6438c..fa009b1 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'] @@ -177,6 +178,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 +254,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.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."""