def get_current_game_data(self, summoner_name): summoner_id = RiotApi.get_summoner_id(summoner_name) if not summoner_id: return None current_game = RiotApi.get_current_game_data(summoner_id) if current_game: players = current_game.get("participants") for player in players: del player["masteries"] del player["runes"] del player["profileIconId"] player["champion"] = self.champions[str(player["championId"])] player["spell1"] = self.summoner_spells[str(player["spell1Id"])] player["spell2"] = self.summoner_spells[str(player["spell2Id"])] return players return None
def get_build_data(self, ids): data = [] aggregatedIds = [] games_request_path = '/api/lol/na/v1.3/game/by-summoner/%s/recent' games_request_params = { 'api_key': self.api_key } for id in ids: print 'Querying summoner id: %s' % id games = RiotApi.get(games_request_path % id, games_request_params)['games'] for game in games: output = {} output['champion'] = game.get('championId', None) stats = game.get('stats', None) if stats: output['item1'] = stats.get('item1', None) output['item2'] = stats.get('item2', None) output['item3'] = stats.get('item3', None) output['item4'] = stats.get('item4', None) output['item5'] = stats.get('item5', None) output['item6'] = stats.get('item6', None) output['win'] = stats.get('win', None) output['kills'] = stats.get('championsKilled', None) output['deaths'] = stats.get('numDeaths', None) output['assists'] = stats.get('assists', None) data.append(output) fellowPlayers = game.get('fellowPlayers', None) if fellowPlayers: for fellowPlayer in fellowPlayers: aggregatedIds.append(fellowPlayer.get('summonerId', None)) return data, list(set(aggregatedIds))
def get_build_data(self, ids): data = [] aggregatedIds = [] games_request_path = '/api/lol/na/v1.3/game/by-summoner/%s/recent' games_request_params = {'api_key': self.api_key} for id in ids: print 'Querying summoner id: %s' % id games = RiotApi.get(games_request_path % id, games_request_params)['games'] for game in games: output = {} output['champion'] = game.get('championId', None) stats = game.get('stats', None) if stats: output['item1'] = stats.get('item1', None) output['item2'] = stats.get('item2', None) output['item3'] = stats.get('item3', None) output['item4'] = stats.get('item4', None) output['item5'] = stats.get('item5', None) output['item6'] = stats.get('item6', None) output['win'] = stats.get('win', None) output['kills'] = stats.get('championsKilled', None) output['deaths'] = stats.get('numDeaths', None) output['assists'] = stats.get('assists', None) data.append(output) fellowPlayers = game.get('fellowPlayers', None) if fellowPlayers: for fellowPlayer in fellowPlayers: aggregatedIds.append(fellowPlayer.get('summonerId', None)) return data, list(set(aggregatedIds))
def get_items(self): items_request_path = '/api/lol/static-data/na/v1.2/item' items_request_params = { 'locale': 'en_US', 'itemListData': 'all', 'api_key': self.api_key } return RiotApi.get(items_request_path, items_request_params).get('data', None)
def get_champions(self): champions_request_path = '/api/lol/static-data/na/v1.2/champion' champions_request_params = { 'locale': 'en_US', 'champData': 'tags', 'api_key': self.api_key } return RiotApi.get(champions_request_path, champions_request_params).get('data', None)
def get_current_game_data(self, summoner_name): summoner_id = RiotApi.get_summoner_id(summoner_name) if not summoner_id: return None current_game = RiotApi.get_current_game_data(summoner_id) if current_game: players = current_game.get("participants") for player in players: del player["masteries"] del player["runes"] del player["profileIconId"] player["champion"] = self.champions[str(player["championId"])] player["spell1"] = self.summoner_spells[str( player["spell1Id"])] player["spell2"] = self.summoner_spells[str( player["spell2Id"])] return players return None
def get_summoner_ids(self, summoner_names): summoners_request_path = '/api/lol/na/v1.4/summoner/by-name/%s' % ( ','.join(summoner_names)) summoners_request_params = {'api_key': self.api_key} summoners = RiotApi.get(summoners_request_path, summoners_request_params) ids = [] for summoner in summoners: ids.append(summoners[summoner].get('id', None)) return ids
def get_summoner_ids(self, summoner_names): summoners_request_path = '/api/lol/na/v1.4/summoner/by-name/%s' % ( ','.join(summoner_names)) summoners_request_params = { 'api_key': self.api_key } summoners = RiotApi.get(summoners_request_path, summoners_request_params) ids = [] for summoner in summoners: ids.append(summoners[summoner].get('id', None)) return ids
def generate_report(some_summ, match_count): matches = RiotApi.get_matches_by_account(some_summ.get_account_id(), match_count) print('Retrieved {} matches'.format(matches['endIndex'] - matches['startIndex'])) full_report = [] match_num = 0 for match in matches['matches']: match_num += 1 match = Match(match['gameId']) match_raw = match.get_data() # Only matchmade Rift, bois if match_raw['gameMode'] != 'CLASSIC' or match_raw[ 'gameType'] != 'MATCHED_GAME': match_report = "{} is non-Rift or custom".format(match_num) print(match_report) full_report.append(match_report) continue # Find desired summoner among participants desired_id = 0 for part_id in match_raw['participantIdentities']: if part_id['player']['accountId'] == some_summ.get_account_id(): desired_id = part_id['participantId'] break # Display champion and match stats for part in match_raw['participants']: if part['participantId'] == desired_id: champ_name = Champion.get_name(part['championId']) cs = (part['stats']['totalMinionsKilled'] + part['stats']['neutralMinionsKilled']) game_dur = match_raw['gameDuration'] cs_per_min = cs / float(game_dur / 60) report = "{} : {}, {}cs / {}min {}s = {:0.2f}cs/min".format( match_num, champ_name, cs, game_dur // 60, game_dur % 60, cs_per_min) full_report.append(report) print(report) break return full_report
def main(argv): mongo_url = "mongodb://localhost:27017" collection = "matches" parser = argparse.ArgumentParser(description='Map match id to builds') parser.add_argument( "-t", default="any", help="Test single input. 'any' for random match (default)") parser.add_argument("-c", default=collection, help="Collection to process") parser.add_argument("--mongo", default=mongo_url, help="URL of MongoDB") args = parser.parse_args() # Initialize MongoDB mongo_client = MongoClient(args.mongo) outliers_db = mongo_client.outliers # Initialize components riot_items = RiotItems() match_processor = MatchProcessor(riot_items) input_db = outliers_db[args.c] # Test script if args.t: match_id = args.t if args.t == 'any': match_id = input_db.find_one()["matchId"] match = RiotApi.get_match(match_id) print "Processing Match: %d" % match["matchId"] trimmed = match_processor.trim_match(match) participants = match_processor.get_builds_from_match(match) print "[Trimmed]:" print trimmed print "[Builds]:" for p in participants: translate_build(riot_items, p["build"]["finalBuild"]) return
def main(argv): mongo_url = "mongodb://localhost:27017" collection = "matches" parser = argparse.ArgumentParser(description='Map match id to builds') parser.add_argument("-t", default="any", help="Test single input. 'any' for random match (default)") parser.add_argument("-c", default=collection, help="Collection to process") parser.add_argument("--mongo", default=mongo_url, help="URL of MongoDB") args = parser.parse_args() # Initialize MongoDB mongo_client = MongoClient(args.mongo) outliers_db = mongo_client.outliers # Initialize components riot_items = RiotItems() match_processor = MatchProcessor(riot_items) input_db = outliers_db[args.c] # Test script if args.t: match_id = args.t if args.t == 'any': match_id = input_db.find_one()["matchId"] match = RiotApi.get_match(match_id) print "Processing Match: %d" % match["matchId"] trimmed = match_processor.trim_match(match) participants = match_processor.get_builds_from_match(match) print "[Trimmed]:" print trimmed print "[Builds]:" for p in participants: translate_build(riot_items, p["build"]["finalBuild"]) return
def create(): api_key = RiotApi.get_default_api_key() return DataAggregator(api_key)
def get_summoner_mastery_info(self, summoner_name): summoner_id = RiotApi.get_summoner_id(summoner_name) if not summoner_id: return None mastery = RiotApi.get_champion_mastery_data(summoner_id) return mastery
def create(): return DataAnalyzer(RiotApi.get_champions(), RiotApi.get_summoner_spells())
def main(argv): mongo_url = "mongodb://localhost:27017" last_update = datetime_to_timestamp(PlayerDb.EARLIEST_UPDATE) + 1 initial_seed = 60783 update_old = False workers = [1, 1] # Parse commandline for last_update date, and thread numbers parser = argparse.ArgumentParser(description='Collect data from Riot API') parser.add_argument("-i", default=initial_seed, type=int, help="Initial summoner ID") parser.add_argument("-n", default=workers, nargs=2, type=int, help="# of pworkers and mworkers, respectively") parser.add_argument("-d", help="Starting date to fetch data for") # TODO add commandline args parser.add_argument("--update_old", action='store_true', help="Whether to prioritize gathering of new player data") parser.add_argument("--mongo", default=mongo_url, help="URL of MongoDB") parser.add_argument("--api_key", default=API_KEY, help="Riot API Key") args = parser.parse_args() if args.d is not None: last_update = datetime_to_timestamp(datetime.datetime.strptime(args.d, "%m/%d/%y")) if args.api_key == "": print "API key not found. Please add your key to api_key.py or use --api_key" sys.exit(2) else: RiotApi.set_api_key(args.api_key) # Initialize MongoDB mongo_client = MongoClient(args.mongo) outliers_db = mongo_client.outliers # Initialize components api_scheduler = RiotApiScheduler() player_db = PlayerDb(outliers_db.players) match_db = MatchDb(outliers_db.matches) build_db = BuildDb(outliers_db) player_queue = Queue(maxsize=MAX_PLAYER_QSIZE) match_queue = Queue(maxsize=MAX_MATCH_QSIZE) riot_items = RiotItems() match_processor = MatchProcessor(riot_items) workers = [] # Initial seed player_queue.put({ "profileIcon": 588, "matchHistoryUri": "/v1/stats/player_history/NA/60783", "summonerName": "-INITIAL_SEED- (TheOddOne)", "summonerId": args.i, "last_update": datetime_to_timestamp(PlayerDb.EARLIEST_UPDATE), "league": "GOLD" }) # Register stop signal handler def stop(sig, frame): api_scheduler.stop() for worker in workers: worker.stop() print "[STOP] Players left: %r, Matches left: %r" % (player_queue.qsize(), match_queue.qsize()) signal.signal(signal.SIGINT, stop) # Start threads api_scheduler.start() for i in xrange(args.n[0]): worker = PlayerWorker( is_prioritize_new=not args.update_old, api_scheduler=api_scheduler, player_db=player_db, match_db=match_db, last_update=last_update, player_queue=player_queue, match_queue=match_queue, ) workers.append(worker) worker.start() for i in xrange(args.n[1]): worker = MatchWorker( last_update=last_update, api_scheduler=api_scheduler, player_db=player_db, match_db=match_db, build_db=build_db, player_queue=player_queue, match_queue=match_queue, match_processor=match_processor ) workers.append(worker) worker.start() # Janky way to quit program line = raw_input() if line == "q": stop(2, None)
def create(): return DataAnalyzer( RiotApi.get_champions(), RiotApi.get_summoner_spells() )