Commit 0a6c7eda authored by Bram Schoenmakers's avatar Bram Schoenmakers

Fix average importance.

Make sure not to make the importance lower than the todos own
importance due to the its parents.

Test case and code were both wrong.
parent 2befec11
...@@ -75,12 +75,17 @@ def importance(p_todo, p_ignore_weekend=False): ...@@ -75,12 +75,17 @@ def importance(p_todo, p_ignore_weekend=False):
return result if not p_todo.is_completed() else 0 return result if not p_todo.is_completed() else 0
def average_importance(p_todo, p_ignore_weekend=False): def average_importance(p_todo, p_ignore_weekend=False):
sum_importance = importance(p_todo, p_ignore_weekend) own_importance = importance(p_todo, p_ignore_weekend)
average = 0
parents = [] parents = []
if 'parents' in p_todo.attributes: if 'parents' in p_todo.attributes:
sum_importance = own_importance
parents = p_todo.attributes['parents'] parents = p_todo.attributes['parents']
for parent in parents: for parent in parents:
sum_importance += importance(parent, p_ignore_weekend) sum_importance += importance(parent, p_ignore_weekend)
return float(sum_importance) / float(1 + len(parents)) average = float(sum_importance) / float(1 + len(parents))
return max(own_importance, average)
(A) Important child task p:1 p:2 ((5+4+2)/3=3.67 -> 5)
(B) Normal task (4) (B) Normal task (4)
(C) Less important child task p:1 p:2 ((3+0+0)/3=1 -> 3) (B) Another relatively important task id:2 (4)
(D) Not-so important parent task id:1 (2) (D) Not-so important parent task id:1 (2)
(D) Another not-so important task id:2 (2)
(B) Normal task (4) (B) Normal task (4)
(D) Not-so important parent task id:1 (2) (D) Not-so important parent task id:1 (2)
(D) Another not-so important task id:2 (2) (B) Another relatively important task id:2 (4)
(C) Less important child task p:1 p:2 ((3+0+0)/3=1 -> 3) (A) Important child task p:1 p:2 ((5+4+2)/3=3.67 -> 5)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment