Use only the current interval duration when summarizing

There are several instances where the "total" reported in the interval
summary is confusing because the summarize function would walk backward
and add all intervals with the same set of tags.

Closes #248 and #308

Signed-off-by: Shaun Ruffell <sruffell@sruffell.net>
This commit is contained in:
Shaun Ruffell 2020-08-14 07:16:13 -05:00 committed by Thomas Lauf
parent 7405d2be96
commit 9d43727c09
8 changed files with 10 additions and 32 deletions

View file

@ -121,7 +121,7 @@ int CmdContinue (
}
if (verbose)
{
std::cout << intervalSummarize (database, rules, to_copy);
std::cout << intervalSummarize (rules, to_copy);
}
return 0;

View file

@ -41,7 +41,7 @@ int CmdDefault (Rules& rules, Database& database)
{
if (verbose)
{
std::cout << intervalSummarize (database, rules, interval);
std::cout << intervalSummarize (rules, interval);
}
return 0;

View file

@ -65,7 +65,7 @@ int CmdStart (
}
if (verbose)
{
std::cout << intervalSummarize (database, rules, interval);
std::cout << intervalSummarize (rules, interval);
}
return 0;

View file

@ -110,7 +110,7 @@ int CmdStop (
if (verbose)
{
std::cout << intervalSummarize (database, rules, interval);
std::cout << intervalSummarize (rules, interval);
}
}
}
@ -127,7 +127,7 @@ int CmdStop (
if (verbose)
{
std::cout << '\n' << intervalSummarize (database, rules, next);
std::cout << '\n' << intervalSummarize (rules, next);
}
}

View file

@ -55,7 +55,7 @@ int CmdTrack (
database.addInterval (interval, verbose);
if (verbose)
std::cout << intervalSummarize (database, rules, interval);
std::cout << intervalSummarize (rules, interval);
}
journal.endTransaction ();

View file

@ -72,35 +72,13 @@ Color tagColor (const Rules& rules, const std::string& tag)
////////////////////////////////////////////////////////////////////////////////
// Summarize either an active or closed interval, for user feedback.
std::string intervalSummarize (
Database& database,
const Rules& rules,
const Interval& interval)
std::string intervalSummarize (const Rules& rules, const Interval& interval)
{
std::stringstream out;
if (interval.is_started ())
{
// Walk backwards through the inclusions, and stop as soon as the tags
// no longer match interval. This means the 'total' is the sum of all time
// in the most recent set of intervals for the same tags. This is the
// acceptable definition of "the current task".
time_t total_recorded = 0;
for (auto& line : database)
{
Interval current = IntervalFactory::fromSerialization (line);
if (interval.tags () == current.tags ())
{
total_recorded += current.total ();
}
else
{
break;
}
}
Duration total (total_recorded);
Duration total (interval.total ());
// Combine and colorize tags.
std::string tags;

View file

@ -71,7 +71,7 @@ int dispatchCommand (const CLI&, Database&, Journal&, Rules&, const Extensions&)
// helper.cpp
Color intervalColor (const std::set <std::string>&, const std::map <std::string, Color>&);
Color tagColor (const Rules&, const std::string&);
std::string intervalSummarize (Database&, const Rules&, const Interval&);
std::string intervalSummarize (const Rules&, const Interval&);
bool expandIntervalHint (const std::string&, Range&);
std::string jsonFromIntervals (const std::vector <Interval>&);
Palette createPalette (const Rules&);

View file

@ -118,7 +118,7 @@ static bool autoAdjust (
database.addInterval (interval, verbose);
if (verbose)
{
std::cout << intervalSummarize (database, rules, interval);
std::cout << intervalSummarize (rules, interval);
}
}
}