def __init__(self, json): self.timeline = json['timeline']['frames'] self.teamBlue = json['teams'][0] self.teamRed = json['teams'][1] self.region = json['region'] self.patch = json['matchVersion'] self.queueType = QueueType(json['queueType']) self.mapId = json['mapId'] self.teamBlueId = self.teamBlue['teamId'] self.teamRedId = self.teamRed['teamId'] self.winner = self.teamBlueId if self.teamBlue['winner'] else self.teamRedId self.participants = json['participants'] self.participantToTeam = {part['participantId']: part['teamId'] for part in json['participants']} self.participantToChamp = {part['participantId']: part['championId'] for part in json['participants']} self.participantToElo = defaultdict(lambda: EloType.ANY) self.summonerIdToParticipant = defaultdict(lambda:0) self.summonerIdToParticipant.update({p['player']['summonerId']:p['participantId'] for p in json['participantIdentities'] if 'player' in p}) dl = getDownloader(self.region.lower()) if self.summonerIdToParticipant: try: ans = dl.api_request("/api/lol/{region}/v2.5/league/by-summoner/{summonerId}/entry".format(region = self.region.lower(), summonerId = ",".join(str(p) for p in self.summonerIdToParticipant)), _reg = self.region.lower()) summonerToRanking = {summonerId:defaultdict(lambda:EloType.UNRANKED, {QueueType(ranking['queue']):EloType(ranking['tier']) for ranking in ans[str(summonerId)]} if str(summonerId) in ans else dict()) for summonerId in self.summonerIdToParticipant} self.participantToElo.update({self.summonerIdToParticipant[summId]: summonerToRanking[summId][self.queueType] for summId in self.summonerIdToParticipant}) except AnswerException as e: if e.answer.status != 404: raise self.participantToElo.update({self.summonerIdToParticipant[summonerId]:EloType.UNRANKED for summonerId in self.summonerIdToParticipant})
def __init__(self, json): self.timeline = json['timeline']['frames'] self.teamBlue = json['teams'][0] self.teamRed = json['teams'][1] self.region = json['region'] self.patch = json['matchVersion'] self.queueType = QueueType(json['queueType']) self.mapId = json['mapId'] self.teamBlueId = self.teamBlue['teamId'] self.teamRedId = self.teamRed['teamId'] self.winner = self.teamBlueId if self.teamBlue[ 'winner'] else self.teamRedId self.participants = json['participants'] self.participantToTeam = { part['participantId']: part['teamId'] for part in json['participants'] } self.participantToChamp = { part['participantId']: part['championId'] for part in json['participants'] } self.participantToElo = defaultdict(lambda: EloType.ANY) self.summonerIdToParticipant = defaultdict(lambda: 0) self.summonerIdToParticipant.update({ p['player']['summonerId']: p['participantId'] for p in json['participantIdentities'] if 'player' in p }) dl = getDownloader(self.region.lower()) if self.summonerIdToParticipant: try: ans = dl.api_request( "/api/lol/{region}/v2.5/league/by-summoner/{summonerId}/entry" .format(region=self.region.lower(), summonerId=",".join( str(p) for p in self.summonerIdToParticipant)), _reg=self.region.lower()) summonerToRanking = { summonerId: defaultdict( lambda: EloType.UNRANKED, { QueueType(ranking['queue']): EloType( ranking['tier']) for ranking in ans[str(summonerId)] } if str(summonerId) in ans else dict()) for summonerId in self.summonerIdToParticipant } self.participantToElo.update({ self.summonerIdToParticipant[summId]: summonerToRanking[summId][self.queueType] for summId in self.summonerIdToParticipant }) except AnswerException as e: if e.answer.status != 404: raise self.participantToElo.update({ self.summonerIdToParticipant[summonerId]: EloType.UNRANKED for summonerId in self.summonerIdToParticipant })
def get_playerid(region, playername): dl = rp.getDownloader(region=region) try: req_time = time.time() response = dl.api_request('/api/lol/{region}/v1.4/summoner/by-name/{summonerName}'.format(region=region, summonerName=playername)) print('Took {time_sec} seconds to query'.format(time_sec=time.time()-req_time)) return (response.get(playername, dict()).get('id', None),) except rp.AnswerException: return None
def loadGame(region, gameID): """Loads and parses a game into the then stored data format: For every item that is bought in the game and not undone, keep an entry and store whether that game was won or lost @param region: the region the game took place in @param gameID: the id of the game to load @return: a Game object that contains data about the game """ dl = getDownloader(region) gameAnswer = dl.api_request('/api/lol/{region}/v2.2/match/{matchId}'.format(region = region, matchId = gameID), _reg = region, includeTimeline = True) #with open("../data/raw/games/{region}_{id}.pkl".format(region = region, id = gameID) , 'wb') as file: # pickle.dump(gameAnswer, file) return Game(gameAnswer)
def loadGame(region, gameID): """Loads and parses a game into the then stored data format: For every item that is bought in the game and not undone, keep an entry and store whether that game was won or lost @param region: the region the game took place in @param gameID: the id of the game to load @return: a Game object that contains data about the game """ dl = getDownloader(region) gameAnswer = dl.api_request( '/api/lol/{region}/v2.2/match/{matchId}'.format(region=region, matchId=gameID), _reg=region, includeTimeline=True) #with open("../data/raw/games/{region}_{id}.pkl".format(region = region, id = gameID) , 'wb') as file: # pickle.dump(gameAnswer, file) return Game(gameAnswer)
def get_mastery_blob(region, playerid): dl = rp.getDownloader(region=region) platformIdMap = { 'br': 'BR1', 'eune': 'EUN1', 'euw': 'EUW1', 'jp': 'JP1', 'kr': 'KR', 'lan': 'LA1', 'las': 'LA2', 'na': 'NA1', 'oce': 'OC1', 'ru': 'RU', 'tr': 'TR1' } try: req_time = time.time() response = dl.api_request('/championmastery/location/{platformId}/player/{playerId}/champions'.format(platformId=platformIdMap[region], playerId=playerid)) print('Took {time_sec} seconds to query'.format(time_sec=time.time()-req_time)) return (json.dumps({a['championId']:make_mastery_data(a)._asdict() for a in response}).encode('utf-8'), time_millis()) except rp.AnswerException: pass
''' Created on 25.08.2015 @author: Katora ''' from . import relevantVersions from riotapi import getDownloader idToMap = {} nameToMap = {} for patch in relevantVersions: dl = getDownloader() mapAnswer = dl.api_request("/api/lol/static-data/euw/v1.2/map", version=patch) itemsVersion = mapAnswer['version'] identifierToMap = mapAnswer['data'] idToMap.update({ int(identifierToMap[name]['mapId']): identifierToMap[name] for name in identifierToMap }) nameToMap.update({idToMap[id]['mapName']: idToMap[id] for id in idToMap})
''' Created on 25.08.2015 @author: Katora ''' from . import relevantVersions from riotapi import getDownloader idToMap = {} nameToMap = {} for patch in relevantVersions: dl = getDownloader() mapAnswer = dl.api_request("/api/lol/static-data/euw/v1.2/map", version = patch) itemsVersion = mapAnswer['version'] identifierToMap = mapAnswer['data'] idToMap.update({int(identifierToMap[name]['mapId']):identifierToMap[name] for name in identifierToMap}) nameToMap.update({idToMap[id]['mapName']:idToMap[id] for id in idToMap})