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 test_mastery_returns_correct_data(): summoner = cassiopeia.get_summoner(name=SUMMONER_NAME) masteries = cassiopeia.get_champion_masteries(summoner.id) on_champ = masteries[0] from_single_call = cassiopeia.get_champion_mastery(SUMMONER_NAME, on_champ.champion) #assert on_champ._data[cassiopeia.core.championmastery.ChampionMasteryData]._dto == from_single_call._data[cassiopeia.core.championmastery.ChampionMasteryData]._dto assert on_champ.points == from_single_call.points
def test_mastery_return(): summ = cassiopeia.get_summoner(name=SUMMONER_NAME) champ = cassiopeia.get_champion(CHAMP_NAME) champ_mastery = cassiopeia.get_champion_mastery(summ.id, champion=champ) assert isinstance(champ_mastery, cassiopeia.ChampionMastery) assert isinstance(champ_mastery.summoner, cassiopeia.Summoner) assert isinstance(champ_mastery.champion, cassiopeia.Champion) assert champ_mastery.summoner.name == SUMMONER_NAME assert champ_mastery.champion.name == CHAMP_NAME
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]
def test_championmastery(): me = Summoner(name="Kalturi", 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]
def test_mastery_return(): summoner = cassiopeia.get_summoner(name=SUMMONER_NAME, region="NA") champion = cassiopeia.get_champion(CHAMP_NAME, region="NA") champion_mastery = cassiopeia.get_champion_mastery(summoner=summoner.id, champion=champion, region="NA") assert isinstance(champion_mastery, cassiopeia.ChampionMastery) assert isinstance(champion_mastery.summoner, cassiopeia.Summoner) assert isinstance(champion_mastery.champion, cassiopeia.Champion) assert champion_mastery.summoner == summoner assert champion_mastery.champion == champion assert isinstance(champion_mastery.platform, Platform) assert isinstance(champion_mastery.region, Region) assert isinstance(champion_mastery.chest_granted, bool) assert isinstance(champion_mastery.last_played, arrow.Arrow) assert isinstance(champion_mastery.level, int) and champion_mastery.level <= 7 assert isinstance(champion_mastery.points, int) assert isinstance(champion_mastery.points_since_last_level, int) assert isinstance(champion_mastery.points_until_next_level, int)
def print_champion_mastery(): # Name: Kalturi # ID: 21359666 # Account ID: 34718348 me = Summoner(name="Kalturi", id=21359666) karma = Champion(name="Karma", id=43) #cm = ChampionMastery(champion=karma, summoner=me) cm = cass.get_champion_mastery(champion=karma, summoner=me) print('Champion ID:', cm.champion.id) print('Mastery points:', cm.points) print('Mastery Level:', cm.level) print('Points until next level:', cm.points_until_next_level) cms = cass.get_champion_masteries(summoner=me) cms = me.champion_masteries print(cms[0].points) # print(cms["Karma"].points) # Does a ton of calls without a cache print("{} has mastery level 6 or higher on:".format(me.name)) pro = cms.filter(lambda cm: cm.level >= 6) print([cm.champion.name for cm in pro])
async def live(ctx, name: str = None): if name == None: await ctx.send('Введите никнейм призывателя') await ctx.message.delete() else: await ctx.message.delete() key = os.environ.get('RIOT') cass.set_riot_api_key(key) cass.set_default_region("RU") summoner = cass.get_summoner(name=name) match = cass.get_current_match(summoner) rt = summoner.current_match.red_team.participants rteam = "" bteam = "" masters = { '7': '<:Level_7:736291517676912660>', '6': '<:Level_6:736291517592764426>', '5': '<:Level_5:736291517416603658>', '4': '<:Level_4:736291517068738631>', } tiers = { 'Iron': '<:Iron:736282364874850386>', 'Bronze': '<:Bronze:736282364984164503>', 'Silver': '<:Silver:736282365177102436>', 'Gold': '<:Gold:736282364866723861>', 'Platinum': '<:Platinum:736282365252337724>', 'Diamond': '<:Diamond:736282364795420773>', 'Master': '<:Master:736282365202006131>', 'Grandmaster': '<:Grandmaster:736282364849684531>', 'Challenger': '<:Challenger:736282365504127047>', } for x in rt: cm = '' tier = '' try: tier = str(x.summoner.league_entries[0].tier) tier = tiers[tier] cmm = cass.get_champion_mastery(x.summoner, x.champion, region='RU') cm = masters[str(cmm.level)] except: pass rteam = rteam + '\n' + '(' + str( x.summoner.level ) + ')' + x.summoner.name + ' - ' + cm + x.champion.name + ' ' + tier bt = summoner.current_match.blue_team.participants for x in bt: cm = '' tier = '' try: tier = str(x.summoner.league_entries[0].tier) tier = tiers[tier] cmm = cass.get_champion_mastery(x.summoner, x.champion, region='RU') cm = masters[str(cmm.level)] except: pass bteam = bteam + '\n' + '(' + str( x.summoner.level ) + ')' + x.summoner.name + ' - ' + cm + x.champion.name + ' ' + tier mode = match.map.name ava = summoner.profile_icon.url t = 'Лайв игра: ' + name em = discord.Embed(title=t, color=0xf5f5f5) em.add_field(name='Синяя команда:', value=bteam, inline=True) em.add_field(name='Красная команда:', value=rteam, inline=True) em.set_footer(text=str(mode), icon_url=ava) await ctx.send(embed=em)
def get_team_data(match, team, gameDuration, color, region): match.properties["blueFirstBlood"] = team.first_blood # Metrics to collect blueKills = 0 blueDeaths = 0 blueAssists = 0 blueEliteMonsters = 0 blueDragons = 0 blueHeralds = 0 blueBarons = 0 blueTowersDestroyed = 0 blueTotalGold = 0 blueAvgLevel = 0 blueTotalExperience = 0 blueTotalMinionsKilled = 0 blueTotalJungleMinionsKilled = 0 blueGoldDiff = 0 blueExperienceDiff = 0 blueCSPerMin = 0 blueGoldPerMin = 0 wards_placed = 0 wards_destroyed = 0 buildings_destroyed = 0 # Temporary variables totalLevel = 0 totalCS = 0 totalMastery = 0 for p in team.participants: p_state = p.cumulative_timeline[gameDuration] summ = p.summoner totalMastery += cass.get_champion_mastery(champion=p.champion, summoner=summ, region=region).points for temp_event in p_state._processed_events: if temp_event.type == "WARD_PLACED": wards_placed += 1 elif temp_event.type == "WARD_KILL": wards_destroyed += 1 elif temp_event.type == "BUILDING_KILL": buildings_destroyed += 1 elif temp_event.type == "ELITE_MONSTER_KILL": blueEliteMonsters += 1 if temp_event.monster_type == "DRAGON": blueDragons += 1 elif temp_event.monster_type == "BARON_NASHOR": blueBarons += 1 else: blueHeralds += 1 wards_destroyed += 1 blueKills += p_state.kills blueDeaths += p_state.deaths blueAssists += p_state.assists totalLevel += p_state.level blueTotalExperience += p_state.experience blueTotalGold += p_state.gold_earned totalCS += p_state.creep_score totalCS += p_state.neutral_minions_killed blueCSPerMin = float(totalCS) / float(gameDuration.total_seconds() / 60) blueGoldPerMin = blueTotalGold / float(gameDuration.total_seconds() / 60) blueAvgLevel = float(totalLevel) / 5 match.properties[color + "Kills"] = blueKills match.properties[color + "Deaths"] = blueDeaths match.properties[color + "Assists"] = blueAssists match.properties[color + "AvgLevel"] = blueAvgLevel match.properties[color + "TotalExperience"] = blueTotalExperience match.properties[color + "CSPerMin"] = blueCSPerMin match.properties[color + "GoldPerMin"] = blueGoldPerMin match.properties[color + "WardsPlaced"] = wards_placed match.properties[color + "WardsDestroyed"] = wards_destroyed match.properties[color + "dragons"] = blueDragons match.properties[color + "EliteMonsters"] = blueEliteMonsters match.properties[color + "Heralds"] = blueHeralds match.properties[color + "Barons"] = blueBarons match.properties[color + "TotalMastery"] = totalMastery
api_key = '' region = 'eune' import sys import cassiopeia as cs cs.set_riot_api_key(api_key) cs.set_default_region(region) summoner = cs.get_summoner(name=sys.argv[1]) champion = sys.argv[2] if champion == "Lee": champion = "Lee Sin" if champion == "Xin": champion = "Xin Zhao" print("\n MASTERY POINTS : ", cs.get_champion_mastery(summoner, champion).points)