Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- from operator import itemgetter
- class Team:
- def __init__(self, name, abbrev,maps):
- self.name=name
- self.abbrev=abbrev
- self.elo=1000
- self.maps = maps
- 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))
- mapresp = requests.get('https://api.overwatchleague.com/maps')
- if mapresp.status_code != 200:
- raise ApiError('GET /ranking {}'.format(mapresp.status_code))
- maps = {}
- for map in mapresp.json():
- maps[map['guid']]=map['name']['en_US']
- #print(maps)
- #print(teamresp.json()['content'][0])
- teams = {}
- for team in teamresp.json()['content']:
- teammaps={}
- for map in maps.keys():
- teammaps[map] = 1000
- teams[team['competitor']['id']] = Team(team['competitor']['name'],team['competitor']['abbreviatedName'],teammaps)
- 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))
- print(resp.json()['data']['stages'][0]['matches'][0]['games'][0]['attributes']['mapGuid'])
- 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)
- gamemap = game['attributes']['mapGuid']
- mapexp = expected(A.maps[gamemap],B.maps[gamemap])
- print("{0} vs {1} map {2} - {3} EV {4:.3f} map EV {5:.3f}".format(A.abbrev,B.abbrev,game['number'],maps[gamemap],exp,mapexp))
- points = game['points']
- if points[0] > points[1]:
- A.elo = elo(A.elo,exp,1)
- A.maps[gamemap] = elo(A.maps[gamemap],mapexp,1)
- B.elo = elo(B.elo,1-exp,0)
- B.maps[gamemap] = elo(B.maps[gamemap],1-mapexp,0)
- print("{0} wins, ELOs {1:.1f} {2:.1f} {3:.1f} {4:.1f}".format(A.abbrev,A.elo,B.elo,A.maps[gamemap],B.maps[gamemap]))
- elif points[0] < points[1]:
- A.elo = elo(A.elo,exp,0)
- A.maps[gamemap] = elo(A.maps[gamemap],mapexp,0)
- B.elo = elo(B.elo,1-exp,1)
- B.maps[gamemap] = elo(B.maps[gamemap],1-mapexp,1)
- print("{0} wins, ELOs {1:.1f} {2:.1f} {3:.1f} {4:.1f}".format(B.abbrev,A.elo,B.elo,A.maps[gamemap],B.maps[gamemap]))
- else:
- A.elo = elo(A.elo,exp,0.5)
- A.maps[gamemap] = elo(A.maps[gamemap],mapexp,0.5)
- B.elo = elo(B.elo,1-exp,0.5)
- B.maps[gamemap] = elo(B.maps[gamemap],1-mapexp,0.5)
- print("draw, ELOs {0:.1f} {1:.1f} {2:.1f} {3:.1f}".format(A.elo,B.elo,A.maps[gamemap],B.maps[gamemap]))
- print()
- teamelos = {}
- for teamid in teams.keys():
- teamelos[teamid]=teams[teamid].elo
- i=1
- for key, value in sorted(teamelos.items(), key = itemgetter(1), reverse = True):
- print("{0}: {1} {2:.1f}".format(i,teams[key].name,value))
- i+=1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement