Created
October 10, 2012 04:03
-
-
Save anonymous/3863082 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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), | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment