def main(): summoner = input("Please enter a summoner's name: ") with open('secret.json') as f: api_key = json.load(f)['riot-key'] cass.set_riot_api_key(api_key) summoner = cass.get_summoner(name=summoner, region=REGION) match_history = Summoner(name=summoner.name, region=REGION).match_history( begin_time=Patch.from_str("9.1", region=REGION).start) match_info_rows = [] for match in match_history: match_info = {} match_info['id'] = match.id match_info['queue_id'] = match.queue.id match_info['patch'] = match.patch match_info['creation'] = match.creation match_info['champion'] = match.participants[summoner].champion.name match_info['win'] = match.participants[summoner].team.win match_info['kills'] = match.participants[summoner].stats.kills match_info['deaths'] = match.participants[summoner].stats.deaths match_info['assists'] = match.participants[summoner].stats.assists match_info['kda'] = match.participants[summoner].stats.kda match_info_rows.append(match_info) match_history_df = pd.DataFrame(match_info_rows) match_history_df.set_index('id') # all_champions = cass.Champions(region=REGION) # sub_test(api_key) print(match_history_df) filename = summoner + '_matchhistory.csv' filepath = os.path.join('data', filename) match_history_df.to_csv(filepath)
def get_spectator_matches(df, champions_data): featured_matches = cass.get_featured_matches(region="EUW") starting_patch = Patch.from_str("9.16", region="EUW") for new_match in featured_matches: if new_match.queue.id == 420 and df[df['match_id'] == new_match.id].shape[0] == 0: match = {'match_id': int(new_match.id)} participants = new_match.blue_team.participants + new_match.red_team.participants for (p, id) in zip(participants, range(1, 11)): current_summoner = Summoner(id=p.summoner.id, region="EUW") match[f'{id}_kda'], match[f'{id}_winrate'] = get_average_kda( current_summoner, starting_patch, new_match.creation.shift(minutes=-10), p.champion.id) cm = cass.get_champion_mastery(champion=p.champion.id, summoner=current_summoner, region="EUW") match[f'{id}_cm_points'] = int(cm.points) champion_data = champions_data[champions_data['name'] == p.champion.name].winrate match[f'{id}_champion_winrate'] = champion_data.iloc[0] match_series = pd.Series(match) df = df.append(match_series, ignore_index=True) df.to_csv('spectator_data.csv', index=None, header=True)
def collect_matches(): initial_summoner_name = "GustavEnk" region = "EUW" summoner = Summoner(name=initial_summoner_name, region=region) patch = Patch.from_str("8.9", region=region) unpulled_summoner_ids = SortedList([summoner.id]) pulled_summoner_ids = SortedList() unpulled_match_ids = SortedList() pulled_match_ids = SortedList() while unpulled_summoner_ids: # Get a random summoner from our list of unpulled summoners and pull their match history new_summoner_id = random.choice(unpulled_summoner_ids) new_summoner = Summoner(id=new_summoner_id, region=region) matches = filter_match_history(new_summoner, patch) unpulled_match_ids.update([match.id for match in matches]) unpulled_summoner_ids.remove(new_summoner_id) pulled_summoner_ids.add(new_summoner_id) while unpulled_match_ids: # Get a random match from our list of matches new_match_id = random.choice(unpulled_match_ids) new_match = Match(id=new_match_id, region=region) for participant in new_match.participants: if participant.summoner.id not in pulled_summoner_ids and participant.summoner.id not in unpulled_summoner_ids: unpulled_summoner_ids.add(participant.summoner.id) # The above lines will trigger the match to load its data by iterating over all the participants. # If you have a database in your datapipeline, the match will automatically be stored in it. unpulled_match_ids.remove(new_match_id) pulled_match_ids.add(new_match_id)
def collect_matches(summoner_name, region_name): summoner = Summoner(name = summoner_name, region = region_name) patch = Patch.from_str("9.22", region = region_name) unpulled_summoner_ids = SortedList([summoner.id]) pulled_summoner_ids = SortedList() unpulled_match_ids = SortedList() pulled_match_ids = SortedList() while unpulled_summoner_ids: new_summoner_id = random.choice(unpulled_summoner_ids) new_summoner = Summoner(id=new_summoner_id, region=region_name) matches = filter_match_history(new_summoner, patch) unpulled_match_ids.update([match.id for match in matches]) unpulled_summoner_ids.remove(new_summoner_id) pulled_summoner_ids.add(new_summoner_id) while unpulled_match_ids: new_match_id = random.choice(unpulled_match_ids) new_match = Match(id=new_match_id, region=region_name) for participant in new_match.participants: if participant.summoner.id not in pulled_summoner_ids and participant.summoner.id not in unpulled_summoner_ids: unpulled_summoner_ids.add(participant.summoner.id) unpulled_match_ids.remove(new_match_id) pulled_match_ids.add(new_match_id)
def collectMatches(): summoner = Summoner(name="Ung5r", region="NA") # A default summoner to pull matches from patchNo = Patch.from_str('8.2', region="NA") # Create some sorted lists to store the IDs of players and matches being analyzed. # Match info can only be pulled on a player basis so we'll have to pull each player # from a match to then get further match info. unpulledSummonerIDS = SortedList([summoner.id]) pulledSummonerIDS = SortedList() unpulledMatchIDS = SortedList() pulledMatchIDS = SortedList() matchesList = [] while unpulledSummonerIDS and len(pulledMatchIDS) < 5000: newSummonerID = random.choice(unpulledSummonerIDS) try: newSummoner = Summoner(id=newSummonerID, region="NA") except: print("Unable to retrieve new summoner, retrying in 10s") time.sleep(10) newSummoner = Summoner(id=newSummonerID, region="NA") matches = filterHistory(newSummoner, patchNo) try: unpulledMatchIDS.update([ match.id for match in matches if match.id not in unpulledMatchIDS ]) except: print("Unable to add to unpulled matches, retrying in 10s") time.sleep(10) unpulledMatchIDS.update([ match.id for match in matches if match.id not in unpulledMatchIDS ]) unpulledSummonerIDS.remove(newSummonerID) pulledSummonerIDS.add(newSummonerID) while unpulledMatchIDS: newMatchID = random.choice(unpulledMatchIDS) try: newMatch = Match(id=newMatchID, region="NA") except: print("Unable to retrieve new match, retrying in 10s") time.sleep(10) newMatch = Match(id=newMatchID, region="NA") for participant in newMatch.participants: if participant.summoner.id not in pulledSummonerIDS and participant.summoner.id not in unpulledSummonerIDS: unpulledSummonerIDS.add(participant.summoner.id) unpulledMatchIDS.remove(newMatchID) if newMatchID not in pulledMatchIDS: pulledMatchIDS.add(newMatchID) # Populate the list of matches by match ID for entry in pulledMatchIDS: matchesList.append(kass.get_match(id=entry, region="NA")) return matchesList
def get_matches(summoner): patch = Patch.from_str("10.8", region="NA") print(patch.start) end_time = patch.end if end_time is None: end_time = arrow.now() match_history = cass.get_match_history(summoner=summoner, seasons={Season.season_9}, queues={Queue.ranked_solo_fives}, begin_time=1585206000) return match_history
def collect_matches(): ''' Collects matches and summoners id in order to feed handle_prints() matches. Discovers new summoners in the games of a default summoner ''' summoner: Summoner = Summoner(name=INIT_SUMMONER, region=REGION) patch: Patch = Patch.from_str(PATCH, region=REGION) pulled_summoner_ids: SortedList[str] = SortedList() unpulled_summoner_ids: SortedList[str] = SortedList([summoner.id]) pulled_match_ids: SortedList[str] = SortedList() input_df = pd.read_csv(MATCHES_FILE, sep='\t') pulled_match_counter = -input_df.shape[0] starting_pulled_ids = SortedList(input_df.id) del input_df unpulled_match_ids: SortedList[str] = SortedList() while unpulled_summoner_ids: # get a random summoner from our list of unpulled summoners and pull their match history new_summoner_id: int = random.choice(unpulled_summoner_ids) new_summoner: Summoner = Summoner(id=new_summoner_id, region=REGION) matches: MatchHistory = filter_match_history(new_summoner, patch) unpulled_match_ids.update([match.id for match in matches]) unpulled_summoner_ids.remove(new_summoner_id) pulled_summoner_ids.add(new_summoner_id) global printed_matches [handle_print(match) for match in matches if match.id not in starting_pulled_ids and printed_matches < MAX_MATCHES] if printed_matches >= MAX_MATCHES: break while unpulled_match_ids: # Get a random match from our list of matches new_match_id: int = random.choice(unpulled_match_ids) new_match: Match = Match(id=new_match_id, region=REGION) for participant in new_match.participants: participant: Participant if participant.summoner.id not in pulled_summoner_ids and participant.summoner.id not in unpulled_summoner_ids: unpulled_summoner_ids.add(participant.summoner.id) # The above lines will trigger the match to load its data by iterating over all the participants. unpulled_match_ids.remove(new_match_id) pulled_match_ids.add(new_match_id) pulled_match_counter = pulled_match_counter + 1
def collect_gosu_matches(players_id): match_ids_dict = {} try: region_str = players_id.keys() with open("./LOLData/matchIDs" + patch_ver + ".csv", "r") as csvfile: csvreader = csv.reader(csvfile) for region_name, gosu_ids in zip(region_str, csvreader): match_ids_dict[region_name] = gosu_ids except: for region_name in players_id.keys(): patch = Patch.from_str(patch_ver, region=region_name) summoner_ids = players_id[region_name] match_ids = set([]) for i, summoner_id in enumerate(summoner_ids): try: new_summoner = Summoner(account_id=summoner_id, region=region_name) matches = filter_match_history(new_summoner, patch) match_ids.update([match.id for match in matches]) print('Now match ids length is {}'.format(len(match_ids))) print('Now used summoners are {} / {}'.format( i + 1, len(summoner_ids))) except: print("Server error raise. Wait for 1 second.") time.sleep(1) pass match_ids = list(match_ids) match_ids_dict[region_name] = match_ids with open("./LOLData/matchIDs" + patch_ver + ".csv", "a", newline="") as csvfile: csvwriter = csv.writer(csvfile) csvwriter.writerow(match_ids) return match_ids_dict
def test_season_start_end_using_patches(): assert Season.season_7.start(Region.north_america) == Patch.from_str( "7.1", region=Region.north_america).start assert Season.season_8.end(Region.north_america) == None
def test_unknown_patch_raises(): with pytest.raises(ValueError): Patch.from_str("unknown patch")
def test_season_start_end_using_patches(): assert Season.season_7.start(Region.north_america) == Patch.from_str("7.1", region=Region.north_america).start assert Season.season_8.end(Region.north_america) == None
def get_comps(summoners): if len(summoners) < 5: # return None pass champion_pool = [] # Maps names to champions so we don't have to make individual calls to the API name_mapping = { champion.id: champion.name for champion in cass.get_champions(region=region) } count = 0 for player in summoners: if count == 0: position = 'TOP' elif count == 1: position = 'JUNGLE' elif count == 2: position = 'MIDDLE' elif count == 3: position = 'BOTTOM' elif count == 4: position = 'UTILITY' # Summoner specific data summoner = Summoner(name=player, region=region) champion_details = get_champion_details( get_match_stats( summoner.match_history( begin_time=Patch.from_str(start_patch).start, end_time=Patch.from_str(end_patch).end, queues={Queue.ranked_solo_fives}), summoner, name_mapping), position) champion_pool += champion_details count += 1 viable_comps = [] for comp in generate_team_comps(champion_pool): is_viable = is_viable_comp(comp) if is_viable: for champion in comp: if champion['role'] == 'TOP': top = champion elif champion['role'] == 'JUNGLE': jungle = champion elif champion['role'] == 'MIDDLE': middle = champion elif champion['role'] == 'BOTTOM': bottom = champion else: support = champion viable_comp = TeamComposition(top=top, jungle=jungle, mid=middle, bot=bottom, support=support) rating = viable_comp.assess_comp() if rating['score'] == 100: viable_comps.append({ 'champions': viable_comp, 'rating': rating['score'], 'full_score': rating['full_score'] }) else: continue viable_comps = sorted(random.sample(viable_comps, len(viable_comps)), key=lambda i: i['full_score'], reverse=True) return viable_comps[0:20]
def test_known_patches(): assert isinstance(Patch.from_str('1.0.0.152', region="NA"), Patch) assert isinstance(Patch.from_str('5.19', region="NA"), Patch) assert isinstance(Patch.from_str('7.22', region="NA"), Patch)
async def on_message(message): # ignore message from itself if message.author == client.user: return # extract content args = message.content.split() # check for search command if args[0] == config.prefix + 'search': # if there is no username, return if (len(args) == 1): return await message.channel.send('Incorrect usage! You need to supply a username as well!') # prepare name spaces = ' ' args.pop(0) username = spaces.join(args) # just for console print('The extracted username is: ' + username) # send notice await message.channel.send('Let me check...') # create summoner object print('Attempting to create summoner object (Region NA)..') summoner_name = Summoner(name=username, region="NA") # attempt to look up match history print('Attempting to look up match history...') try: match_hist = summoner_name.match_history(begin_time=Patch.from_str("10.7", region="NA").start) except Exception as e: print(e) return await message.channel.send('That username does not exist!') # check if you are looking for a win streak or a loss streak looking_for_win = False if (match_hist[0].participants[summoner_name].team.win is True): looking_for_win = True # count match streak match_counter = 1 while (True): next_turnout = match_hist[match_counter].participants[summoner_name].team.win if (looking_for_win and not next_turnout) or (not looking_for_win and next_turnout): break match_counter += 1 # print results print('Printing out result for ' + username) if looking_for_win: return await message.channel.send(username + ' is on a ' + str(match_counter) + ' game winning streak.') else: return await message.channel.send(username + ' is on a ' + str(match_counter) + ' game losing streak.') # if user supplied help command, show search if args[0] == config.prefix + 'help': return await message.channel.send('The proper command is `' + config.prefix + 'search <username>`.') # if user supplied invalid command, show search if args[0][0:2] == config.prefix: return await message.channel.send('Invalid usage! Do `' + config.prefix + 'search <username>`.')