[PATCH] Compute the height of a burndown chart

Signed-off-by: Paul Beckingham <paul@beckingham.net>
This commit is contained in:
Ben Boeckel 2011-07-29 22:30:27 -04:00 committed by Paul Beckingham
parent 402bac02a6
commit 210b5f54d5
3 changed files with 50 additions and 0 deletions

View file

@ -169,6 +169,7 @@
+ Fixed bug that required the '%YAML' prologue in a YAML import.
+ Fixed bug that showed the 'due' date, under the heading 'until' date, in the
info report (thanks to Michael McCann).
+ Fixed burndown chart y-axis height calculation (thanks to Ben Boeckel).
------ old releases ------------------------------

View file

@ -29,6 +29,7 @@
#include <iostream>
#include <fstream>
#include <limits>
#include <sstream>
#include <vector>
#include <algorithm>
@ -39,6 +40,7 @@
#include <sys/wait.h>
#include <fcntl.h>
#include <unistd.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -54,6 +56,12 @@
extern Context context;
////////////////////////////////////////////////////////////////////////////////
static inline unsigned round_up_to (unsigned n, unsigned target)
{
return n + target - (n % target);
}
////////////////////////////////////////////////////////////////////////////////
// Uses std::getline, because std::cin eats leading whitespace, and that means
// that if a newline is entered, std::cin eats it and never returns from the
@ -437,4 +445,43 @@ int execute(const std::string& executable, std::vector<std::string> arguments)
}
}
// Collides with std::numeric_limits methods
#undef max
////////////////////////////////////////////////////////////////////////////////
unsigned 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 ();
}

View file

@ -83,5 +83,7 @@ int execute (const std::string&, std::vector<std::string>);
std::string compressIds (const std::vector <int>&);
void combine (std::vector <int>&, const std::vector <int>&);
unsigned burndown_size (unsigned ntasks);
#endif
////////////////////////////////////////////////////////////////////////////////