codeforces의 최근 contest에서
등급이 올라간 유저와 등급이 내려간 유저들을 구해봅니다.
최근 컨테스트들의 아이디를 얻습니다.
컨테스트 아이디로 레이팅의 변화를 살펴보고 간단히 처리합니다.
아래 파이썬 스크립트를 실행하면 이번 컨테스트에서 강등/승급한 사람이 몇 명인지 보여줍니다.
import requests
import time
#import datetime
#import json
# codeforces의 가장 최근 콘테스트에서,
# 승급한 사람과 강등당한 사람을 구해봅니다.
URL='https://codeforces.com/api/'
method1='contest.list'
payload={'gym':'false'}
URI=URL+method1
response=requests.get(URI,payload)
print(response.status_code) #succeeded?
result=response.json()['result']
#print(result)
ContestName={}
#print("time now : ",datetime.datetime.now())
print("time now:",time.time())
nowtime=time.time()
for res in result:
#ContestId[res['name']]=res['id']
ContestName[res['id']]=res['name']
cnt=0
RecentContestId=[]
for res in result:
if res['startTimeSeconds']>=nowtime: #not yet started contests -> skip
continue
if cnt>=30:
break
RecentContestId.append(res['id'])
cnt+=1
# < show all Contest's name,Id>
# for name,id in ContestId.items():
# print(name,id)
########################################################################
#RatingChange
#Represents a participation of user in rated contest.
ratings={}
for i in range(-1000,4000):
if i<1200:
ratings[i]='newbie'
continue
if i<1400:
ratings[i]='pupil'
continue
if i<1600:
ratings[i] = 'specialist'
continue
if i < 1900:
ratings[i] = 'expert'
continue
if i < 2100:
ratings[i] = 'candidate master'
continue
if i < 2300:
ratings[i] = 'master'
continue
if i < 2400:
ratings[i] = 'International master'
continue
if i < 2600:
ratings[i] = 'Grandmaster'
continue
if i < 3000:
ratings[i] = 'International Grandmaster'
continue
ratings[i]='Legandary Grandmaster'
method2 = 'contest.ratingChanges'
for Id in RecentContestId[:1]: #가장 최근 콘테스트만 살펴보았습니다.
URI=URL+method2
payload={'contestId':Id}
response=requests.get(URI,payload)
print(response.status_code) #succeeded?
result=response.json()['result']
#print(result)
#print(type(result))
userInfos = []
Sames=[]
Changed = []
Ups = []
Downs = []
for res in result:
#print(res)
userInfo=[]
userInfo.append(res['handle'])
userInfo.append(res['oldRating'])
userInfo.append(res['newRating'])
userInfos.append(userInfo)
# if res['oldRating']<0 or res['newRating']>4000: #there exists negative rated user!
# print(res)
#print(userInfos)
specialist_up=0
specialist_down=0
experts_up=0
experts_down=0
for user in userInfos:
if ratings[user[1]] !=ratings[user[2]]:
Changed.append(user)
if user[1] > user[2]: # rated down
tmp=[]
tmp.append(user[0])
tmp.append(ratings[user[1]])
tmp.append(ratings[user[2]])
Downs.append(tmp)
if tmp[2]=='expert':
experts_down+=1
if tmp[2]=='specialist':
specialist_down+=1
else: #rated up
tmp = []
tmp.append(user[0])
tmp.append(ratings[user[1]])
tmp.append(ratings[user[2]])
Ups.append(tmp)
if tmp[2]=='expert':
experts_up+=1
if tmp[2] == 'specialist':
specialist_up += 1
else:
Sames.append(user)
print("Contest : ",ContestName[Id])
print("same", len(Sames))
print("changed",len(Changed))
print("ups",len(Ups))
print("downs",len(Downs))
#이번 콘테스트에서 expert가 된 사람들.
print("became expert (by rated up):",experts_up)
print("became expert (by rated down):", experts_down)
# 이번 콘테스트에서 specialist가 된 사람들.
print("became specialist (by rated up):", specialist_up)
print("became specialist (by rated down):", specialist_down)
낮은 구간에선 올라가는 사람들이 더 많습니다.