# HG changeset patch # User Mike Becker # Date 1740505577 -3600 # Node ID de22ded6d50a4cfd298c0fbd41162017aebf13a0 # Parent f58fd8461e10b7b02927cf569c8d09f8a407007e add total commits counters fixes #605 diff -r f58fd8461e10 -r de22ded6d50a src/heatmap.cpp --- a/src/heatmap.cpp Tue Feb 25 18:22:55 2025 +0100 +++ b/src/heatmap.cpp Tue Feb 25 18:46:17 2025 +0100 @@ -51,3 +51,16 @@ }]++; } } + +std::array fm::heatmap::commits_per_month( + const std::string& repo, + const std::string& author, + chrono::year year +) const { + std::array result{}; + for (auto&& [ymd, commits] : m_heatmap.at(repo).at(author)) { + if (ymd.year() != year) continue; + result[static_cast(ymd.month())-1] += commits; + } + return result; +} diff -r f58fd8461e10 -r de22ded6d50a src/heatmap.h --- a/src/heatmap.h Tue Feb 25 18:22:55 2025 +0100 +++ b/src/heatmap.h Tue Feb 25 18:46:17 2025 +0100 @@ -26,6 +26,7 @@ #define HEATMAP_H #include +#include #include #include @@ -53,6 +54,12 @@ [[nodiscard]] const auto& data() const { return m_heatmap; } + + [[nodiscard]] std::array commits_per_month( + const std::string &repo, + const std::string& author, + std::chrono::year year + ) const; }; } diff -r f58fd8461e10 -r de22ded6d50a src/html.cpp --- a/src/html.cpp Tue Feb 25 18:22:55 2025 +0100 +++ b/src/html.cpp Tue Feb 25 18:46:17 2025 +0100 @@ -134,17 +134,19 @@ } } -void html::h1(const std::string& heading) { +void html::heading_repo(const std::string& repo) { indent(); - printf("

%s

\n", encode(heading).c_str()); + printf("

%s

\n", encode(repo).c_str()); } -void html::h2(const std::string& heading) { +void html::heading_author(const std::string& author, unsigned int total_commits) { indent(); - printf("

%s

\n", encode(heading).c_str()); + printf("

%s

\n", + total_commits, + encode(author).c_str()); } -void html::table_begin(year y) { +void html::table_begin(year y, const std::array &commits_per_month) { static constexpr const char* months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; // compute the column spans, first unsigned colspans[12] = {}; @@ -169,7 +171,8 @@ puts(""); for (unsigned i = 0 ; i < 12 ; i++) { indent(); - printf("%s\n", colspans[i], months[i]); + printf("%s\n", + commits_per_month[i], colspans[i], months[i]); } indent(-1); puts(""); diff -r f58fd8461e10 -r de22ded6d50a src/html.h --- a/src/html.h Tue Feb 25 18:22:55 2025 +0100 +++ b/src/html.h Tue Feb 25 18:46:17 2025 +0100 @@ -27,6 +27,7 @@ #include #include +#include namespace html { @@ -35,9 +36,9 @@ void open(bool fragment); void close(bool fragment); - void h1(const std::string& heading); - void h2(const std::string& heading); - void table_begin(std::chrono::year y); + void heading_repo(const std::string& repo); + void heading_author(const std::string& author, unsigned int total_commits); + void table_begin(std::chrono::year y, const std::array &commits_per_month); void table_end(); void row_begin(unsigned int row); void row_end(); diff -r f58fd8461e10 -r de22ded6d50a src/main.cpp --- a/src/main.cpp Tue Feb 25 18:22:55 2025 +0100 +++ b/src/main.cpp Tue Feb 25 18:46:17 2025 +0100 @@ -34,6 +34,8 @@ #include #include +#include + using namespace std::chrono; static constexpr auto program_version = "1.1.0 (dev)"; @@ -266,11 +268,14 @@ for (const auto &[author, entries] : authors) { if (settings.exclude_author(author)) continue; if (!h1_rendered) { - html::h1(repo); + html::heading_repo(repo); h1_rendered = true; } - html::h2(author); - html::table_begin(report_year); + + const auto commits_per_month = heatmap.commits_per_month(repo, author, report_year); + const auto total_commits = std::accumulate(commits_per_month.begin(), commits_per_month.end(), 0u); + html::heading_author(author, total_commits); + html::table_begin(report_year, commits_per_month); // initialize counters unsigned column = 0, row = 0;