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 print_leagues(summoner_name: str, region: str): summoner = Summoner(name=summoner_name, region=region) print("Name:", summoner.name) print("ID:", summoner.id) # entries = cass.get_league_entries(summoner, region=region) entries = summoner.league_entries if entries.fives.promos is not None: # If the summoner is in their promos, print some info print("Promos progress:", entries.fives.promos.progress) print("Promos wins", entries.fives.promos.wins) print("Promos losses:", entries.fives.promos.losses) print("Games not yet played in promos:", entries.fives.promos.not_played) print("Number of wins required to win promos:", entries.fives.promos.wins_required) else: print("The summoner is not in their promos.") print("Name of leagues this summoner is in:") for entry in entries: print(entry.league.name) print() print(f"Listing all summoners in this league:") for position, entry in enumerate(entries.fives.league.entries): print(entry.summoner.name, entry.league_points, entry.tier, entry.division, position) print() print("Master's League name:") masters = cass.get_master_league(queue=Queue.ranked_solo_fives, region=region) print(masters.name)
def print_leagues(summoner_name: str, region: str): summoner = Summoner(name=summoner_name, region=region) print("Name:", summoner.name) print("ID:", summoner.id) # leagues = cass.get_leagues(summoner) leagues = summoner.leagues for league in leagues: print(league.name) print() print(leagues.fives.name) for entry in leagues.fives: print(entry.summoner.name, entry.league_points) print(entry.tier) print(entry.division) print(entry.region) print(entry.queue) print(entry.name) print() print() print("Challenger:") challenger = cass.get_challenger_league(queue=Queue.ranked_solo) print(challenger.name)
def region_check(self, region: str): """Checks a given region is valid""" try: Summoner(name="", region=region) return True except ValueError: return False
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 print_newest_match(name: str, region: str): summoner = Summoner(name = name, region = region) match_history = summoner.match_history match_history(seasons= {Season.season_9}, queues= {Queue.ranked_solo_fives}) champion_id_to_name_mapping = {champion.id: champion.name for champion in cass.get_champions(region=region)} played_champions = Counter() for match in match_history: champion_id = match.participants[summoner.name].champion.id champion_name = champion_id_to_name_mapping[champion_id] played_champions[champion_name] += 1 print("Length of match history:", len(match_history)) print("Top 10 champions {} played:".format(summoner.name)) for champion_name, count in played_champions.most_common(10): print(champion_name, count) print() match = match_history[0] print('Match ID:', match.id) p = match.participants[summoner] print("\nSince the match was created from a matchref, we only know one participant:") #print(p.summoner.name, 'playing', p.champion.name) print(p.id, p.summoner.region, p.summoner.account_id, p.summoner.name, p.summoner.id, p.champion.id) print("\nNow pull the full match data by iterating over all the participants:") for p in match.participants: #print(p.summoner.name, 'playing', p.champion.name) print(p.id, p.summoner.region, p.summoner.account_id, p.summoner.name, p.summoner.id, p.champion.id, p.team.first_dragon, p.runes.keystone.name) print("\nIterate over all the participants again and note that the data is not repulled:") for p in match.participants: #print(p.summoner.name, 'playing', p.champion.name) print(p.id, p.summoner.region, p.summoner.account_id, p.summoner.name, p.summoner.id, p.champion.id, p.team.first_dragon, p.runes.keystone.name) print("\nBlue team won?", match.blue_team.win) print("Red team won?", match.red_team.win) print("Participants on blue team:") for p in match.blue_team.participants: print(p.summoner.name, p.champion.name) # Print keystone and the stat runes for each player/champion for p in match.participants: print(p.champion.name, p.runes.keystone.name, *[r.name for r in p.stat_runes])
def print_newest_match(name: str, region: str): summoner = Summoner(name=name, region=region) match_history = summoner.match_history match_history(seasons={Season.season_9}, queues={Queue.ranked_solo_fives}) for match in match_history: champion_id = match.participants[summoner.name].champion.id match_url = match.participants[summoner.name].match_history_uri match = match_history[0] print(match.id, match_url, champion_id)
def get_accounts_in_league(summoner_name: str, region: str): acc_ids = [] summoner = Summoner(name=summoner_name, region=region) print("Name:", summoner.name) print("ID:", summoner.id) entries = summoner.league_entries print(f"Listing all summoners in this league:") for entry in entries.fives.league.entries: acc_ids.append(entry.summoner) return acc_ids
def print_leagues(summoner_name: str, region: str): summoner = Summoner(name=summoner_name, region=region) print("Name:", summoner.name) print("ID:", summoner.id) # positions = cass.get_league_positions(summoner, region=region) positions = summoner.league_positions if positions.fives.promos is not None: # If the summoner is in their promos, print some info print("Promos progress:", positions.fives.promos.progress) print("Promos wins", positions.fives.promos.wins) print("Promos losses:", positions.fives.promos.losses) print("Games not yet played in promos:", positions.fives.promos.not_played) print("Number of wins required to win promos:", positions.fives.promos.wins_required) else: print("The summoner is not in their promos.") print("Name of leagues this summoner is in:") for league in positions: print(league.name) print() # leagues = cass.get_leagues(summoner) leagues = summoner.leagues print( "Name of leagues this summoner is in (called from a different endpoint):" ) for league in leagues: print(league.name) print() print(f"Listing all summoners in {leagues.fives.name}") for entry in leagues.fives: print(entry.summoner.name, entry.league_points, entry.tier, entry.division) print() print("Challenger League name:") challenger = cass.get_challenger_league(queue=Queue.ranked_solo, region=region) print(challenger.name)
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 print_newest_match(name: str, account: int, id: int, region: str): # Notice how this function never makes a call to the summoner endpoint because we provide all the needed data! summoner = Summoner(name=name, account=account, id=id, region=region) # matches = cass.get_matches(summoner) match_history = summoner.match_history match = match_history[ 0] # TODO This is triggering two match history loads for some reason... print('Match ID:', match.id) p = match.participants[name] print( "\nSince the match was created from a matchref, we only know one participant:" ) #print(p.summoner.name, 'playing', p.champion.name) print(p.id, p.summoner.region, p.summoner.account.id, p.summoner.name, p.summoner.id, p.champion.id) print( "\nNow pull the full match data by iterating over all the participants:" ) for p in match.participants: #print(p.summoner.name, 'playing', p.champion.name) print(p.id, p.summoner.region, p.summoner.account.id, p.summoner.name, p.summoner.id, p.champion.id, p.team.first_dragon) print( "\nIterate over all the participants again and note that the data is not repulled:" ) for p in match.participants: #print(p.summoner.name, 'playing', p.champion.name) print(p.id, p.summoner.region, p.summoner.account.id, p.summoner.name, p.summoner.id, p.champion.id, p.team.first_dragon) print("\nBlue team won?", match.blue_team.win) print("Red team won?", match.red_team.win) print("Participants on blue team:") for p in match.blue_team.participants: print(p.summoner.name)
def get_summoner_information(): summoner_id = request.query.id if summoner_id in known_summoners: summoner = known_summoners[summoner_id] else: summoner = Summoner(id=summoner_id) known_summoners[summoner_id] = summoner information = {"gameIdentifier": summoner.name} if Queue.ranked_solo_fives in summoner.ranks and Queue.ranked_flex_fives in summoner.ranks: if summoner.ranks[Queue.ranked_solo_fives] > summoner.ranks[ Queue.ranked_flex_fives]: information["rank"] = summoner.ranks[ Queue.ranked_solo_fives].division.value information["tier"] = summoner.ranks[ Queue.ranked_solo_fives].tier.value else: information["rank"] = summoner.ranks[ Queue.ranked_flex_fives].division.value information["tier"] = summoner.ranks[ Queue.ranked_flex_fives].tier.value elif Queue.ranked_solo_fives in summoner.ranks: information["rank"] = summoner.ranks[ Queue.ranked_solo_fives].division.value information["tier"] = summoner.ranks[ Queue.ranked_solo_fives].tier.value elif Queue.ranked_flex_fives in summoner.ranks: information["rank"] = summoner.ranks[ Queue.ranked_flex_fives].division.value information["tier"] = summoner.ranks[ Queue.ranked_flex_fives].tier.value else: information["rank"] = "" information["tier"] = "" return information
import cassiopeia as cass import random import arrow from cassiopeia.core import Summoner, MatchHistory, Match from cassiopeia import Queue, Patch, Match, Season from cassiopeia.data import Role, Lane, Division, Tier import json import matplotlib.pyplot as plt conf = json.loads(open("config.json", "r").read()) cass.set_riot_api_key(conf["API_KEY"]) cass.set_default_region("NA") matches = cass.MatchHistory(summoner=Summoner(name="Tompson", region="NA"), queues=["ARAM"]) print(matches[0].blue_team.participants) cass.configuration.settings.expire_sinks() cass.configuration.settings.clear_sinks() for sink in cass.configuration.settings.pipeline._sinks: sink.expire(0) sink.clear(0) print(matches[0].blue_team.participants) input() while (len(users) != 0):
def summoner_wrapper(name, region): stripped_name = name.replace(" ", "") return Summoner(name=stripped_name, region=region)
def get_summoner_id(): summoner_name = request.query.name summoner = Summoner(name=summoner_name) return {"id": summoner.id}