Skip to content

Commit 8d93713

Browse files
Add five year summary to main report (#132)
* Add five year summary to main report * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent b530e48 commit 8d93713

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

gitstats/report_creator.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,46 @@ def create_activity_html(self, data, path):
133133

134134
# f.write('<h2>Last 12 months</h2>')
135135

136+
# Yearly activity
137+
YEARS = 5
138+
f.write(html_header(2, "Yearly activity"))
139+
f.write("<p>Last %d years</p>" % YEARS)
140+
141+
# generate years to show (previous N years from now)
142+
now = datetime.datetime.now()
143+
deltayear = datetime.timedelta(365)
144+
years = []
145+
stampcur = now
146+
for i in range(0, YEARS):
147+
years.insert(0, stampcur.strftime("%Y"))
148+
stampcur -= deltayear
149+
150+
# top row: commits & bar
151+
f.write('<table class="noborders"><tr>')
152+
for i in range(0, YEARS):
153+
commits = 0
154+
year_key = int(years[i])
155+
if year_key in data.commits_by_year:
156+
commits = data.commits_by_year[year_key]
157+
158+
percentage = 0
159+
if year_key in data.commits_by_year:
160+
max_commits = (
161+
max(data.commits_by_year.values()) if data.commits_by_year else 1
162+
)
163+
percentage = float(data.commits_by_year[year_key]) / max_commits
164+
height = max(1, int(200 * percentage))
165+
f.write(
166+
'<td style="text-align: center; vertical-align: bottom">%d<div style="display: block; background-color: red; width: 20px; height: %dpx"></div></td>'
167+
% (commits, height)
168+
)
169+
170+
# bottom row: year
171+
f.write("</tr><tr>")
172+
for i in range(0, YEARS):
173+
f.write("<td>%s</td>" % years[i])
174+
f.write("</tr></table>")
175+
136176
# Weekly activity
137177
WEEKS = 32
138178
f.write(html_header(2, "Weekly activity"))

0 commit comments

Comments
 (0)