Permalink
Browse files

Separated aggregation from commandline tool.

  • Loading branch information...
1 parent a0757dd commit a9651749d8e8e6b6d1cad1523bf61dfdc9a575e3 @dustin committed Jan 17, 2009
Showing with 61 additions and 54 deletions.
  1. +4 −54 git-timecard
  2. +57 −0 gitaggregates.py
View
58 git-timecard
@@ -11,60 +11,10 @@ you don't, it should be easy enough to adapt main to what you need.
"""
import sys
-import time
-import subprocess
-from collections import defaultdict
-
-class TimeHisto(object):
-
- def __init__(self, log_args=['HEAD']):
- self.h = defaultdict(lambda: 0)
- self.add_logs(None, log_args)
-
- def add_logs(self, directory, log_args=['HEAD']):
- args=['git']
- if directory:
- args.append('--git-dir=' + directory)
- args.extend(['log', '--pretty=format:%at'])
- args.extend(log_args)
- sub = subprocess.Popen(args, stdout=subprocess.PIPE, close_fds=True)
-
- for l in sub.stdout:
- self.h[time.strftime("%w %H", time.localtime(float(l.strip())))] += 1
-
- def dump(self):
- for h in range(24):
- for d in range(7):
- sys.stderr.write("%02d %d - %s\n"
- % (h, d, self.h["%d %02d" % (d, h)]))
-
- def to_gchart(self):
- from pygooglechart import ScatterChart
- chart = ScatterChart(800, 300, x_range=(-1, 24), y_range=(-1, 7))
-
- chart.add_data([(h % 24) for h in range(24 * 8)])
-
- d=[]
- for i in range(8):
- d.extend([i] * 24)
- chart.add_data(d)
-
- day_names = "Sun Mon Tue Wed Thu Fri Sat".split(" ")
- days = (0, 6, 5, 4, 3, 2, 1)
-
- sizes=[]
- for d in days:
- sizes.extend([self.h["%d %02d" % (d, h)] for h in range(24)])
- sizes.extend([0] * 24)
- chart.add_data(sizes)
-
- chart.set_axis_labels('x', [''] + [str(h) for h in range(24)] + [''])
- chart.set_axis_labels('y', [''] + [day_names[n] for n in days] + [''])
-
- chart.add_marker(1, 1.0, 'o', '333333', 25)
- return chart.get_url() + '&chds=-1,24,-1,7,0,20'
+import gitaggregates
if __name__ == '__main__':
- th = TimeHisto(sys.argv[1:])
- subprocess.check_call(["open", th.to_gchart()])
+ th = gitaggregates.TimeHisto()
+ th.add_logs(log_args=sys.argv[1:])
+ gitaggregates.open_chart(th)
View
57 gitaggregates.py
@@ -0,0 +1,57 @@
+#!/usr/bin/env python
+"""A collection of git info aggregators for graph commands."""
+
+import time
+import subprocess
+from collections import defaultdict
+
+class TimeHisto(object):
+
+ def __init__(self):
+ self.h = defaultdict(lambda: 0)
+
+ def add_logs(self, directory=None, log_args=['HEAD']):
+ args=['git']
+ if directory:
+ args.append('--git-dir=' + directory)
+ args.extend(['log', '--pretty=format:%at'])
+ args.extend(log_args)
+ sub = subprocess.Popen(args, stdout=subprocess.PIPE, close_fds=True)
+
+ for l in sub.stdout:
+ self.h[time.strftime("%w %H", time.localtime(float(l.strip())))] += 1
+
+ def dump(self):
+ for h in range(24):
+ for d in range(7):
+ sys.stderr.write("%02d %d - %s\n"
+ % (h, d, self.h["%d %02d" % (d, h)]))
+
+ def to_gchart(self):
+ from pygooglechart import ScatterChart
+ chart = ScatterChart(800, 300, x_range=(-1, 24), y_range=(-1, 7))
+
+ chart.add_data([(h % 24) for h in range(24 * 8)])
+
+ d=[]
+ for i in range(8):
+ d.extend([i] * 24)
+ chart.add_data(d)
+
+ day_names = "Sun Mon Tue Wed Thu Fri Sat".split(" ")
+ days = (0, 6, 5, 4, 3, 2, 1)
+
+ sizes=[]
+ for d in days:
+ sizes.extend([self.h["%d %02d" % (d, h)] for h in range(24)])
+ sizes.extend([0] * 24)
+ chart.add_data(sizes)
+
+ chart.set_axis_labels('x', [''] + [str(h) for h in range(24)] + [''])
+ chart.set_axis_labels('y', [''] + [day_names[n] for n in days] + [''])
+
+ chart.add_marker(1, 1.0, 'o', '333333', 25)
+ return chart.get_url() + '&chds=-1,24,-1,7,0,20'
+
+def open_chart(chartish):
+ subprocess.check_call(['open', chartish.to_gchart()])

0 comments on commit a965174

Please sign in to comment.