public
anonymous / stats.py
Created

  • Download Gist
stats.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
#!/usr/bin/env python
 
import re
import fileinput
 
stats = {}
totals = {}
 
for line in fileinput.input():
line = line.strip()
m = re.match('^"(\d{4})-.+organizations/(.+)>$', line)
if not m:
print "uhoh: %s" % line
continue
year, inst = m.groups()
 
s = stats.get(year, {})
s[inst] = s.get(inst, 0) + 1
stats[year] = s
totals[inst] = totals.get(inst, 0) + 1
 
years = stats.keys()
years.sort()
 
institutions = totals.keys()
institutions.sort(lambda a, b: cmp(totals[b], totals[a]))
 
print "year\t", "\t".join(institutions)
for year in years:
print year,
for inst in institutions:
print "\t", stats[year].get(inst, 0),
print

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.