At work, we have a "pair programming ladder" where you can keep track of who is pairing with whom (based on check-ins). The idea is to promote "promiscuous pairing" where each developer eventually pairs with every other developer.
In our team, this was being updated manually, so I thought of writing a script that will parse the logs and generate a table.
Given these are the names of the developers:
"Adam", "Bill", "Carl", "David", "Eddie", "Frank", "George"
The output would look like so:
|Adam Bill |0 |Bill Carl |0 |2 |Carl David |1 |0 |0 |David Earl |0 |0 |3 |0 |Earl Frank |0 |0 |0 |2 |1 |Frank George |0 |0 |0 |0 |2 |0 |George Solo |1 |0 |0 |0 |0 |1 |0 |Solo Other |1 |0 |0 |0 |0 |2 |1 |0 |Other
This is my script:
from git import *
import re
from collections import Counter
list = ["Adam", "Bill", "Carl", "David", "Eddie", "Frank", "George"]
def build():
repo = Repo("/home/developer/work/commerce-git/commerce-project")
master = repo.heads.master
pairsDict = {}
for commit in repo.iter_commits(master, since='2013-02-06+14:00', reverse=True):
for person in list:
if person not in pairsDict:
pairsDict[person] = Counter()
if person in commit.message:
pairedWith = ""
m = re.search('(\w+)/(\w+)\s', commit.message)
if not m:
pairedWith = "Solo"
else:
if m.group(1) == person:
pairedWith = m.group(2) #pair is right of slash
else:
pairedWith = m.group(1) #pair is left of slash
if pairedWith not in list:
pairedWith = "Other"
pairsDict[person][pairedWith] += 1
if pairedWith not in pairsDict:
pairsDict[pairedWith] = Counter()
pairsDict[pairedWith][person] += 1
break;
return pairsDict
def print_table():
pairsList = list + ["Solo", "Other"]
pairsDict = build()
str = ""
for index,person in enumerate(pairsList):
if (index == 0):
str += '|'.rjust(8) + person.ljust(7) + '\n'
else:
str += person.ljust(7) + '|'
for paired in pairsList[:index]:
count = pairsDict[person][paired]
str += '{:<7}|'.format(count)
str += person.ljust(7)+'\n'
print str
return str
if __name__ == "__main__":
print_table();
The scripts parses the git logs using GitPython, where a commit message is expected to look like this:
"Adam/David - Refactored app to be more polyglot-y"
From there it constructs a HashMap
of Counter
s to keep track of who has paired with whom. I'm going to eventually feed this data structure into a simple Django web-app so people can view it in a browser.
Do you have any suggestions for this script? Could it be more "pythonic"? Is there anything I could do to refactor it to be simpler to read, or better performance-wise?