Commit 5268018655cefcedee6173f5cca419ead14e6ed0

A github-style timecard tool.
git-timecard
(65 / 0)
  
1#!/usr/bin/env python
2"""Create timecard histograms for a ref.
3
4For printing a chart (the default), pygooglechart is required:
5
6 http://pygooglechart.slowchop.com/
7
8Note that this assumes you've got an OS-X style "open" command. If
9you don't, it should be easy enough to adapt main to what you need.
10
11"""
12
13import sys
14import time
15import subprocess
16from collections import defaultdict
17
18class TimeHisto(object):
19
20 def __init__(self, ref='HEAD'):
21 self.h = defaultdict(lambda: 0)
22 args = ['git', 'log', '--pretty=format:%at', ref]
23 sub = subprocess.Popen(args, stdout=subprocess.PIPE, close_fds=True)
24
25 for l in sub.stdout:
26 self.h[time.strftime("%w %H", time.localtime(float(l.strip())))] += 1
27
28 def dump(self):
29 for h in range(24):
30 for d in range(7):
31 sys.stderr.write("%02d %d - %s\n"
32 % (h, d, self.h["%d %02d" % (d, h)]))
33
34 def to_gchart(self):
35 from pygooglechart import ScatterChart
36 chart = ScatterChart(800, 300, x_range=(-1, 24), y_range=(-1, 7))
37
38 chart.add_data([(h % 24) for h in range(24 * 8)])
39
40 d=[]
41 for i in range(8):
42 d.extend([i] * 24)
43 chart.add_data(d)
44
45 sizes=[]
46 for d in range(7):
47 sizes.extend([self.h["%d %02d" % (d, h)] for h in range(24)])
48 sizes.extend([0] * 24)
49 chart.add_data(sizes)
50
51 chart.set_axis_labels('x', [''] + [str(h) for h in range(24)] + [''])
52 chart.set_axis_labels('y',
53 ['', 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', ''])
54
55 chart.add_marker(1, 1.0, 'o', '333333', 25)
56 return chart.get_url() + '&chds=-1,24,-1,7,0,20'
57
58
59if __name__ == '__main__':
60 ref = 'HEAD'
61 if len(sys.argv) > 1:
62 ref = sys.argv[1]
63
64 th = TimeHisto(ref)
65 subprocess.check_call(["open", th.to_gchart()])