Skip to content

Instantly share code, notes, and snippets.

@jeremyBanks
Created November 7, 2009 15:08
Show Gist options
  • Save jeremyBanks/228731 to your computer and use it in GitHub Desktop.
Save jeremyBanks/228731 to your computer and use it in GitHub Desktop.
Shitty little script that spits out a Google chart of activity in a repo over time
#!/usr/bin/env python3.1
"""Shitty little script that spits out a Google chart of activity in a repo over time"""
import sys
import subprocess
import re
import collections
import itertools
import datetime
WHITESPACE = re.compile("[ \t\n\r]+")
GIT_LOG = "git log --pretty=medium --numstat --date=short --all".split(" ")
log = subprocess.Popen(GIT_LOG, stdout=subprocess.PIPE).stdout
current_insertions = 0
current_deletions = 0
first_date = last_date = None
insertions = collections.defaultdict(int)
deletions = collections.defaultdict(int)
for line in itertools.chain(log, [b"Date: "]):
line = line.decode()
if line.startswith("Date: "):
date = line.partition("Date: ")[2].strip()
insertions[last_date] += current_insertions
deletions[last_date] += current_deletions
current_insertions = current_deletions = 0
if first_date is None:
first_date = date
if date:
last_date = date
if line[0] in set("0123456789"):
written, deleted, filename, *_ = WHITESPACE.split(line)
current_insertions = int(written)
current_deletions = int(deleted)
DAY = datetime.timedelta(days=1)
def date_range(start, end):
"""takes two YYYY-MM-DD dates and yields their inclusive range"""
start_ymd = list(map(int, start.split("-")))
end_ymd = list(map(int, end.split("-")))
if end_ymd < start_ymd:
start_ymd, end_ymd = end_ymd, start_ymd
start_date = datetime.date(*start_ymd)
end_date = datetime.date(*end_ymd)
now = start_date
while now <= end_date:
yield(str(now))
now += DAY
i_list = []
d_list = []
for day in date_range(first_date, last_date):
i_list.append(insertions[day])
d_list.append(deletions[day])
highest = max(map(sum, zip(i_list, d_list)))
i_list = [v * 100 / highest for v in i_list]
d_list = [v * 100 / highest for v in d_list]
weekend_list = [100 * (i % 7 in {4,3}) for i in range(len(d_list))]
weekday_list = [100 * (i % 7 not in {4,3}) for i in range(len(d_list))]
width = 12 * len(d_list) + 16
print("http://chart.apis.google.com/chart?cht=bvs&"
"chs={}x200&chd=t:{}|{}|{}|{}&chco=FF4444,44FF44,CCDEFF,FFEDCC&chbh=10,2,0"
.format(width,
",".join(map(str, d_list)),
",".join(map(str, i_list)),
",".join(map(str, weekend_list)),
",".join(map(str, weekday_list))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment