Activity: added 'Commits by Timezone'.

This commit is contained in:
Heikki Hokkanen 2009-12-23 21:52:12 +02:00
parent 04568e7fbd
commit 8542a238e2

View File

@ -174,6 +174,9 @@ class GitDataCollector(DataCollector):
self.last_active_day = None
self.active_days = 0
# timezone
self.commits_by_timezone = {} # timezone -> commits
# tags
self.tags = {}
lines = getpipeoutput(['git show-ref --tags']).split('\n')
@ -213,7 +216,7 @@ class GitDataCollector(DataCollector):
# Collect revision statistics
# Outputs "<stamp> <author>"
lines = getpipeoutput(['git rev-list --pretty=format:"%at %an" HEAD', 'grep -v ^commit']).split('\n')
lines = getpipeoutput(['git rev-list --pretty=format:"%at %ai %an" HEAD', 'grep -v ^commit']).split('\n')
for line in lines:
# linux-2.6 says "<unknown>" for one line O_o
parts = line.split(' ')
@ -222,7 +225,8 @@ class GitDataCollector(DataCollector):
stamp = int(parts[0])
except ValueError:
stamp = 0
if len(parts) > 1:
timezone = parts[3]
if len(parts) > 4:
author = ' '.join(parts[1:])
date = datetime.datetime.fromtimestamp(float(stamp))
@ -331,6 +335,9 @@ class GitDataCollector(DataCollector):
self.last_active_day = yymmdd
self.active_days += 1
# timezone
self.commits_by_timezone[timezone] = self.commits_by_timezone.get(timezone, 0) + 1
# TODO Optimize this, it's the worst bottleneck
# outputs "<stamp> <files>" for each revision
self.files_by_stamp = {} # stamp -> files
@ -713,6 +720,17 @@ class HTMLReportCreator(ReportCreator):
fg.write('%d %d\n' % (yy, data.commits_by_year[yy]))
fg.close()
# Commits by timezone
f.write(html_header(2, 'Commits by Timezone'))
f.write('<table><tr>')
f.write('<th>Timezone</th><th>Commits</th>')
max_commits_on_tz = max(data.commits_by_timezone.values())
for i in sorted(data.commits_by_timezone.keys(), key = lambda n : int(n)):
commits = data.commits_by_timezone[i]
r = 127 + int((float(commits) / max_commits_on_tz) * 128)
f.write('<tr><th>%s</th><td style="background-color: rgb(%d, 0, 0)">%d</td></tr>' % (i, r, commits))
f.write('</tr></table>')
f.write('</body></html>')
f.close()