- TW-72 extend info report with urgency column
This commit is contained in:
Paul Beckingham 2014-06-01 16:33:14 -04:00
parent a1ba10d820
commit 55b5149be0
5 changed files with 99 additions and 13 deletions

View file

@ -22,6 +22,7 @@
(thanks to Marton Suranyi). (thanks to Marton Suranyi).
- TW-5 color.due.today does not work (thanks to Max Muller). - TW-5 color.due.today does not work (thanks to Max Muller).
- TW-28 Inserts spaces before punctuation characters (thanks to Matt Kraai). - TW-28 Inserts spaces before punctuation characters (thanks to Matt Kraai).
- TW-72 extend info report with urgency column
- TW-115 allow "0day" durations for UDAs. - TW-115 allow "0day" durations for UDAs.
- TW-197 New virtual tag READY. - TW-197 New virtual tag READY.
- TW-253 Unrecognized taskwarrior file format. in - TW-253 Unrecognized taskwarrior file format. in

1
NEWS
View file

@ -11,6 +11,7 @@ New Features in taskwarrior 2.4.0
- Regular expressions are now enabled by default. - Regular expressions are now enabled by default.
- The 'filter' verbosity token shows the complete filter used for the last - The 'filter' verbosity token shows the complete filter used for the last
command. command.
- The 'info' report now breaks down urgency values.
New commands in taskwarrior 2.4.0 New commands in taskwarrior 2.4.0

View file

@ -163,18 +163,19 @@ private:
void parseLegacy (const std::string&); void parseLegacy (const std::string&);
void validate_before (const std::string&, const std::string&); void validate_before (const std::string&, const std::string&);
inline float urgency_priority () const; public:
inline float urgency_project () const; float urgency_priority () const;
inline float urgency_active () const; float urgency_project () const;
inline float urgency_scheduled () const; float urgency_active () const;
inline float urgency_waiting () const; float urgency_scheduled () const;
inline float urgency_blocked () const; float urgency_waiting () const;
inline float urgency_annotations () const; float urgency_blocked () const;
inline float urgency_tags () const; float urgency_annotations () const;
inline float urgency_next () const; float urgency_tags () const;
inline float urgency_due () const; float urgency_next () const;
inline float urgency_blocking () const; float urgency_due () const;
inline float urgency_age () const; float urgency_blocking () const;
float urgency_age () const;
}; };
#endif #endif

View file

@ -27,6 +27,7 @@
#include <cmake.h> #include <cmake.h>
#include <sstream> #include <sstream>
#include <stdlib.h> #include <stdlib.h>
#include <math.h>
#include <Context.h> #include <Context.h>
#include <Filter.h> #include <Filter.h>
#include <Date.h> #include <Date.h>
@ -38,6 +39,9 @@
#include <CmdInfo.h> #include <CmdInfo.h>
extern Context context; extern Context context;
static const float epsilon = 0.000001;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CmdInfo::CmdInfo () CmdInfo::CmdInfo ()
{ {
@ -317,7 +321,62 @@ int CmdInfo::execute (std::string& output)
// Task::urgency // Task::urgency
row = view.addRow (); row = view.addRow ();
view.set (row, 0, STRING_COLUMN_LABEL_URGENCY); view.set (row, 0, STRING_COLUMN_LABEL_URGENCY);
view.set (row, 1, trimLeft (format (task->urgency (), 4, 4)));
std::string urgency =
trimLeft (format (task->urgency (), 4, 4)) + "\n" +
urgencyTerm ("project", task->urgency_project (), Task::urgencyProjectCoefficient) +
urgencyTerm ("priority", task->urgency_priority (), Task::urgencyPriorityCoefficient) +
urgencyTerm ("active", task->urgency_active (), Task::urgencyActiveCoefficient) +
urgencyTerm ("scheduled", task->urgency_scheduled (), Task::urgencyScheduledCoefficient) +
urgencyTerm ("waiting", task->urgency_waiting (), Task::urgencyWaitingCoefficient) +
urgencyTerm ("blocked", task->urgency_blocked (), Task::urgencyBlockedCoefficient) +
urgencyTerm ("blocking", task->urgency_blocking (), Task::urgencyBlockingCoefficient) +
urgencyTerm ("annotations", task->urgency_annotations (), Task::urgencyAnnotationsCoefficient) +
urgencyTerm ("tags", task->urgency_tags (), Task::urgencyTagsCoefficient) +
urgencyTerm ("next", task->urgency_next (), Task::urgencyNextCoefficient) +
urgencyTerm ("due", task->urgency_due (), Task::urgencyDueCoefficient) +
urgencyTerm ("age", task->urgency_age (), Task::urgencyAgeCoefficient);
// Tag, Project- and UDA-specific coefficients.
std::map <std::string, float>::iterator var;
for (var = Task::coefficients.begin (); var != Task::coefficients.end (); ++var)
{
if (var->first.substr (0, 13) == "urgency.user.")
{
// urgency.user.project.<project>.coefficient
std::string::size_type end = std::string::npos;
if (var->first.substr (13, 8) == "project." &&
(end = var->first.find (".coefficient")) != std::string::npos)
{
std::string project = var->first.substr (21, end - 21);
if (task->get ("project").find (project) == 0)
urgency += urgencyTerm ("PROJECT " + project, 1.0, var->second);
}
// urgency.user.tag.<tag>.coefficient
if (var->first.substr (13, 4) == "tag." &&
(end = var->first.find (".coefficient")) != std::string::npos)
{
std::string name = var->first.substr (17, end - 17);
if (task->hasTag (name))
urgency += urgencyTerm ("TAG " + name, 1.0, var->second);
}
}
// urgency.uda.<name>.coefficient
else if (var->first.substr (0, 12) == "urgency.uda.")
{
std::string::size_type end = var->first.find (".coefficient");
if (end != std::string::npos)
{
std::string name = var->first.substr (12, end - 12);
if (task->has (name))
urgency += urgencyTerm ("UDA " + name, 1.0, var->second);
}
}
}
view.set (row, 1, urgency);
// Show any UDAs // Show any UDAs
std::vector <std::string> all = task->all (); std::vector <std::string> all = task->all ();
@ -455,3 +514,24 @@ int CmdInfo::execute (std::string& output)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
std::string CmdInfo::urgencyTerm (
const std::string& label,
float measure,
float coefficient) const
{
float value = measure * coefficient;
if (fabsf (value) > epsilon)
return std::string (
rightJustify (label, 20) +
" " +
leftJustify (format (measure, 5, 3), 6) +
" * " +
leftJustify (format (coefficient, 4, 2), 4) +
" = " +
leftJustify (format (value, 5, 3), 5) +
"\n");
return "";
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -35,6 +35,9 @@ class CmdInfo : public Command
public: public:
CmdInfo (); CmdInfo ();
int execute (std::string&); int execute (std::string&);
private:
std::string urgencyTerm (const std::string&, float, float) const;
}; };
#endif #endif