def getCurrentMatch(summonerName, region="NA"): riotapi.set_region(region) summoner = riotapi.get_summoner_by_name(summonerName) match = riotapi.get_current_game(summoner) if match is None: return None roleMap = allRoles(match) # for x in roleMap: # print x.champion.name, x.side.name, roleMap[x] if len(roleMap.keys()) < 10: print "Role confusion!" return None statMap = {} rankMap = {} nonNormMap = {} for p in match.participants: role = roleMap[p] stats, nonNorm, rank = avgPerformance.getAvgPerformance(p, role) if stats is None: #currently filling with avg gold? stats = getAvg() rank = "unranked" statMap[p.side.name+role] = list(stats) rankMap[p] = rank nonNormMap[p] = nonNorm print p.summoner_name, p.side.name+role statVector = (statMap['blueTop']+statMap['blueMid']+statMap['blueJung']+ statMap['blueSup']+statMap['blueADC']+statMap['redTop']+ statMap['redMid']+statMap['redJung']+statMap['redSup']+ statMap['redADC']) model = fetchModel(match) results = model.predict_proba(statVector) return format.prepareReturn(roleMap, rankMap, nonNormMap, results, match)
def isInGame(player): summoner = riotapi.get_summoner_by_name(player) current_game = riotapi.get_current_game(summoner) if current_game is None: return False else: return True
def checkgame(zone,name): try: riotapi.set_region(zone) cgame = riotapi.get_current_game(riotapi.get_summoner_by_name(name)) except: print("printing traceback:") traceback.print_exc() if cgame is None: return jsonify({'current_game_exists': False}) else: return jsonify({'current_game_exists': True})
def get_current_game(summoner): currentGame = riotapi.get_current_game(summoner) if currentGame: blueSide = [] redSide = [] #print currentGame.to_json() for player in currentGame.participants: if player.side == Side.blue: blueSide.append(player) else: redSide.append(player) print_players(blueSide, redSide) else: print "That summoner is not currently in a game."
def get_current_game( summoner ): currentGame = riotapi.get_current_game( summoner ) if currentGame: blueSide = [] redSide = [] #print currentGame.to_json() for player in currentGame.participants: if player.side == Side.blue: blueSide.append(player) else: redSide.append(player) print_players( blueSide, redSide ) else: print "That summoner is not currently in a game."
async def game(self, ctx, sum_name: str, region: str): if region is None: try: db = database.Database('guilds.db') region = db.find_entry(ctx.guild.id) db.close_connection() except TypeError: embed = utilities.error_embed( ctx, "Please specify a region, or set a default region with `b!region set [region]`." ) await ctx.send("", embed=embed) return if "'" in sum_name: embed = utilities.error_embed( ctx, "Please use quotation marks to enclose names") await ctx.send("", embed=embed) return await ctx.trigger_typing() try: riotapi.set_region(region) except ValueError: embed = utilities.error_embed( ctx, "{0} is not a valid region! Valid regions are listed in `b!region list`." .format(region)) await ctx.send("", embed=embed) return try: summoner = riotapi.get_summoner_by_name(sum_name) game = riotapi.get_current_game(summoner) except APIError as exception: await Summoner.raise_exception(self, ctx, exception, sum_name, region) return try: does_game_exist = game.id except AttributeError: embed = utilities.error_embed( ctx, "{} is not in an active game!".format(summoner.name)) await ctx.send("", embed=embed) return
def main(): # Setup riotapi riotapi.set_region("NA") riotapi.print_calls(False) key = os.environ["DEV_KEY"] # You can create an env var called "DEV_KEY" that holds your developer key. It will be loaded here. riotapi.set_api_key(key) riotapi.set_load_policy(LoadPolicy.lazy) summoner = riotapi.get_summoner_by_name("Dyrs") # SummonerID is 5908 # dyrus = riotapi.get_summoner_by_id(5908) # You could use this as well current_game = riotapi.get_current_game(summoner) if current_game is None: print("{0} is not in-game!".format(summoner)) else: print("{0} is in-game!".format(summoner))
def main(): # Setup riotapi riotapi.set_region("NA") riotapi.print_calls(False) key = os.environ["DEV_KEY"] # You can create an env var called "DEV_KEY" that holds your developer key. It will be loaded here. riotapi.set_api_key(key) riotapi.set_load_policy(LoadPolicy.lazy) summoner = riotapi.get_summoner_by_name("Dyrus") # SummonerID is 5908 # dyrus = riotapi.get_summoner_by_id(5908) # You could use this as well current_game = riotapi.get_current_game(summoner) if current_game is None: print("{0} is not in-game!".format(summoner)) else: print("{0} is in-game!".format(summoner))
def getCurrentMatch(summonerName, region="NA"): riotapi.set_region(region) try: summoner = riotapi.get_summoner_by_name(summonerName) match = riotapi.get_current_game(summoner) except APIError as e: print e return None if match is None: return None if match.mode.name != "classic": print "Not classic" return None roleMap = allRoles(match) if len(roleMap.keys()) < 10: roleMap = assignRandom(match) print "Role confusion!" statMap = {} rankMap = {} nonNormMap = {} for p in match.participants: role = roleMap[p] try: stats, nonNorm, rank = avgPerformance.getAvgPerformance(p, role) except: stats = getAvg(p.side.name+role) rank = "unranked" nonNorm = [0, 0, 0, 0, 0, 0] statMap[p.side.name+role] = list(stats) rankMap[p] = rank nonNormMap[p] = nonNorm print p.summoner_name, p.side.name+role statVector = (statMap['blueTop']+statMap['blueMid']+statMap['blueJung']+ statMap['blueSup']+statMap['blueADC']+statMap['redTop']+ statMap['redMid']+statMap['redJung']+statMap['redSup']+ statMap['redADC']) model = fetchModel(match, rankMap) results = model.predict_proba(statVector) return format.prepareReturn(roleMap, rankMap, nonNormMap, results, match)
def test_current_game(): int_test_handler.test_result( riotapi.get_current_game( riotapi.get_summoner_by_id(int_test_handler.summoner_id)))
def test_current_game(): int_test_handler.test_result(riotapi.get_current_game(riotapi.get_summoner_by_id(int_test_handler.summoner_id)))
def check_ingame(summoner=me): return riotapi.get_current_game(summoner)
def currentgame(zone,summonername): # Make the cgame (try to get this info pass from the ajax eventually) riotapi.set_region(zone) cgame = riotapi.get_current_game(riotapi.get_summoner_by_name(summonername)) # Gather all participants and the champ they play participants = cgame.participants # Show each participants key info like damage type (individual + team aggregate), badges(veteran, newbie, hot streak, etc.), maybe counter info text scraped from lolcounter # Average damage for all roles from now. Add a role filter to adjust it later that player can toggle when they figure out what lane champs go to. # Split into teams blueteam = [] redteam = [] # Holder to construct counters dict to avoid duplicate champs counters_set = set() # Iterate through players for p in participants: # Format data into a dict champs = ChampionGeneral.query.filter_by(key=p.champion.key).all() physicaldmg = sum([value.physicaldmg for value in champs]) / len(champs) magicdmg = sum([value.magicdmg for value in champs]) / len(champs) truedmg = sum([value.truedmg for value in champs]) / len(champs) data = { 'name': p.summoner_name, 'champion': p.champion.name, 'champion_id': p.champion.id, 'champion_key': p.champion.key, 'physical': physicaldmg, 'magical': magicdmg, 'true': truedmg } # Add team average dmg composition and matching advice (AD->Get armor, AP->Get mr, True/mix->Get HP+mix) blue_physical = sum([each['physical'] for each in blueteam]) / 5 blue_magical = sum([each['magical'] for each in blueteam]) / 5 blue_true = sum([each['true'] for each in blueteam]) / 5 red_physical = sum([each['physical'] for each in redteam]) / 5 red_magical = sum([each['magical'] for each in redteam]) / 5 red_true = sum([each['true'] for each in redteam]) / 5 # Make set of champs to fetch counter tips after loop counters_set.add(p.champion.key) print('key') print(p.champion.key) # ====== Add additional info on amount of CC/offensive skills ====== # For each participant # Fetch participant's champion # Fetch tags associated with that champion from db or cass/riotapi and look for CC, heal, shield, etc. # Create a dictionary of CHAMP: [list of tags] # Use dict in template # Add additional info on amount of shields/defensive skills (maybe make it affect the armor/mr suggestion, like # if champions on the team have a lot of shields or effects that already give armor/mr # Sort into teams if p.side.name == 'blue': blueteam.append(data) else: redteam.append(data) # ===Outside for loop=== # Create counters dict counters = {} for champ in counters_set: print('counterchamp and its counters:') print(champ) c = ChampionCounter.query.filter_by(key=champ).first() # Add a dictionary entry of CHAMPNAME : [LIST OF TIPS] counters[champ] = [tip for tip in c.counters] print(counters[champ]) return render_template('currentgame.html', round=round, blueteam=blueteam, blue_average=(blue_physical, blue_magical, blue_true), redteam=redteam, red_average=(red_physical, red_magical, red_true), counters=counters)