async def winrate(self, ctx, person): """Gets winrate for a player over the past week""" summoner = Summoner(name=person, region="NA") await self.bot.say("It will take me a moment to do the math...") wins = 0 last_week = datetime.datetime.now() - datetime.timedelta(weeks=1) year = last_week.year month = last_week.month day = last_week.day matchhistory = cass.MatchHistory(summoner=summoner, begin_time=arrow.Arrow( year, month, day), end_time=arrow.now()) total_games = len(matchhistory) for match in matchhistory: if match.participants[summoner].team.win: wins += 1 winrate = round(wins / total_games * 100) await self.bot.send_message( ctx.message.channel, f"{person} has a win rate of **{winrate}%** with {wins} wins over {total_games} games this week. " )
def update_matches(player, region, min_time=7200, max_matches=100): try: match_history = cass.MatchHistory( summoner=cass.get_summoner(name=player), queues={cass.Queue.ranked_solo_fives})[:max_matches] return match_history except: return []
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): cuser = users[0]
def get_user_role_stats(summoner, games): """For the given userid, get ranked role distribution and winrates Keyword arguments: summoner -- a cass summoner object games -- number of games to query Returns: A dictionary of: user_id -- the user_id from riot, a string top_wins--number of games won top this season etc top_losses -- games lost as top this season etc """ top_wins = 0 jun_wins = 0 mid_wins = 0 adc_wins = 0 sup_wins = 0 top_total = 0 jun_total = 0 mid_total = 0 adc_total = 0 sup_total = 0 # Get only games from this season. ranked_hist = cass.MatchHistory(summoner=summoner, queues = {cass.Queue.ranked_solo_fives},begin_time=cass.Patch.from_str("9.1",region="NA").start) for m in ranked_hist[:games]: player = m.participants[summoner.name] if player.lane == cass.data.Lane.top_lane: top_wins += player.team.win top_total += 1 continue if player.lane == cass.data.Lane.jungle: jun_wins += player.team.win jun_total += 1 continue if player.lane == cass.data.Lane.mid_lane: mid_wins += player.team.win mid_total += 1 continue if player.lane == cass.data.Lane.bot_lane: if player.role == cass.data.Role.duo_carry: adc_wins += player.team.win adc_total += 1 continue elif player.role == cass.data.Role.duo_support: sup_wins += player.team.win sup_total += 1 continue entry = dict() entry["id"] = [summoner.account_id] entry["top_wins"] = [top_wins] entry["jun_wins"] = [jun_wins] entry["mid_wins"] = [mid_wins] entry["adc_wins"] = [adc_wins] entry["sup_wins"] = [sup_wins] entry["top_losses"] = [top_total - top_wins] entry["jun_losses"] = [jun_total - jun_wins] entry["mid_losses"] = [mid_total - mid_wins] entry["adc_losses"] = [adc_total - adc_wins] entry["sup_losses"] = [sup_total - sup_wins] return entry