Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.pyc
135 changes: 71 additions & 64 deletions ui/api_functions_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ def getProblemDataFromContest(contestID):
r = requests.get(url).json()

if r['status'] == 'FAILED':
expectedMessage = 'contestId: Contest with id ' + str(contestID) + ' not found'
if r['comment'] == expectedMessage:
raise ContestNotFound(contestID)
expectedMessage = 'contestId: Contest with id ' + str(contestID) + ' not found'
if r['comment'] == expectedMessage:
raise ContestNotFound(contestID)

r = r['result']
contest = r['contest']['name']
Expand Down Expand Up @@ -79,7 +79,7 @@ def getProblemDataFromContest(contestID):
return probdf

def getSolveSuccessDF(contestID):
#contestID = 671
#contestID = 671
urlbase = 'http://codeforces.com/api/'
method = 'contest.standings'
maxcnt = 100000
Expand All @@ -92,43 +92,49 @@ def getSolveSuccessDF(contestID):

# CHECK TO MAKE SURE THAT TEAMS ARE NOT ALLOWED!!!
for r in rows: # for each person
if len(r['party']['members']) > 1:
raise Error("This contest allows teams. ELO scores are not well-defined.")

if len(r['party']['members']) > 1:
raise Error("This contest allows teams. ELO scores are not well-defined.")
users = []
points = []
for r in rows:
users.append(r['party']['members'][0]['handle'])

userpts = [0]*len(problems)
for i in range(len(problems)):
userpts[i] = r['problemResults'][i]['points']
points.append([1 if u > 0 else 0 for u in userpts])

users.append(r['party']['members'][0]['handle'])

userpts = [0]*len(problems)
for i in range(len(problems)):
userpts[i] = r['problemResults'][i]['points']
points.append([1 if u > 0 else 0 for u in userpts])

# Grab rating changes
method = 'contest.ratingChanges'
url = urlbase + method + '?contestId=' + str(contestID)
ratingchanges = requests.get(url).json()['result']
ratingdict = dict()
for r in ratingchanges:
ratingdict[r['handle']] = r['oldRating']

ratingdict[r['handle']] = r['oldRating']

# Create output df
# start constructing dataframe
array_out = []
for i in range(len(users)): # for each user in the contest
hdl = users[i]
rating = ratingdict[hdl]
for j, p in enumerate(problems): # for each problem in the contest, make a new row
temp = dict.fromkeys(['handle', 'rating', 'contestID', 'problemID', 'success'])
temp['handle'] = hdl
temp['contestID'] = contestID
temp['problemID'] = p['index']
temp['success'] = points[i][j]
temp['rating'] = rating
array_out.append(temp)
hdl = users[i]

if hdl not in ratingdict:
continue

#try:
rating = ratingdict[hdl]
#except:
# url = 'http://codeforces.com/api/user.rating?handle=' + hdl
# rating = requests.get(url).json()['result'][-1]['newRating']
for j, p in enumerate(problems): # for each problem in the contest, make a new row
temp = dict.fromkeys(['handle', 'rating', 'contestID', 'problemID', 'success'])
temp['handle'] = hdl
temp['contestID'] = contestID
temp['problemID'] = p['index']
temp['success'] = points[i][j]
temp['rating'] = rating
array_out.append(temp)

output = pd.DataFrame.from_dict(array_out)
return output
Expand All @@ -148,46 +154,48 @@ def getUserActivity(handle):

r = requests.get(url).json()
if r['status'] == 'FAILED':
expectedMessage = 'handle: User with handle ' + str(handle) + ' not found'
if r['comment'] == expectedMessage:
raise UserNotFound(handle)
expectedMessage = 'handle: User with handle ' + str(handle) + ' not found'
if r['comment'] == expectedMessage:
raise UserNotFound(handle)

dictlist = []
keys = ['testset', 'passedTestCount', 'author', 'relativeTimeSeconds',
'language', 'memoryBytes', 'timeMilliseconds', 'problem_name', 'problem_index',
'problem_tags', 'points', 'contestID', 'verdict', 'id', 'participantType', 'startTimeSeconds']
'language', 'memoryBytes', 'timeMilliseconds', 'problem_name', 'problem_index',
'problem_tags', 'points', 'contestID', 'verdict', 'id', 'participantType', 'startTimeSeconds']

r = r['result']
for rr in r:
temp = dict.fromkeys(keys)
temp['author'] = rr['author']['members'][0]['handle']
temp['startTimeSeconds'] = rr['creationTimeSeconds']

if 'startTimeSeconds' not in rr['author']:
temp['participantType'] = 'GYM'
else:
temp['participantType'] = rr['author']['participantType']

temp['id'] = rr['id']
temp['verdict'] = rr['verdict']
temp['contestID'] = rr['contestId']

if 'points' not in rr['problem']:
temp['points'] = 0
else:
temp['points'] = rr['problem']['points']

temp['problem_tags'] = rr['problem']['tags']
temp['problem_index'] = rr['problem']['index']
temp['problem_name'] = rr['problem']['name']
temp['timeMilliseconds'] = rr['timeConsumedMillis']
temp['memoryBytes'] = rr['memoryConsumedBytes']
temp['language'] = rr['programmingLanguage']
temp['relativeTimeSeconds'] = rr['relativeTimeSeconds']
temp['passedTestCount'] = rr['passedTestCount']
temp['testset'] = rr['testset']

dictlist.append(temp)
temp = dict.fromkeys(keys)
temp['author'] = rr['author']['members'][0]['handle']
temp['startTimeSeconds'] = rr['creationTimeSeconds']

if 'startTimeSeconds' not in rr['author']:
temp['participantType'] = 'GYM'
else:
temp['participantType'] = rr['author']['participantType']

temp['id'] = rr['id']
temp['verdict'] = rr['verdict']
if 'contestId' not in rr: continue
temp['contestID'] = rr['contestId']

if 'points' not in rr['problem']:
temp['points'] = 0
else:
temp['points'] = rr['problem']['points']

temp['problem_tags'] = rr['problem']['tags']
temp['problem_index'] = rr['problem']['index']
temp['problem_name'] = rr['problem']['name']
temp['timeMilliseconds'] = rr['timeConsumedMillis']
temp['memoryBytes'] = rr['memoryConsumedBytes']
temp['language'] = rr['programmingLanguage']
temp['relativeTimeSeconds'] = rr['relativeTimeSeconds']
temp['passedTestCount'] = rr['passedTestCount']
temp['testset'] = rr['testset']

dictlist.append(temp)

df_userActivity = pd.DataFrame.from_dict(dictlist)
return df_userActivity

Expand All @@ -196,10 +204,9 @@ def getUserRatingHistory(handle):

r = requests.get(url).json()
if r['status'] == 'FAILED':
expectedMessage = 'handle: User with handle ' + str(handle) + ' not found'
if r['comment'] == expectedMessage:
raise UserNotFound(handle)

expectedMessage = 'handle: User with handle ' + str(handle) + ' not found'
if r['comment'] == expectedMessage:
raise UserNotFound(handle)
r = r['result']
rating_history = pd.DataFrame.from_dict(r)
return rating_history
Expand Down
Binary file added ui/api_functions_v2.pyc
Binary file not shown.
187 changes: 187 additions & 0 deletions ui/bad_contests.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
925
927
958
952
924
926
953
923
929
928
921
916
910
905
886
889
890
888
885
887
884
883
873
874
863
847
858
860
861
857
856
846
852
845
838
837
825
823
826
818
819
820
821
817
813
802
808
773
803
775
772
797
774
795
784
792
771
770
769
761
762
753
751
728
730
726
718
720
717
712
710
703
702
691
690
695
693
683
678
684
643
642
641
665
663
664
640
661
660
656
639
652
647
646
638
644
637
632
636
628
630
622
620
616
612
609
600
598
597
594
595
589
575
566
562
541
537
532
530
531
524
523
522
491
484
485
470
440
411
409
398
399
396
397
394
392
393
391
390
386
374
345
328
323
311
312
306
301
302
291
290
267
212
209
207
206
188
190
185
182
172
171
170
162
159
158
153
147
134
130
125
120
119
100
98
99
76
72
64
52
50
45
44
39
21
20
15
8 changes: 6 additions & 2 deletions ui/elo.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,14 @@ def get_problem_elo(problem_df):
def get_contest_elo(contestID):
try:
contest_df = af.getSolveSuccessDF(contestID)
except:
except Exception as e:
with open('bad_contests.txt', 'a') as f:
f.write(str(contestID) + '\n')
return None

if contest_df.shape[0] < 50:
with open('bad_contests.txt', 'a') as f:
f.write(str(contestID) + '\n')
return None

contestID = contest_df.contestID.unique()[0]
Expand Down
Binary file added ui/elo.pyc
Binary file not shown.
Loading