From 48be6986c27ee5a6734a544be01e2cb5c66463b3 Mon Sep 17 00:00:00 2001 From: Tomas Babej Date: Sat, 28 Feb 2015 01:43:30 +0100 Subject: [PATCH] Make tasks affect statistics of super-projects --- ChangeLog | 2 ++ src/commands/CmdProjects.cpp | 10 +++++++++- src/commands/CmdSummary.cpp | 35 +++++++++++++++++++++-------------- 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 06cd8fa42..009c569ed 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2.4.2 () - +- TW-41 Tasks in subprojects are not counted in project completion (thanks + to Renato Alves). - TW-1450 Projects command should trigger running garbage collector (thanks to Tomas Babej). - TW-1535 move default listing-break from list to ls (thanks to David Patrick). diff --git a/src/commands/CmdProjects.cpp b/src/commands/CmdProjects.cpp index 2edfdf0d6..1c69929cb 100644 --- a/src/commands/CmdProjects.cpp +++ b/src/commands/CmdProjects.cpp @@ -92,8 +92,16 @@ int CmdProjects::execute (std::string& output) continue; } + // Increase the count for the project the task belongs to and all + // its super-projects project = task->get ("project"); - unique[project] += 1; + + std::vector projects = extractParents (project); + projects.push_back (project); + + std::vector ::const_iterator parent; + for (parent = projects.begin (); parent != projects.end (); ++parent) + unique[*parent] += 1; if (project == "") no_project = true; diff --git a/src/commands/CmdSummary.cpp b/src/commands/CmdSummary.cpp index d012fb0dd..842948e33 100644 --- a/src/commands/CmdSummary.cpp +++ b/src/commands/CmdSummary.cpp @@ -92,27 +92,34 @@ int CmdSummary::execute (std::string& output) for (task = filtered.begin (); task != filtered.end (); ++task) { std::string project = task->get ("project"); - ++counter[project]; + std::vector projects = extractParents (project); + projects.push_back (project); + + std::vector ::const_iterator parent; + for (parent = projects.begin (); parent != projects.end (); ++parent) + ++counter[*parent]; if (task->getStatus () == Task::pending || task->getStatus () == Task::waiting) - { - ++countPending[project]; + for (parent = projects.begin (); parent != projects.end (); ++parent) + { + ++countPending[*parent]; - time_t entry = strtol (task->get ("entry").c_str (), NULL, 10); - if (entry) - sumEntry[project] = sumEntry[project] + (double) (now - entry); - } + time_t entry = strtol (task->get ("entry").c_str (), NULL, 10); + if (entry) + sumEntry[*parent] = sumEntry[*parent] + (double) (now - entry); + } else if (task->getStatus () == Task::completed) - { - ++countCompleted[project]; + for (parent = projects.begin (); parent != projects.end (); ++parent) + { + ++countCompleted[*parent]; - time_t entry = strtol (task->get ("entry").c_str (), NULL, 10); - time_t end = strtol (task->get ("end").c_str (), NULL, 10); - if (entry && end) - sumEntry[project] = sumEntry[project] + (double) (end - entry); - } + time_t entry = strtol (task->get ("entry").c_str (), NULL, 10); + time_t end = strtol (task->get ("end").c_str (), NULL, 10); + if (entry && end) + sumEntry[*parent] = sumEntry[*parent] + (double) (end - entry); + } }