CmdHistory: Code Cleanup

- Fixed formatting inconsistencies.
- Added Lukas to AUTHORS.
This commit is contained in:
Paul Beckingham 2017-01-27 17:32:19 -05:00
parent 91b73270c8
commit 00a4cbf906
3 changed files with 83 additions and 47 deletions

View file

@ -137,6 +137,7 @@ The following submitted code, packages or analysis, and deserve special thanks:
Jelle van der Waa Jelle van der Waa
Flavio Poletti Flavio Poletti
Antonio Huete Jimenez Antonio Huete Jimenez
Lukas Barth
Thanks to the following, who submitted detailed bug reports and excellent Thanks to the following, who submitted detailed bug reports and excellent
suggestions: suggestions:

View file

@ -56,6 +56,7 @@ CmdHistoryBase<HistoryStrategy>::CmdHistoryBase ()
_category = Command::Category::graphs; _category = Command::Category::graphs;
} }
////////////////////////////////////////////////////////////////////////////////
template<class HistoryStrategy> template<class HistoryStrategy>
void CmdHistoryBase<HistoryStrategy>::outputGraphical (std::string &output) void CmdHistoryBase<HistoryStrategy>::outputGraphical (std::string &output)
{ {
@ -116,10 +117,10 @@ void CmdHistoryBase<HistoryStrategy>::outputGraphical (std::string &output)
unsigned int completedBar = (widthOfBar * completedGroup[i.first]) / maxLine; unsigned int completedBar = (widthOfBar * completedGroup[i.first]) / maxLine;
unsigned int deletedBar = (widthOfBar * deletedGroup[i.first]) / maxLine; unsigned int deletedBar = (widthOfBar * deletedGroup[i.first]) / maxLine;
std::string bar = ""; std::string bar;
if (context.color ()) if (context.color ())
{ {
std::string aBar = ""; std::string aBar;
if (addedGroup[i.first]) if (addedGroup[i.first])
{ {
aBar = format (addedGroup[i.first]); aBar = format (addedGroup[i.first]);
@ -127,7 +128,7 @@ void CmdHistoryBase<HistoryStrategy>::outputGraphical (std::string &output)
aBar = ' ' + aBar; aBar = ' ' + aBar;
} }
std::string cBar = ""; std::string cBar;
if (completedGroup[i.first]) if (completedGroup[i.first])
{ {
cBar = format (completedGroup[i.first]); cBar = format (completedGroup[i.first]);
@ -135,7 +136,7 @@ void CmdHistoryBase<HistoryStrategy>::outputGraphical (std::string &output)
cBar = ' ' + cBar; cBar = ' ' + cBar;
} }
std::string dBar = ""; std::string dBar;
if (deletedGroup[i.first]) if (deletedGroup[i.first])
{ {
dBar = format (deletedGroup[i.first]); dBar = format (deletedGroup[i.first]);
@ -151,9 +152,9 @@ void CmdHistoryBase<HistoryStrategy>::outputGraphical (std::string &output)
} }
else else
{ {
std::string aBar = ""; while (aBar.length () < addedBar) aBar += '+'; std::string aBar; while (aBar.length () < addedBar) aBar += '+';
std::string cBar = ""; while (cBar.length () < completedBar) cBar += 'X'; std::string cBar; while (cBar.length () < completedBar) cBar += 'X';
std::string dBar = ""; while (dBar.length () < deletedBar) dBar += '-'; std::string dBar; while (dBar.length () < deletedBar) dBar += '-';
bar += std::string (leftOffset - aBar.length (), ' '); bar += std::string (leftOffset - aBar.length (), ' ');
bar += aBar + cBar + dBar; bar += aBar + cBar + dBar;
@ -190,6 +191,7 @@ void CmdHistoryBase<HistoryStrategy>::outputGraphical (std::string &output)
output = out.str (); output = out.str ();
} }
////////////////////////////////////////////////////////////////////////////////
template<class HistoryStrategy> template<class HistoryStrategy>
void CmdHistoryBase<HistoryStrategy>::outputTabular (std::string &output) void CmdHistoryBase<HistoryStrategy>::outputTabular (std::string &output)
{ {
@ -288,6 +290,7 @@ void CmdHistoryBase<HistoryStrategy>::outputTabular (std::string &output)
output = out.str (); output = out.str ();
} }
////////////////////////////////////////////////////////////////////////////////
template<class HistoryStrategy> template<class HistoryStrategy>
int CmdHistoryBase<HistoryStrategy>::execute (std::string& output) int CmdHistoryBase<HistoryStrategy>::execute (std::string& output)
{ {
@ -353,3 +356,5 @@ template class CmdHistoryBase<MonthlyHistoryStrategy>;
template class CmdHistoryBase<AnnualHistoryStrategy>; template class CmdHistoryBase<AnnualHistoryStrategy>;
template class CmdHistoryBase<MonthlyGHistoryStrategy>; template class CmdHistoryBase<MonthlyGHistoryStrategy>;
template class CmdHistoryBase<AnnualGHistoryStrategy>; template class CmdHistoryBase<AnnualGHistoryStrategy>;
////////////////////////////////////////////////////////////////////////////////

View file

@ -47,23 +47,31 @@ private:
std::map <time_t, int> deletedGroup; // Deletions by timeinterval std::map <time_t, int> deletedGroup; // Deletions by timeinterval
int rc; int rc;
void outputTabular(std::string&); void outputTabular (std::string&);
void outputGraphical(std::string&); void outputGraphical (std::string&);
}; };
////////////////////////////////////////////////////////////////////////////i ////////////////////////////////////////////////////////////////////////////i
class MonthlyHistoryStrategy { class MonthlyHistoryStrategy
{
public: public:
static Datetime getRelevantDate (const Datetime & dt) { static Datetime getRelevantDate (const Datetime & dt)
{
return dt.startOfMonth (); return dt.startOfMonth ();
} }
static void setupTableDates (Table & view) { static void setupTableDates (Table & view)
{
view.add (STRING_CMD_HISTORY_YEAR); view.add (STRING_CMD_HISTORY_YEAR);
view.add (STRING_CMD_HISTORY_MONTH); view.add (STRING_CMD_HISTORY_MONTH);
} }
static void insertRowDate (Table & view, int row, time_t rowTime, time_t lastTime) { static void insertRowDate (
Table& view,
int row,
time_t rowTime,
time_t lastTime)
{
Datetime dt (rowTime); Datetime dt (rowTime);
int m, d, y; int m, d, y;
dt.toYMD (y, m, d); dt.toYMD (y, m, d);
@ -76,33 +84,41 @@ public:
{ {
view.set (row, 0, y); view.set (row, 0, y);
} }
view.set (row, 1, Datetime::monthName(m));
view.set (row, 1, Datetime::monthName (m));
} }
static constexpr const char * keyword = "history.monthly"; static constexpr const char* keyword = "history.monthly";
static constexpr const char * usage = "task <filter> history.monthly"; static constexpr const char* usage = "task <filter> history.monthly";
static constexpr const char * description = STRING_CMD_HISTORY_USAGE_M; static constexpr const char* description = STRING_CMD_HISTORY_USAGE_M;
static constexpr unsigned int dateFieldCount = 2; static constexpr unsigned int dateFieldCount = 2;
static constexpr bool graphical = false; static constexpr bool graphical = false;
}; };
typedef CmdHistoryBase<MonthlyHistoryStrategy> CmdHistoryMonthly; typedef CmdHistoryBase<MonthlyHistoryStrategy> CmdHistoryMonthly;
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////i ////////////////////////////////////////////////////////////////////////////i
class MonthlyGHistoryStrategy { class MonthlyGHistoryStrategy
{
public: public:
static Datetime getRelevantDate (const Datetime & dt) { static Datetime getRelevantDate (const Datetime & dt)
{
return dt.startOfMonth (); return dt.startOfMonth ();
} }
static void setupTableDates (Table & view) { static void setupTableDates (Table & view)
{
view.add (STRING_CMD_HISTORY_YEAR); view.add (STRING_CMD_HISTORY_YEAR);
view.add (STRING_CMD_HISTORY_MONTH); view.add (STRING_CMD_HISTORY_MONTH);
} }
static void insertRowDate (Table & view, int row, time_t rowTime, time_t lastTime) { static void insertRowDate (
Table& view,
int row,
time_t rowTime,
time_t lastTime)
{
Datetime dt (rowTime); Datetime dt (rowTime);
int m, d, y; int m, d, y;
dt.toYMD (y, m, d); dt.toYMD (y, m, d);
@ -115,32 +131,40 @@ public:
{ {
view.set (row, 0, y); view.set (row, 0, y);
} }
view.set (row, 1, Datetime::monthName(m));
view.set (row, 1, Datetime::monthName (m));
} }
static constexpr const char * keyword = "ghistory.monthly"; static constexpr const char* keyword = "ghistory.monthly";
static constexpr const char * usage = "task <filter> ghistory.monthly"; static constexpr const char* usage = "task <filter> ghistory.monthly";
static constexpr const char * description = STRING_CMD_GHISTORY_USAGE_M; static constexpr const char* description = STRING_CMD_GHISTORY_USAGE_M;
static constexpr unsigned int dateFieldCount = 2; static constexpr unsigned int dateFieldCount = 2;
static constexpr bool graphical = true; static constexpr bool graphical = true;
}; };
typedef CmdHistoryBase<MonthlyGHistoryStrategy> CmdGHistoryMonthly; typedef CmdHistoryBase<MonthlyGHistoryStrategy> CmdGHistoryMonthly;
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////i ////////////////////////////////////////////////////////////////////////////i
class AnnualHistoryStrategy { class AnnualHistoryStrategy
{
public: public:
static Datetime getRelevantDate (const Datetime & dt) { static Datetime getRelevantDate (const Datetime & dt)
{
return dt.startOfYear (); return dt.startOfYear ();
} }
static void setupTableDates (Table & view) { static void setupTableDates (Table & view)
{
view.add (STRING_CMD_HISTORY_YEAR); view.add (STRING_CMD_HISTORY_YEAR);
} }
static void insertRowDate (Table & view, int row, time_t rowTime, time_t lastTime) { static void insertRowDate (
Table& view,
int row,
time_t rowTime,
time_t lastTime)
{
Datetime dt (rowTime); Datetime dt (rowTime);
int m, d, y; int m, d, y;
dt.toYMD (y, m, d); dt.toYMD (y, m, d);
@ -155,29 +179,36 @@ public:
} }
} }
static constexpr const char * keyword = "history.annual"; static constexpr const char* keyword = "history.annual";
static constexpr const char * usage = "task <filter> history.annual"; static constexpr const char* usage = "task <filter> history.annual";
static constexpr const char * description = STRING_CMD_HISTORY_USAGE_A; static constexpr const char* description = STRING_CMD_HISTORY_USAGE_A;
static constexpr unsigned int dateFieldCount = 1; static constexpr unsigned int dateFieldCount = 1;
static constexpr bool graphical = false; static constexpr bool graphical = false;
}; };
typedef CmdHistoryBase<AnnualHistoryStrategy> CmdHistoryAnnual; typedef CmdHistoryBase<AnnualHistoryStrategy> CmdHistoryAnnual;
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////i ////////////////////////////////////////////////////////////////////////////i
class AnnualGHistoryStrategy { class AnnualGHistoryStrategy
{
public: public:
static Datetime getRelevantDate (const Datetime & dt) { static Datetime getRelevantDate (const Datetime & dt)
{
return dt.startOfYear (); return dt.startOfYear ();
} }
static void setupTableDates (Table & view) { static void setupTableDates (Table & view)
{
view.add (STRING_CMD_HISTORY_YEAR); view.add (STRING_CMD_HISTORY_YEAR);
} }
static void insertRowDate (Table & view, int row, time_t rowTime, time_t lastTime) { static void insertRowDate (
Table& view,
int row,
time_t rowTime,
time_t lastTime)
{
Datetime dt (rowTime); Datetime dt (rowTime);
int m, d, y; int m, d, y;
dt.toYMD (y, m, d); dt.toYMD (y, m, d);
@ -192,14 +223,13 @@ public:
} }
} }
static constexpr const char * keyword = "ghistory.annual"; static constexpr const char* keyword = "ghistory.annual";
static constexpr const char * usage = "task <filter> ghistory.annual"; static constexpr const char* usage = "task <filter> ghistory.annual";
static constexpr const char * description = STRING_CMD_GHISTORY_USAGE_A; static constexpr const char* description = STRING_CMD_GHISTORY_USAGE_A;
static constexpr unsigned int dateFieldCount = 1; static constexpr unsigned int dateFieldCount = 1;
static constexpr bool graphical = true; static constexpr bool graphical = true;
}; };
typedef CmdHistoryBase<AnnualGHistoryStrategy> CmdGHistoryAnnual; typedef CmdHistoryBase<AnnualGHistoryStrategy> CmdGHistoryAnnual;
////////////////////////////////////////////////////////////////////////////
#endif #endif