Implemented non-cumulative burndown reports and added a test for them.

This commit is contained in:
DanielMowitz 2021-08-06 13:31:10 +02:00 committed by Tomas Babej
parent 0bc92d6115
commit 1d804ae7c8
2 changed files with 43 additions and 39 deletions

View file

@ -235,6 +235,7 @@ void Chart::scan (std::vector <Task>& tasks)
Datetime now; Datetime now;
time_t epoch; time_t epoch;
bool cumulative = !Context::getContext ().config.getBoolean ("burndown.nc");
for (auto& task : tasks) for (auto& task : tasks)
{ {
// The entry date is when the counting starts. // The entry date is when the counting starts.
@ -292,50 +293,44 @@ void Chart::scan (std::vector <Task>& tasks)
if (_bars.find (epoch) != _bars.end ()) if (_bars.find (epoch) != _bars.end ())
++_bars[epoch]._removed; ++_bars[epoch]._removed;
if (cumulative)
{
// Maintain a running total of 'done' tasks that are off the left of the // Maintain a running total of 'done' tasks that are off the left of the
// chart. // chart.
if (end < _earliest) if (end < _earliest)
{ {
++_carryover_done; ++_carryover_done;
continue; continue;
}
while (from < end)
{
epoch = from.toEpoch ();
if (_bars.find (epoch) != _bars.end ())
++_bars[epoch]._pending;
from = increment (from, _period);
}
while (from < now)
{
epoch = from.toEpoch ();
if (_bars.find (epoch) != _bars.end ())
++_bars[epoch]._done;
from = increment (from, _period);
}
} }
while (from < end) else
{ {
epoch = from.toEpoch (); while (from < end)
if (_bars.find (epoch) != _bars.end ()) {
++_bars[epoch]._pending; if (_bars.find (epoch) != _bars.end ())
from = increment (from, _period); ++_bars[epoch]._pending;
} from = increment (from, _period);
epoch = from.toEpoch ();
while (from < now) if (_bars.find (epoch) != _bars.end ())
{ ++_bars[epoch]._done;
epoch = from.toEpoch (); }
if (_bars.find (epoch) != _bars.end ())
++_bars[epoch]._done;
from = increment (from, _period);
}
}
// e--D e--s--D
// ppp pppsss
else if (status == Task::deleted)
{
// Skip old deleted tasks.
Datetime end = quantize (Datetime (task.get_date ("end")), _period);
epoch = end.toEpoch ();
if (_bars.find (epoch) != _bars.end ())
++_bars[epoch]._removed;
if (end < _earliest)
continue;
while (from < end)
{
epoch = from.toEpoch ();
if (_bars.find (epoch) != _bars.end ())
++_bars[epoch]._pending;
from = increment (from, _period);
} }
} }
} }

View file

@ -64,6 +64,15 @@ class TestBurndownCommand(TestCase):
self.assertIn("+", out) self.assertIn("+", out)
self.assertIn("X", out) self.assertIn("X", out)
def test_burndown_daily_non_cumulative(self):
"""Ensure burndown.daily in non-cumulative mode generates a chart"""
self.t.config("burndown.nc", True)
code, out, err = self.t("burndown.daily")
self.assertIn("Daily Burndown", out)
self.assertIn(".", out)
self.assertIn("+", out)
self.assertIn("X", out)
def test_burndown_daily_color(self): def test_burndown_daily_color(self):
"""Ensure burndown.daily with color, generates a chart""" """Ensure burndown.daily with color, generates a chart"""
code, out, err = self.t("burndown.daily rc._forcecolor:on") code, out, err = self.t("burndown.daily rc._forcecolor:on")