Sunday, February 2, 2014

Gettings stats for Play’s “Get involved” page

Here is how I get stats for the upcoming Play framework Get involved page.

Getting the number of committers

$ git shortlog -sn | head
   695 James Roper
   517 Guillaume Bort
   336 Peter Hausel
   330 Christopher Hunt
   237 peter hausel
   234 Sadek Drobi
   140 Erwan Loisant
    95 Rich Dougherty
    95 Nilanjan Raychaudhuri
    83 Julien Richard-Foy
$ git shortlog -sn | wc
     312     878    6391

The first column returned by wc shows that Play has had 312 committers over the repository's lifetime.

Credit: Pedro Nascimento's answer on Stack Overflow.

Getting the number of issue reporters

I'm counting creators of both open and closed issues. Even better would be to include people who comment on issues as well.

#!/usr/bin/env python

import requests
import json

def getIssues(page, state):
  return requests.get('https://api.github.com/repos/playframework/playframework/issues?state={}&page={}'.format(state, page))

def getReporters(page, state):
  resp = getIssues(page, state)
  if resp.ok:
    reporters = set()
    issues = json.loads(resp.content)
    for issue in issues:
      reporter = issue['user']['login']
      reporters.add(reporter)
    return reporters
  else:
    return None

def getAllReportersForState(state):
  reporters = set()
  page = 1
  while True:
    reportersForPage = getReporters(page, state)
    if reportersForPage:
      reporters |= reportersForPage
    else:
      return reporters
    page += 1

openReporters = getAllReportersForState('open')
print '=== open ==='
print openReporters
print len(openReporters)

closedReporters = getAllReportersForState('closed')
print '=== closed ==='
print closedReporters
print len(closedReporters)

allReporters = openReporters | closedReporters
print '=== all ==='
print allReporters
print len(allReporters)