Monday, November 23, 2009

Personal Git Punch Card Grapher

Say you like GitHub's punch card graphs, but you want more info. This hack, based on blatantly stolen code, allows you to generate punch card graphs from the command line.

Here's the command to generate these two punch cards, comparing commit activity in the past week on branch A to commit activity in the past week on branch B:

ruby timecard.rb . branch_a a && ruby timecard.rb . branch_b b

(Names changed, of course, but this command produces two pngs, a.png and b.png, and they show you the commits on branch_a and branch_b, respectively.)

Here's the code for it. I found some good code and hacked a few argument vector calls into it. (Comments in the gist can direct you to the original.) Command-line args control everything except the date of the earliest commit to consider. That's hard-coded: Monday the 16th at 3am.

EARLY_MONDAY = 1258370000

If you fork this and add the ability to specify dates in a cleaner way, ping me, I think that would make this very handy.

Update: Gavin Stark forked and improved:

Thanks, this is really handy. I wrote something similar to parse my company's mail log to generate a punch card of when people check mail. VERY telling for some employees. ;-)

I added a few more features and use the chronic gem for date parsing:

Only real problem left is that the google chart API seems to barf if you have too many points on the graph. You get a 414 URI too large error if the URL is over 2000 or so bytes. I guess google giveth and taketh away.