Enhancement - stats

- Implemented stats report.
- Removed more obsolete code.
This commit is contained in:
Paul Beckingham 2009-06-11 00:44:31 -04:00
parent 7b9cb12308
commit d961dfda59
3 changed files with 24 additions and 84 deletions

View file

@ -165,9 +165,9 @@ void Context::dispatch ()
else if (cmd.command == "colors") { out = handleColor (); }
else if (cmd.command == "version") { out = handleVersion (); }
else if (cmd.command == "help") { out = longUsage (); }
else if (cmd.command == "stats") { out = handleReportStats (); }
/*
else if (command == "info") { out = handleInfo (); }
else if (command == "stats") { out = handleReportStats (); }
else if (command == "history") { out = handleReportHistory (); }
else if (command == "ghistory") { out = handleReportGHistory (); }
else if (command == "calendar") { out = handleReportCalendar (); }

View file

@ -153,67 +153,7 @@ std::string runTaskCommand (
bool gc /* = false */,
bool shadow /* = false */)
{
/*
// If argc == 1 and there is a default.command, use it. Otherwise use
// argc/argv.
std::string defaultCommand = context.config.get ("default.command");
if (args.size () == 0 || defaultCommand != "")
{
// Stuff the command line.
args.clear ();
split (args, defaultCommand, ' ');
std::cout << "[task " << defaultCommand << "]" << std::endl;
}
loadCustomReports ();
std::string command;
T task;
parse (args, command, task);
bool gcMod = false; // Change occurred by way of gc.
bool cmdMod = false; // Change occurred by way of command type.
*/
std::string out;
/*
// Read-only commands with no side effects.
if (command == "export") { out = handleExport (tdb, task); }
else if (command == "info") { out = handleInfo (tdb, task); }
else if (command == "stats") { out = handleReportStats (tdb, task); }
else if (command == "history") { out = handleReportHistory (tdb, task); }
else if (command == "ghistory") { out = handleReportGHistory (tdb, task); }
else if (command == "calendar") { out = handleReportCalendar (tdb, task); }
else if (command == "summary") { out = handleReportSummary (tdb, task); }
else if (command == "timesheet") { out = handleReportTimesheet (tdb, task); }
// Commands that cause updates.
else if (command == "" && task.getId ()) { cmdMod = true; out = handleModify (tdb, task); }
else if (command == "add") { cmdMod = true; out = handleAdd (tdb, task); }
else if (command == "append") { cmdMod = true; out = handleAppend (tdb, task); }
else if (command == "annotate") { cmdMod = true; out = handleAnnotate (tdb, task); }
else if (command == "done") { cmdMod = true; out = handleDone (tdb, task); }
else if (command == "undelete") { cmdMod = true; out = handleUndelete (tdb, task); }
else if (command == "delete") { cmdMod = true; out = handleDelete (tdb, task); }
else if (command == "start") { cmdMod = true; out = handleStart (tdb, task); }
else if (command == "stop") { cmdMod = true; out = handleStop (tdb, task); }
else if (command == "undo") { cmdMod = true; out = handleUndo (tdb, task); }
else if (command == "import") { cmdMod = true; out = handleImport (tdb, task); }
else if (command == "duplicate") { cmdMod = true; out = handleDuplicate (tdb, task); }
else if (command == "edit") { cmdMod = true; out = handleEdit (tdb, task); }
// Command that display IDs and therefore need TDB::gc first.
else if (command == "completed") { if (gc) gcMod = tdb.gc (); out = handleCompleted (tdb, task); }
else if (command == "next") { if (gc) gcMod = tdb.gc (); out = handleReportNext (tdb, task); }
else if (command == "active") { if (gc) gcMod = tdb.gc (); out = handleReportActive (tdb, task); }
else if (command == "overdue") { if (gc) gcMod = tdb.gc (); out = handleReportOverdue (tdb, task); }
else if (isCustomReport (command)) { if (gc) gcMod = tdb.gc (); out = handleCustomReport (tdb, task, command); }
// Only update the shadow file if such an update was not suppressed (shadow),
// and if an actual change occurred (gcMod || cmdMod).
if (shadow && (gcMod || cmdMod))
updateShadowFile (tdb);
*/
return out;
}

View file

@ -2241,11 +2241,11 @@ std::string handleReportStats ()
{
std::stringstream out;
/*
// Get all the tasks.
std::vector <T> tasks;
tdb.allT (tasks);
filter (tasks, task);
std::vector <Task> tasks;
context.tdb.lock (context.config.get ("locking", true));
context.tdb.load (tasks, context.filter);
context.tdb.unlock ();
Date now;
time_t earliest = time (NULL);
@ -2262,31 +2262,31 @@ std::string handleReportStats ()
std::map <std::string, int> allTags;
std::map <std::string, int> allProjects;
std::vector <T>::iterator it;
std::vector <Task>::iterator it;
for (it = tasks.begin (); it != tasks.end (); ++it)
{
++totalT;
if (it->getStatus () == T::deleted) ++deletedT;
if (it->getStatus () == T::pending) ++pendingT;
if (it->getStatus () == T::completed) ++completedT;
if (it->getStatus () == T::recurring) ++recurringT;
if (it->getStatus () == Task::deleted) ++deletedT;
if (it->getStatus () == Task::pending) ++pendingT;
if (it->getStatus () == Task::completed) ++completedT;
if (it->getStatus () == Task::recurring) ++recurringT;
time_t entry = ::atoi (it->getAttribute ("entry").c_str ());
time_t entry = ::atoi (it->get ("entry").c_str ());
if (entry < earliest) earliest = entry;
if (entry > latest) latest = entry;
if (it->getStatus () == T::completed)
if (it->getStatus () == Task::completed)
{
time_t end = ::atoi (it->getAttribute ("end").c_str ());
time_t end = ::atoi (it->get ("end").c_str ());
daysPending += (end - entry) / 86400.0;
}
if (it->getStatus () == T::pending)
if (it->getStatus () == Task::pending)
daysPending += (now - entry) / 86400.0;
descLength += it->getDescription ().length ();
descLength += it->get ("description").length ();
std::map <time_t, std::string> annotations;
std::vector <Att> annotations;
it->getAnnotations (annotations);
annotationsT += annotations.size ();
@ -2297,7 +2297,7 @@ std::string handleReportStats ()
foreach (t, tags)
allTags[*t] = 0;
std::string project = it->getAttribute ("project");
std::string project = it->get ("project");
if (project != "")
allProjects[project] = 0;
}
@ -2424,7 +2424,7 @@ std::string handleReportStats ()
out << optionalBlankLine ()
<< table.render ()
<< optionalBlankLine ();
*/
return out.str ();
}