Commit d2b978c4 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Add function which calculates the Importance value.

parent b85075d4
"""
Provides a function to calculate the importance value of a task.
For those who are familiar with the Toodledo website, the importance value is a
combination of the priority and the todo's due date. Low priority tasks due
today may have a higher importance than high priority tasks in the distant
future.
"""
import Config
IMPORTANCE_VALUE = {'A': 3, 'B': 2, 'C': 1}
def importance(p_todo):
"""
Calculates the importance of the given task.
"""
result = 2
priority = p_todo.priority()
result += IMPORTANCE_VALUE[priority] if priority in IMPORTANCE_VALUE else 0
if p_todo.has_tag(Config.TAG_DUE):
days_left = p_todo.days_till_due()
if days_left >= 7 and days_left < 14:
result += 1
elif days_left >= 2 and days_left < 7:
result += 2
elif days_left >= 1 and days_left < 2:
result += 3
elif days_left >= 0 and days_left < 1:
result += 5
elif days_left < 0:
result += 6
if p_todo.has_tag(Config.TAG_STAR):
result += 1
return result
import datetime
import unittest
import Config
from Importance import importance
import Todo
class ImportanceTest(unittest.TestCase):
def test_importance1(self):
todo = Todo.Todo("Foo")
self.assertEqual(importance(todo), 2)
def test_importance2(self):
todo = Todo.Todo("(A) Foo")
self.assertEqual(importance(todo), 5)
def test_importance3(self):
todo = Todo.Todo("(A) Foo " + Config.TAG_STAR + ":1")
self.assertEqual(importance(todo), 6)
def test_importance4(self):
today_str = datetime.date.today().isoformat()
todo = Todo.Todo("(C) Foo " + Config.TAG_DUE + ":" + today_str)
self.assertEqual(importance(todo), 8)
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