Advertisement
tzoonami

Untitled

Feb 23rd, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.01 KB | None | 0 0
  1. import requests
  2.  
  3. class Team:
  4.     def __init__(self, name, abbrev):
  5.         self.name=name
  6.         self.abbrev=abbrev
  7.         self.elo=1000
  8.  
  9. def expected(A, B):
  10.     return 1 / (1 + 10 ** ((B - A) / 400))
  11. def elo(old, exp, score, k=24):
  12.     return old + k * (score - exp)
  13.  
  14. if __name__ == "__main__":
  15.     teamresp = requests.get('https://api.overwatchleague.com/ranking')
  16.     if teamresp.status_code != 200:
  17.         raise ApiError('GET /ranking {}'.format(teamresp.status_code))
  18.     #print(teamresp.json()['content'][0])
  19.     teams = {}
  20.     for team in teamresp.json()['content']:
  21.         teams[team['competitor']['id']] = Team(team['competitor']['name'],team['competitor']['abbreviatedName'])
  22.     #for teamid in teams.keys():
  23.         #print(teamid,teams[teamid].name)
  24.     resp = requests.get('https://api.overwatchleague.com/schedule')
  25.     if resp.status_code != 200:
  26.         raise ApiError('GET /schedule {}'.format(resp.status_code))
  27.     for match in resp.json()['data']['stages'][0]['matches']:
  28.         if match['state'] != "CONCLUDED":
  29.             break
  30.         A = teams[match['competitors'][0]['id']]
  31.         B = teams[match['competitors'][1]['id']]
  32.         print(A.name, "vs", B.name)
  33.         for game in match['games']:
  34.             exp = expected(A.elo,B.elo)
  35.             print("{0} vs {1} map {2} EV {3:.3f}".format(A.abbrev,B.abbrev,game['number'],exp))
  36.             points = game['points']
  37.             if points[0] > points[1]:
  38.                 A.elo = elo(A.elo,exp,1)
  39.                 B.elo = elo(B.elo,1-exp,0)
  40.                 print("{0} wins, ELOs {1:.1f} {2:.1f}".format(A.abbrev,A.elo,B.elo))
  41.             elif points[0] < points[1]:
  42.                 A.elo = elo(A.elo,exp,0)
  43.                 B.elo = elo(B.elo,1-exp,1)
  44.                 print("{0} wins, ELOs {1:.1f} {2:.1f}".format(B.abbrev,A.elo,B.elo))
  45.             else:
  46.                 A.elo = elo(A.elo,exp,0.5)
  47.                 B.elo = elo(B.elo,1-exp,0.5)
  48.                 print("draw, ELOs {0:.1f} {1:.1f}".format(A.elo,B.elo))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement