Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- class Team:
- def __init__(self, name, abbrev):
- self.name=name
- self.abbrev=abbrev
- self.elo=1000
- def expected(A, B):
- return 1 / (1 + 10 ** ((B - A) / 400))
- def elo(old, exp, score, k=24):
- return old + k * (score - exp)
- if __name__ == "__main__":
- teamresp = requests.get('https://api.overwatchleague.com/ranking')
- if teamresp.status_code != 200:
- raise ApiError('GET /ranking {}'.format(teamresp.status_code))
- #print(teamresp.json()['content'][0])
- teams = {}
- for team in teamresp.json()['content']:
- teams[team['competitor']['id']] = Team(team['competitor']['name'],team['competitor']['abbreviatedName'])
- #for teamid in teams.keys():
- #print(teamid,teams[teamid].name)
- resp = requests.get('https://api.overwatchleague.com/schedule')
- if resp.status_code != 200:
- raise ApiError('GET /schedule {}'.format(resp.status_code))
- for match in resp.json()['data']['stages'][0]['matches']:
- if match['state'] != "CONCLUDED":
- break
- A = teams[match['competitors'][0]['id']]
- B = teams[match['competitors'][1]['id']]
- print(A.name, "vs", B.name)
- for game in match['games']:
- exp = expected(A.elo,B.elo)
- print("{0} vs {1} map {2} EV {3:.3f}".format(A.abbrev,B.abbrev,game['number'],exp))
- points = game['points']
- if points[0] > points[1]:
- A.elo = elo(A.elo,exp,1)
- B.elo = elo(B.elo,1-exp,0)
- print("{0} wins, ELOs {1:.1f} {2:.1f}".format(A.abbrev,A.elo,B.elo))
- elif points[0] < points[1]:
- A.elo = elo(A.elo,exp,0)
- B.elo = elo(B.elo,1-exp,1)
- print("{0} wins, ELOs {1:.1f} {2:.1f}".format(B.abbrev,A.elo,B.elo))
- else:
- A.elo = elo(A.elo,exp,0.5)
- B.elo = elo(B.elo,1-exp,0.5)
- print("draw, ELOs {0:.1f} {1:.1f}".format(A.elo,B.elo))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement