Commit 3715527a authored by Bram Schoenmakers's avatar Bram Schoenmakers

In case a todo has parents, use the max progress of all its parents

The parent color is only used when the todo item has not enough information to
determine its own progress.
parent 8163a029
......@@ -21,6 +21,7 @@ from test.topydo_testcase import TopydoTest
from topydo.lib.Config import config
from topydo.lib.ProgressColor import progress_color
from topydo.lib.Todo import Todo
from topydo.lib.TodoList import TodoList
def set_256_colors():
config(p_overrides={('topydo', 'colors'): '256'})
......@@ -186,5 +187,43 @@ class ProgressColorTest(TopydoTest):
# a length of 14 days is assumed
self.assertEqual(color.color, 208)
def test_progress28(self):
""" Progress color determined by parent """
todolist = TodoList([
"Overdue id:1 due:2015-12-31",
"Bar p:1",
])
color = progress_color(todolist.todo(2))
# color the subitem red because it has no color of its own and its
# parent is overdue
self.assertEqual(color.color, 1)
def test_progress29(self):
""" Progress color determined by parent """
todolist = TodoList([
"Overdue id:1 due:2015-12-31",
"Bar p:1 t:2016-01-01 due:2016-01-01",
])
color = progress_color(todolist.todo(2))
# the parent has no influence here
self.assertEqual(color.color, 3)
def test_progress30(self):
""" Progress color determined by parent """
todolist = TodoList([
"Foo id:1",
"Bar p:1",
])
color = progress_color(todolist.todo(2))
# the parent has no influence here
self.assertEqual(color.color, 2)
if __name__ == '__main__':
unittest.main()
......@@ -77,11 +77,21 @@ def progress_color(p_todo):
# a todo item is at least one day long
return max(1, result)
def get_progress():
def get_progress(p_todo, p_consider_parents=True):
"""
Returns a value from 0 to 1 where we are today in a date range. Returns
a value >1 when a todo item is overdue.
"""
def progress_of_parents():
try:
parents = p_todo.parents()
except AttributeError:
parents = []
if parents:
return max(get_progress(parent, False) for parent in parents)
else:
return 0
if p_todo.is_overdue():
return 1.1
......@@ -89,11 +99,13 @@ def progress_color(p_todo):
days_till_due = p_todo.days_till_due()
length = get_length()
return max((length - days_till_due), 0) / length
elif p_consider_parents:
return progress_of_parents()
else:
return 0
color_range = color256_range if config().colors() == 256 else color16_range
progress = get_progress()
progress = get_progress(p_todo)
# TODO: remove linear scale to exponential scale
if progress > 1:
......
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