Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
topydo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
topydo
Commits
d2b978c4
Commit
d2b978c4
authored
Jun 14, 2014
by
Bram Schoenmakers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add function which calculates the Importance value.
parent
b85075d4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
0 deletions
+64
-0
Importance.py
Importance.py
+40
-0
test/ImportanceTest.py
test/ImportanceTest.py
+24
-0
No files found.
Importance.py
0 → 100644
View file @
d2b978c4
"""
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
test/ImportanceTest.py
0 → 100644
View file @
d2b978c4
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
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment