Created
May 16, 2018 08:08
-
-
Save jakobkogler/9deb1afc53632d211f315146b1ce2683 to your computer and use it in GitHub Desktop.
Visualize successful CF submissions
This file contains hidden or 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 python3 | |
import urllib.request | |
import json | |
from datetime import datetime, timedelta | |
import matplotlib.pyplot as plt | |
from matplotlib.dates import drange | |
from collections import defaultdict | |
import sys | |
def loadData(user): | |
url = "http://codeforces.com/api/user.status?handle={}&from=1".format(user) | |
response = urllib.request.urlopen(url) | |
data = response.read() | |
j = json.loads(data) | |
d = defaultdict(int) | |
s = set() | |
if j['status'] == 'OK': | |
for submission in j['result']: | |
if submission['verdict'] != 'OK': | |
continue | |
problem = submission['problem'] | |
if 'problemsetName' in problem: | |
continue | |
index = str(problem['contestId']) + problem['index'] | |
if index not in s: | |
s.add(index) | |
time = submission['creationTimeSeconds'] | |
time = datetime.fromtimestamp(time) | |
time = datetime(time.year, time.month, time.day) | |
d[time] += 1 | |
return d | |
if __name__ == '__main__': | |
start = datetime(2018, 1, 1) | |
end = datetime.today() | |
days = (end - start).days | |
x = [start + timedelta(days=da) for da in range(0, days+1)] | |
users = sys.argv[1:] | |
ys = dict() | |
for user in users: | |
data = loadData(user) | |
ys[user] = [data[day] for day in x] | |
y_max = max((max(y, default=1) for y in ys.values()), default=1) | |
fig = plt.figure(1) | |
fig.suptitle('Successful CF submissions', size=16) | |
for idx, user in enumerate(users, start=1): | |
plt.subplot(len(users), 1, idx) | |
axes = plt.gca() | |
axes.set_ylim(0, y_max + 1)G | |
plt.title(user) | |
plt.bar(x, ys[user]) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment