def test_championmastery(): me = Summoner(name="Kalturi", id=21359666, region="NA") karma = Champion(name="Karma", id=43, region="NA") cm = ChampionMastery(champion=karma, summoner=me, region="NA") cm = cass.get_champion_mastery(champion=karma, summoner=me, region="NA") 'Champion ID:', cm.champion.id 'Mastery points:', cm.points 'Mastery Level:', cm.level 'Points until next level:', cm.points_until_next_level cms = cass.get_champion_masteries(summoner=me, region="NA") cms = me.champion_masteries cms[0].points cms["Karma"].points # Does a ton of calls without a cache "{} has mastery level 6 or higher on:".format(me.name) pro = cms.filter(lambda cm: cm.level >= 6) [cm.champion.name for cm in pro]
async def get_champion_mastery(self, champion, region, msg) -> ChampionMastery: """Returns ChampionMastery object""" try: champion = Champion(name=champion, region="NA") mastery = ChampionMastery(summoner=self.summoner, champion=champion, region=region) mastery.points return mastery except TypeError as exception: await Exceptions().raise_exception(self.ctx, exception, "cm", msg, champion) return except APIRequestError as exception: await Exceptions().raise_exception(self.ctx, exception, "", msg, None) return
def index(): # show summoner results once fields are submitted and hide otherwise if request.vars.name is None or request.vars.name2 is None: show_results = False else: show_results = True all_champions = Champions(region="NA") r_val = randint(0, len(all_champions) - 1) champ = all_champions[r_val] skins = champ.skins r_val2 = randint(0, len(skins) - 1) random_skin = skins[r_val2] loading = False if show_results: region_selected = request.vars.reg # user input for region selection summoner_name = request.vars.name # user input for summoner 1 summoner_name2 = request.vars.name2 # user input for summoner 2 if request.vars.champs is None: champion_name = "Ahri" # default selection (can be any champion) else: champion_name = request.vars.champs try: summoner = Summoner(name=str(summoner_name), region=region_selected) summoner2 = Summoner(name=str(summoner_name2), region=region_selected) if (summoner.exists == False or summoner2.exists == False): redirect(URL('default', 'index')) all_champions = Champions(region=region_selected) champ = all_champions[champion_name] r_val3 = randint(0, len(champ.skins) - 1) r_val4 = randint(0, len(champ.skins) - 1) mh_playing_champ = summoner.match_history.filter( lambda mh: mh.participants[summoner].champion == champ) mh_playing_champ2 = summoner2.match_history.filter( lambda mh: mh.participants[summoner2].champion == champ) mh_len = len(mh_playing_champ) mh_len2 = len(mh_playing_champ2) matches_blue_team = [1, 2, 3, 4, 5] matches_red_team = [1, 2, 3, 4, 5] matches_blue_team2 = [1, 2, 3, 4, 5] matches_red_team2 = [1, 2, 3, 4, 5] matches_sum = [0] * mh_len matches_sum2 = [0] * mh_len2 sum_wins = 0 sum_wins2 = 0 sum_average_kills = 0 sum_average_kills2 = 0 sum_average_deaths = 0 sum_average_deaths2 = 0 sum_average_assists = 0 sum_average_assists2 = 0 sum_average_damage = 0 sum_average_damage2 = 0 sum_average_minions = 0 sum_average_minions2 = 0 sum_average_vision = 0 sum_average_vision2 = 0 last_frame_index = 0 latest_frame = 0 insufficient_info = False if mh_len > 9: index = 0 while index < mh_len - 1: if mh_playing_champ[index].participants[ summoner].stats.win: sum_wins += 1 index += 1 else: insufficient_info = True insufficient_info2 = False if mh_len2 > 9: index = 0 while index < mh_len2 - 1: if mh_playing_champ2[index].participants[ summoner2].stats.win: sum_wins2 += 1 index += 1 else: insufficient_info2 = True insufficient_info = False if mh_len > 9: index = 0 print("index:" + str(index)) print("mh_len:" + str(mh_len)) while index < mh_len - 1: matches_sum[index] = mh_playing_champ[index].participants[ summoner].stats.kills index += 1 sum_average_kills = str(round(sum(matches_sum) / mh_len, 1)) else: insufficient_info = True insufficient_info2 = False if mh_len2 > 9: index = 0 while index < mh_len2 - 1: matches_sum2[index] = mh_playing_champ2[ index].participants[summoner2].stats.kills index += 1 sum_average_kills2 = str(round(sum(matches_sum2) / mh_len2, 1)) else: insufficient_info2 = True insufficient_info = False if mh_len > 9: index = 0 while index < mh_len - 1: matches_sum[index] = mh_playing_champ[index].participants[ summoner].stats.deaths index += 1 sum_average_deaths = str(round(sum(matches_sum) / mh_len, 1)) else: insufficient_info = True insufficient_info2 = False if mh_len2 > 9: index = 0 while index < mh_len2 - 1: matches_sum2[index] = mh_playing_champ2[ index].participants[summoner2].stats.deaths index += 1 sum_average_deaths2 = str(round( sum(matches_sum2) / mh_len2, 1)) else: insufficient_info2 = True insufficient_info = False if mh_len > 9: index = 0 while index < mh_len - 1: matches_sum[index] = mh_playing_champ[index].participants[ summoner].stats.assists index += 1 sum_average_assists = str(round(sum(matches_sum) / mh_len, 1)) else: insufficient_info = True insufficient_info2 = False if mh_len2 > 9: index = 0 while index < mh_len2 - 1: matches_sum2[index] = mh_playing_champ2[ index].participants[summoner2].stats.assists index += 1 sum_average_assists2 = str( round(sum(matches_sum2) / mh_len2, 1)) else: insufficient_info2 = True insufficient_info = False if mh_len > 9: index = 0 while index < mh_len - 1: matches_sum[index] = mh_playing_champ[index].participants[ summoner].stats.total_damage_dealt_to_champions index += 1 sum_average_damage = str(int(sum(matches_sum) / mh_len)) else: insufficient_info = True insufficient_info2 = False if mh_len2 > 9: index = 0 while index < mh_len2 - 1: matches_sum2[index] = mh_playing_champ2[ index].participants[ summoner2].stats.total_damage_dealt_to_champions index += 1 sum_average_damage2 = str(int(sum(matches_sum2) / mh_len2)) else: insufficient_info2 = True insufficient_info = False if mh_len > 9: index = 0 while index < mh_len - 1: matches_sum[index] = ( mh_playing_champ[index].participants[summoner].stats. total_minions_killed + mh_playing_champ[index]. participants[summoner].stats.neutral_minions_killed) index += 1 sum_average_minions = str(int(sum(matches_sum) / mh_len)) else: insufficient_info = True insufficient_info2 = False if mh_len2 > 9: index = 0 while index < mh_len2 - 1: matches_sum2[index] = ( mh_playing_champ2[index].participants[summoner2].stats. total_minions_killed + mh_playing_champ2[index]. participants[summoner2].stats.neutral_minions_killed) index += 1 sum_average_minions2 = str(int(sum(matches_sum2) / mh_len2)) else: insufficient_info2 = True insufficient_info = False if mh_len > 9: index = 0 while index < mh_len - 1: matches_sum[index] = mh_playing_champ[index].participants[ summoner].stats.vision_score index += 1 sum_average_vision = str(round(sum(matches_sum) / mh_len, 2)) else: insufficient_info = True insufficient_info2 = False if mh_len2 > 9: index = 0 while index < mh_len2 - 1: matches_sum2[index] = mh_playing_champ2[ index].participants[summoner2].stats.vision_score index += 1 sum_average_vision2 = str(round( sum(matches_sum2) / mh_len2, 2)) else: insufficient_info2 = True # index = 0 # for s in summoner.match_history[0].blue_team.participants: # matches_blue_team[index] = Champion(name=str(s.champion.name)) # index += 1 # # index = 0 # for s in summoner.match_history[0].red_team.participants: # matches_red_team[index] = Champion(name=str(s.champion.name)) # index += 1 # index = 0 # for s in summoner2.match_history[0].blue_team.participants: # matches_blue_team2[index] = Champion(name=str(s.champion.name)) # index += 1 # # index = 0 # for s in summoner2.match_history[0].red_team.participants: # matches_red_team2[index] = Champion(name=str(s.champion.name)) # index += 1 cm = ChampionMastery(champion=champ, summoner=summoner, region=region_selected) try: solo_rank = str(summoner.leagues.fives.tier) + " " + str( summoner.leagues.fives.entries[summoner].division) pass # exception case if solo rank does not exist for summoner 1 except KeyError: solo_rank = "N/A" pass try: flex_rank = str(summoner.leagues.flex.tier) + " " + str( summoner.leagues.flex.entries[summoner].division) # exception case if flex rank does not exist for summoner 1 except KeyError: flex_rank = "N/A" pass cm2 = ChampionMastery(champion=champ, summoner=summoner2, region=region_selected) try: solo_rank2 = str(summoner2.leagues.fives.tier) + " " + str( summoner2.leagues.fives.entries[summoner2].division) pass # exception case if solo rank does not exist for summoner 2 except KeyError: solo_rank2 = "N/A" pass try: flex_rank2 = str(summoner2.leagues.flex.tier) + " " + str( summoner2.leagues.flex.entries[summoner2].division) # exception case if flex rank does not exist for summoner 2 except KeyError: flex_rank2 = "N/A" pass # exception case for blank fields for summoner 1 or summoner 2 except KeyError: redirect(URL('default', 'index')) pass return dict(show_results=show_results, random_skin=random_skin, champ=champ, summoner=summoner, summoner2=summoner2, cm=cm, cm2=cm2, solo_rank=solo_rank, solo_rank2=solo_rank2, flex_rank=flex_rank, flex_rank2=flex_rank2, matches_blue_team=matches_blue_team, matches_red_team=matches_red_team, matches_blue_team2=matches_blue_team2, matches_red_team2=matches_red_team2, sum_average_kills=sum_average_kills, sum_average_kills2=sum_average_kills2, sum_average_deaths=sum_average_deaths, sum_average_deaths2=sum_average_deaths2, sum_average_assists=sum_average_assists, sum_average_assists2=sum_average_assists2, sum_average_damage=sum_average_damage, sum_average_damage2=sum_average_damage2, sum_average_minions=sum_average_minions, sum_average_minions2=sum_average_minions2, sum_average_vision=sum_average_vision, sum_average_vision2=sum_average_vision2, sum_wins=sum_wins, sum_wins2=sum_wins2, insufficient_info=insufficient_info, insufficient_info2=insufficient_info2, mh_len=mh_len, mh_len2=mh_len2, r_val3=r_val3, r_val4=r_val4) else: return dict(show_results=show_results, random_skin=random_skin)