mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
CmdReportMonth: Parameterized the report type (month, day ...)
This commit is contained in:
parent
028399ddb3
commit
0b6814e82b
1 changed files with 32 additions and 16 deletions
|
@ -37,9 +37,10 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
|
||||||
static void renderAxis (const Rules&, Palette&, const std::string&, int, int);
|
int renderReport (const std::string&, Interval&, Rules&, Database&);
|
||||||
static void renderExclusionBlocks (const Rules&, std::vector <Composite>&, Palette&, const Datetime&, int, int, const std::vector <Range>&);
|
static void renderAxis (const std::string&, const Rules&, Palette&, const std::string&, int, int);
|
||||||
static void renderInterval (const Rules&, std::vector <Composite>&, const Datetime&, const Interval&, Palette&, std::map <std::string, Color>&, time_t&);
|
static void renderExclusionBlocks (const std::string&, const Rules&, std::vector <Composite>&, Palette&, const Datetime&, int, int, const std::vector <Range>&);
|
||||||
|
static void renderInterval (const std::string&, const Rules&, std::vector <Composite>&, const Datetime&, const Interval&, Palette&, std::map <std::string, Color>&, time_t&);
|
||||||
static void renderSummary (const std::string&, const Interval&, const std::vector <Range>&, const std::vector <Interval>&);
|
static void renderSummary (const std::string&, const Interval&, const std::vector <Range>&, const std::vector <Interval>&);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -48,11 +49,21 @@ int CmdReportMonth (
|
||||||
Rules& rules,
|
Rules& rules,
|
||||||
Database& database)
|
Database& database)
|
||||||
{
|
{
|
||||||
// Create a filter, and if empty, choose 'today'.
|
// Create a filter, and if empty, choose the current month.
|
||||||
auto filter = getFilter (cli);
|
auto filter = getFilter (cli);
|
||||||
if (! filter.range.is_started ())
|
if (! filter.range.is_started ())
|
||||||
filter.range = Range (Datetime ("socm"), Datetime ("eocm"));
|
filter.range = Range (Datetime ("socm"), Datetime ("eocm"));
|
||||||
|
|
||||||
|
return renderReport ("month", filter, rules, database);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
int renderReport (
|
||||||
|
const std::string& type,
|
||||||
|
Interval& filter,
|
||||||
|
Rules& rules,
|
||||||
|
Database& database)
|
||||||
|
{
|
||||||
// Load the data.
|
// Load the data.
|
||||||
auto exclusions = getAllExclusions (rules, filter.range);
|
auto exclusions = getAllExclusions (rules, filter.range);
|
||||||
auto tracked = getTracked (database, rules, filter);
|
auto tracked = getTracked (database, rules, filter);
|
||||||
|
@ -60,11 +71,12 @@ int CmdReportMonth (
|
||||||
// Map tags to colors.
|
// Map tags to colors.
|
||||||
auto palette = createPalette (rules);
|
auto palette = createPalette (rules);
|
||||||
auto tag_colors = createTagColorMap (rules, palette, tracked);
|
auto tag_colors = createTagColorMap (rules, palette, tracked);
|
||||||
|
Color colorToday (palette.enabled ? rules.get ("theme.colors.today") : "");
|
||||||
|
|
||||||
// Determine hours shown.
|
// Determine hours shown.
|
||||||
int first_hour = 0;
|
int first_hour = 0;
|
||||||
int last_hour = 23;
|
int last_hour = 23;
|
||||||
if (! rules.getBoolean ("reports.month.24hours"))
|
if (! rules.getBoolean ("reports." + type + ".24hours"))
|
||||||
{
|
{
|
||||||
// Get the extreme time range for the filtered data.
|
// Get the extreme time range for the filtered data.
|
||||||
first_hour = 23;
|
first_hour = 23;
|
||||||
|
@ -84,7 +96,7 @@ int CmdReportMonth (
|
||||||
|
|
||||||
// Render the axis.
|
// Render the axis.
|
||||||
std::cout << '\n';
|
std::cout << '\n';
|
||||||
renderAxis (rules, palette, " ", first_hour, last_hour);
|
renderAxis (type, rules, palette, " ", first_hour, last_hour);
|
||||||
|
|
||||||
// For breaks.
|
// For breaks.
|
||||||
Datetime previous (filter.range.start);
|
Datetime previous (filter.range.start);
|
||||||
|
@ -95,14 +107,14 @@ int CmdReportMonth (
|
||||||
for (Datetime day = filter.range.start; day < filter.range.end; day++)
|
for (Datetime day = filter.range.start; day < filter.range.end; day++)
|
||||||
{
|
{
|
||||||
// Render the exclusion blocks.
|
// Render the exclusion blocks.
|
||||||
std::vector <Composite> lines (rules.has ("reports.month.lines") ? rules.getInteger ("reports.month.lines") : 1);
|
std::vector <Composite> lines (rules.has ("reports." + type + ".lines") ? rules.getInteger ("reports." + type + ".lines") : 1);
|
||||||
renderExclusionBlocks (rules, lines, palette, day, first_hour, last_hour, exclusions);
|
renderExclusionBlocks (type, rules, lines, palette, day, first_hour, last_hour, exclusions);
|
||||||
|
|
||||||
time_t work = 0;
|
time_t work = 0;
|
||||||
for (auto& track : tracked)
|
for (auto& track : tracked)
|
||||||
{
|
{
|
||||||
time_t interval_work = 0;
|
time_t interval_work = 0;
|
||||||
renderInterval (rules, lines, day, track, palette, tag_colors, interval_work);
|
renderInterval (type, rules, lines, day, track, palette, tag_colors, interval_work);
|
||||||
work += interval_work;
|
work += interval_work;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,7 +158,7 @@ int CmdReportMonth (
|
||||||
total_work += work;
|
total_work += work;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string pad (15 + ((last_hour - first_hour + 1) * (4 + rules.getInteger ("reports.month.spacing"))) + 1, ' ');
|
std::string pad (15 + ((last_hour - first_hour + 1) * (4 + rules.getInteger ("reports." + type + ".spacing"))) + 1, ' ');
|
||||||
std::cout << pad << "[4m [0m\n";
|
std::cout << pad << "[4m [0m\n";
|
||||||
|
|
||||||
std::cout << pad
|
std::cout << pad
|
||||||
|
@ -155,7 +167,7 @@ int CmdReportMonth (
|
||||||
<< std::setw (2) << std::setfill ('0') << 45
|
<< std::setw (2) << std::setfill ('0') << 45
|
||||||
<< '\n';
|
<< '\n';
|
||||||
|
|
||||||
if (rules.getBoolean ("reports.month.summary"))
|
if (rules.getBoolean ("reports." + type + ".summary"))
|
||||||
renderSummary (" ", filter, exclusions, tracked);
|
renderSummary (" ", filter, exclusions, tracked);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -163,13 +175,14 @@ int CmdReportMonth (
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
static void renderAxis (
|
static void renderAxis (
|
||||||
|
const std::string& type,
|
||||||
const Rules& rules,
|
const Rules& rules,
|
||||||
Palette& palette,
|
Palette& palette,
|
||||||
const std::string& indent,
|
const std::string& indent,
|
||||||
int first_hour,
|
int first_hour,
|
||||||
int last_hour)
|
int last_hour)
|
||||||
{
|
{
|
||||||
auto spacing = rules.getInteger ("reports.month.spacing");
|
auto spacing = rules.getInteger ("reports." + type + ".spacing");
|
||||||
Color colorLabel (palette.enabled ? rules.get ("theme.colors.label") : "");
|
Color colorLabel (palette.enabled ? rules.get ("theme.colors.label") : "");
|
||||||
|
|
||||||
std::cout << indent;
|
std::cout << indent;
|
||||||
|
@ -181,6 +194,7 @@ static void renderAxis (
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
static void renderExclusionBlocks (
|
static void renderExclusionBlocks (
|
||||||
|
const std::string& type,
|
||||||
const Rules& rules,
|
const Rules& rules,
|
||||||
std::vector <Composite>& lines,
|
std::vector <Composite>& lines,
|
||||||
Palette& palette,
|
Palette& palette,
|
||||||
|
@ -189,8 +203,8 @@ static void renderExclusionBlocks (
|
||||||
int last_hour,
|
int last_hour,
|
||||||
const std::vector <Range>& excluded)
|
const std::vector <Range>& excluded)
|
||||||
{
|
{
|
||||||
auto spacing = rules.getInteger ("reports.month.spacing");
|
auto spacing = rules.getInteger ("reports." + type + ".spacing");
|
||||||
auto style = rules.get ("reports.month.style");
|
auto style = rules.get ("reports." + type + ".style");
|
||||||
Color colorExc (palette.enabled ? rules.get ("theme.colors.exclusion") : "");
|
Color colorExc (palette.enabled ? rules.get ("theme.colors.exclusion") : "");
|
||||||
|
|
||||||
// Render the exclusion blocks.
|
// Render the exclusion blocks.
|
||||||
|
@ -222,6 +236,7 @@ static void renderExclusionBlocks (
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
static void renderInterval (
|
static void renderInterval (
|
||||||
|
const std::string& type,
|
||||||
const Rules& rules,
|
const Rules& rules,
|
||||||
std::vector <Composite>& lines,
|
std::vector <Composite>& lines,
|
||||||
const Datetime& day,
|
const Datetime& day,
|
||||||
|
@ -230,11 +245,12 @@ static void renderInterval (
|
||||||
std::map <std::string, Color>& tag_colors,
|
std::map <std::string, Color>& tag_colors,
|
||||||
time_t& work)
|
time_t& work)
|
||||||
{
|
{
|
||||||
auto spacing = rules.getInteger ("reports.month.spacing");
|
auto spacing = rules.getInteger ("reports." + type + ".spacing");
|
||||||
|
|
||||||
// Make sure the track only represents one day.
|
// Make sure the track only represents one day.
|
||||||
auto day_range = getFullDay (day);
|
auto day_range = getFullDay (day);
|
||||||
if (! day_range.overlap (track.range))
|
if (! day_range.overlap (track.range) ||
|
||||||
|
(track.range.is_open () && day > Datetime ()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Interval clipped = clip (track, day_range);
|
Interval clipped = clip (track, day_range);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue