From 69fecbb2c045115a567a19da4e8f6ccb8db51ea7 Mon Sep 17 00:00:00 2001 From: Johannes Schlatow Date: Sat, 17 Dec 2011 19:08:31 +0100 Subject: [PATCH] Urgency - Age-dependet urgency calculation now normalizes. --- doc/man/taskrc.5.in | 5 ++--- src/Config.cpp | 2 +- src/Task.cpp | 25 +++++++++++-------------- src/Task.h | 2 +- 4 files changed, 15 insertions(+), 19 deletions(-) diff --git a/doc/man/taskrc.5.in b/doc/man/taskrc.5.in index 44469db7a..fa0d8fa92 100644 --- a/doc/man/taskrc.5.in +++ b/doc/man/taskrc.5.in @@ -961,10 +961,9 @@ Urgency coefficients for annotations .RS Urgency coefficients for the age of tasks .RE -.B urgency.age.max=0.0 +.B urgency.age.max=365 .RS -Maximum (or minimum if negative) urgency a task can reach due to aging. If -this is set to zero, the term will be unlimited. +Maximum age in days. After this number of days has elapsed, the urgency of a task won't increase any more because of aging. .RE The coefficients reflect the relative importance of the various terms in the diff --git a/src/Config.cpp b/src/Config.cpp index 53a02fad1..f497623b8 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -148,7 +148,7 @@ std::string Config::_defaults = "urgency.tags.coefficient=2.0 # Urgency coefficients for tags\n" "urgency.annotations.coefficient=1.0 # Urgency coefficients for annotations\n" "urgency.age.coefficient=0 # Urgency coefficients for age\n" - "urgency.age.max=0 # Maximum urgency offset for age\n" + "urgency.age.max=365 # Maximum age in days\n" "\n" "#urgency.user.project.foo.coefficient=5.0 # Urgency coefficients for 'foo' project\n" "#urgency.user.tag.foo.coefficient=5.0 # Urgency coefficients for 'foo' tag\n" diff --git a/src/Task.cpp b/src/Task.cpp index dc36db880..641d5b6f1 100644 --- a/src/Task.cpp +++ b/src/Task.cpp @@ -1231,8 +1231,7 @@ float Task::urgency_c () const value += urgency_next () * context.config.getReal ("urgency.next.coefficient"); value += urgency_due () * context.config.getReal ("urgency.due.coefficient"); value += urgency_blocking () * context.config.getReal ("urgency.blocking.coefficient"); - value += urgency_age (context.config.getReal ("urgency.age.coefficient"), - context.config.getReal ("urgency.age.max")); + value += urgency_age () * context.config.getReal ("urgency.age.coefficient"); // Tag- and project-specific coefficients. std::vector all; @@ -1402,24 +1401,22 @@ float Task::urgency_due () const } //////////////////////////////////////////////////////////////////////////////// -float Task::urgency_age (float coefficient, float max) const +float Task::urgency_age () const { - if (coefficient == 0) { - return 0.0; - } - else if (has ("entry")) + if (has ("entry")) { Date now; Date entry (get_date ("entry")); + int age = (now - entry) / 86400; // in days + float max = context.config.getReal ("urgency.age.max"); - int age = (now - entry) / 86400; - float result = age * coefficient; - if (max == 0) // unlimited - return result; - else if (max > 0) - return (result > max) ? max : result; + if (max == 0) + return 1.0; + + if (age > max) + return 1.0; else - return (result < max) ? max : result; + return (1.0 * age/max); } return 0.0; diff --git a/src/Task.h b/src/Task.h index 08f0760e9..4196f4536 100644 --- a/src/Task.h +++ b/src/Task.h @@ -117,7 +117,7 @@ private: inline float urgency_next () const; inline float urgency_due () const; inline float urgency_blocking () const; - inline float urgency_age (float, float) const; + inline float urgency_age () const; }; #endif