mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
CmdBurndown
- Migrated util.cpp round_up_to and burndown_size functions to CmdBurndown, as they are only called once.
This commit is contained in:
parent
4f54578241
commit
ab95ef5ba5
1 changed files with 47 additions and 0 deletions
|
@ -27,6 +27,7 @@
|
||||||
#include <cmake.h>
|
#include <cmake.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <limits>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <Context.h>
|
#include <Context.h>
|
||||||
|
@ -158,6 +159,8 @@ private:
|
||||||
void maxima ();
|
void maxima ();
|
||||||
void yLabels (std::vector <int>&);
|
void yLabels (std::vector <int>&);
|
||||||
void calculateRates (std::vector <time_t>&);
|
void calculateRates (std::vector <time_t>&);
|
||||||
|
unsigned round_up_to (unsigned, unsigned);
|
||||||
|
unsigned burndown_size (unsigned);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int _width; // Terminal width
|
int _width; // Terminal width
|
||||||
|
@ -964,6 +967,50 @@ void Chart::calculateRates (std::vector <time_t>& sequence)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
unsigned Chart::round_up_to (unsigned n, unsigned target)
|
||||||
|
{
|
||||||
|
return n + target - (n % target);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
unsigned Chart::burndown_size (unsigned ntasks)
|
||||||
|
{
|
||||||
|
// Nearest 2
|
||||||
|
if (ntasks < 20)
|
||||||
|
return round_up_to (ntasks, 2);
|
||||||
|
|
||||||
|
// Nearest 10
|
||||||
|
if (ntasks < 50)
|
||||||
|
return round_up_to (ntasks, 10);
|
||||||
|
|
||||||
|
// Nearest 20
|
||||||
|
if (ntasks < 100)
|
||||||
|
return round_up_to (ntasks, 20);
|
||||||
|
|
||||||
|
// Choose the number from here rounded up to the nearest 10% of the next
|
||||||
|
// highest power of 10 or half of power of 10.
|
||||||
|
const unsigned count = (unsigned) log10 (std::numeric_limits<unsigned>::max ());
|
||||||
|
unsigned half = 500;
|
||||||
|
unsigned full = 1000;
|
||||||
|
|
||||||
|
// We start at two because we handle 5, 10, 50, and 100 above.
|
||||||
|
for (unsigned i = 2; i < count; ++i)
|
||||||
|
{
|
||||||
|
if (ntasks < half)
|
||||||
|
return round_up_to (ntasks, half / 10);
|
||||||
|
|
||||||
|
if (ntasks < full)
|
||||||
|
return round_up_to (ntasks, full / 10);
|
||||||
|
|
||||||
|
half *= 10;
|
||||||
|
full *= 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Round up to max of unsigned.
|
||||||
|
return std::numeric_limits<unsigned>::max ();
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CmdBurndownMonthly::CmdBurndownMonthly ()
|
CmdBurndownMonthly::CmdBurndownMonthly ()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue