Permalink
Browse files

Added a new git chart generator showing commit counts.

  • Loading branch information...
1 parent a5d7c98 commit 4f0c9f16d42768f6759423b84ebffbcbb3c00534 @dustin committed Mar 3, 2012
Showing with 68 additions and 0 deletions.
  1. +20 −0 git-commit-chart
  2. +48 −0 gitaggregates.py
View
20 git-commit-chart
@@ -0,0 +1,20 @@
+#!/usr/bin/env python
+"""Create bar chart showing divergence over time.
+
+For printing a chart (the default), pygooglechart is required:
+
+ http://pygooglechart.slowchop.com/
+
+Note that this assumes you've got an OS-X style "open" command. If
+you don't, it should be easy enough to adapt main to what you need.
+
+"""
+
+import sys
+
+import gitaggregates
+
+if __name__ == '__main__':
+ th = gitaggregates.ChangeOverTime()
+ th.add_logs(log_args=sys.argv[1:])
+ gitaggregates.open_chart(th)
View
48 gitaggregates.py
@@ -123,5 +123,53 @@ def mk_chart(self):
def to_gchart(self):
return self.mk_chart().get_url()
+class ChangeOverTime(object):
+
+ width = 800
+ height = 300
+ max_entries = 6
+
+ def __init__(self, log_args=['HEAD']):
+ self.newdata = []
+ self.cumulative = []
+ self.cmax = 0
+ self.max = 0
+
+ def add_logs(self, directory=None, log_args=['HEAD']):
+ args = ['git', 'log', '--pretty=format:%at'] + log_args
+ sub = subprocess.Popen(args, stdout=subprocess.PIPE, close_fds=True)
+
+ dates = {}
+ for l in sub.stdout:
+ k = time.strftime("%F", time.localtime(float(l.strip())))
+ dates[k] = dates.get(k, 0) + 1
+
+ total = 0
+ for k,v in sorted(dates.items()):
+ total += v
+ self.max = max(self.max, v)
+ self.newdata.append( (k, v) )
+ self.cumulative.append( (k, total) )
+
+ self.cmax = total
+
+ def dump(self):
+ sys.stderr.write(repr(self.data) + "\n")
+
+ def mk_chart(self):
+ from pygooglechart import SimpleLineChart
+ chart = SimpleLineChart(self.width, self.height)
+
+ all_labels = [d[0] for d in self.cumulative]
+
+ chart.add_data([d[1] for d in self.cumulative])
+ chart.set_axis_labels('y', range(0, self.cmax, (self.cmax / 4)))
+ chart.set_axis_labels('x', [all_labels[x] for x in
+ range(0, len(all_labels), (len(all_labels) / 4))])
+ return chart
+
+ def to_gchart(self):
+ return self.mk_chart().get_url()
+
def open_chart(chartish):
subprocess.check_call(['open', chartish.to_gchart()])

0 comments on commit 4f0c9f1

Please sign in to comment.