Created
May 3, 2012 19:33
-
-
Save ZhanruiLiang/2588518 to your computer and use it in GitHub Desktop.
SOJ statistics
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
import urllib2 | |
import re | |
oo = 9000 | |
# userPageAddr = 'http://soj.me/user.php?id=8750' | |
userPageAddr = raw_input('Please input your user page address on Sicily(http://soj.me/user.php?id=8750, for example): ') | |
userId = re.findall('id=(\d+)', userPageAddr)[0] | |
s = urllib2.urlopen(userPageAddr).read() | |
problems = re.findall(r'show_problem\.php\?pid=(\d+)', s, re.M) | |
problems.sort() | |
def get_pass_count(problemID): | |
addr = 'http://soj.me/show_problem.php?pid=%s' % problemID | |
page = urllib2.urlopen(addr).read() | |
try: | |
tds = re.findall(r"<td[^>]*>(.*)</td>", page, re.M) | |
return int(tds[tds.index('Accepted:')+1]) | |
except: | |
print 'Can not view problem#%d' % problemID | |
return 0 | |
levels = [1, 50, 100, 150, 200, 300, oo] | |
intervals = [(levels[i], levels[i+1]) for i in xrange(len(levels)-1)] | |
data = {interval:0 for interval in intervals} | |
total = 0 | |
for pid in problems: | |
pid = int(pid) | |
# print 'Problem#%d ' % pid, | |
cnt = get_pass_count(pid) | |
# print 'pass %d people' % cnt | |
for l, r in intervals: | |
if l <= cnt < r: | |
data[(l, r)] += 1 | |
total += 1 | |
break | |
percents = {interval:cnt*100./total for interval, cnt in data.iteritems()} | |
for l, r in intervals: | |
print 'interval [%4d, %4d), accepted %3d(%.2f%%).' %( | |
l, r, data[l, r], percents[l, r]) | |
print 'total accepted: %d' % total | |
with open('save-id-%s' %(userId), 'w') as f: | |
print >> f, userPageAddr | |
print >> f, total | |
print >> f, data | |
raw_input('Press enter to exit...') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment