Esempio n. 1
0
 def test_equality(self):
     from_name = cassiopeia.get_summoner(name=SUMMONER_NAME, region="NA")
     from_id = cassiopeia.get_summoner(id=from_name.id, region="NA")
     self.assertEqual(from_name.id, from_id.id)
     self.assertEqual(from_name.name, from_id.name)
     self.assertEqual(from_name, from_id)
     self.assertEqual(from_name.to_dict(), from_id.to_dict())
Esempio n. 2
0
def test_equal_summoners():
    from_name = cassiopeia.get_summoner(name=SUMMONER_NAME, region="NA")
    from_id = cassiopeia.get_summoner(id=from_name.id, region="NA")

    assert from_name.id == from_id.id
    assert from_name.name == from_id.name
    assert from_name == from_id
    assert from_name.to_dict() == from_id.to_dict()
def test_equal_summoners():
    from_name = cassiopeia.get_summoner(name=SUMMONER_NAME, region="NA")
    from_id = cassiopeia.get_summoner(id=from_name.id, region="NA")

    assert from_name.id == from_id.id
    assert from_name.name == from_id.name
    assert from_name == from_id
    assert from_name.to_dict() == from_id.to_dict()
Esempio n. 4
0
def get_summoner(request):
    region = normalize_region(request.GET['region'])
    try:
        summoner_id = request.GET['summoner_id']
        s = cass.get_summoner(id=summoner_id, region=region)
    except:
        summoner_name = request.GET['summoner_name']
        s = cass.get_summoner(name=summoner_name, region=region)

    if not s.exists:
        return HttpResponse('Summoner does not exist', status=404)

    update_summoner_helper(s, region)

    try:
        summoner = ProfileStats.objects.get(user_id=s.id, region=region)
    except:
        log.warn("ProfileStats not found after update in get_summoner")
        return HttpResponse("Error retrieving profile stats", status=500)

    try:
        cmasteries = UserChampionMasteries.objects.filter(user_id=s.id, region=region).order_by('-total_points')[:3]
    except:
        log.warn("UserChampionMasteries not found after update in get_summoner")
        return HttpResponse("Error retrieving champion masteries", status=500)

    try:
        user_leagues = UserLeagues.objects.filter(user_id=s.id, region=region)
    except:
        log.warn("ProfileStats not found after update in get_summoner")
        return HttpResponse("Error retrieving leagues", status=500)

    try:
        lawn = MatchLawn.objects.filter(user_id=s.id, region=region).order_by('-date')[:90]
    except:
        log.warn("Lawn not found after update in get_summoner")
        return HttpResponse("Error retrieving matchlawn", status=500)

    try:
        champ_stats = UserChampionStats.objects.filter(user_id=s.id, region=region)
    except:
        log.warn("Champ stats not found after update in get_summoner")
        return HttpResponse(status=500)

    response = model_to_dict(summoner)
    response['championMasteries'] = list(cmasteries.values())
    response['leagues'] = list(user_leagues.values())
    response['lawn'] = list(lawn.values())
    response['championStats'] = list(champ_stats.values())

    return JsonResponse(response)
Esempio n. 5
0
def get_user_champion_stats_by_name(request):
    region = normalize_region(request.GET['region'])
    champion_id = get_champion_id(request.GET['champion_name'])
    try:
        summoner_id = request.GET['summoner_id']
        s = cass.get_summoner(id=summoner_id, region=region)
    except:
        summoner_name = request.GET['summoner_name']
        s = cass.get_summoner(name=summoner_name, region=region)

    if not s.exists:
        return HttpResponse('Summoner does not exist', status=404)

    return get_user_champion_stats(s, region, champion_id)
Esempio n. 6
0
def get_current_match_details_by_id(request):
    region = normalize_region(request.GET['region'])
    champion_id = int(request.GET['champion_id'])
    try:
        summoner_id = request.GET['summoner_id']
        s = cass.get_summoner(id=summoner_id, region=region)
    except:
        summoner_name = request.GET['summoner_name']
        s = cass.get_summoner(name=summoner_name, region=region)

    if not s.exists:
        return HttpResponse("Summoner does not exist", status=404)

    response = get_current_match_details(s, region, champion_id)

    return JsonResponse(response)
Esempio n. 7
0
def main():

    summoner = input("Please enter a summoner's name: ")
    with open('secret.json') as f:
        api_key = json.load(f)['riot-key']

    cass.set_riot_api_key(api_key)
    summoner = cass.get_summoner(name=summoner, region=REGION)
    match_history = Summoner(name=summoner.name, region=REGION).match_history(
        begin_time=Patch.from_str("9.1", region=REGION).start)
    match_info_rows = []
    for match in match_history:
        match_info = {}
        match_info['id'] = match.id
        match_info['queue_id'] = match.queue.id
        match_info['patch'] = match.patch
        match_info['creation'] = match.creation
        match_info['champion'] = match.participants[summoner].champion.name
        match_info['win'] = match.participants[summoner].team.win
        match_info['kills'] = match.participants[summoner].stats.kills
        match_info['deaths'] = match.participants[summoner].stats.deaths
        match_info['assists'] = match.participants[summoner].stats.assists
        match_info['kda'] = match.participants[summoner].stats.kda
        match_info_rows.append(match_info)

    match_history_df = pd.DataFrame(match_info_rows)
    match_history_df.set_index('id')
    # all_champions = cass.Champions(region=REGION)
    # sub_test(api_key)
    print(match_history_df)

    filename = summoner + '_matchhistory.csv'
    filepath = os.path.join('data', filename)

    match_history_df.to_csv(filepath)
Esempio n. 8
0
 def test_unknown_summoner(self):
     for e in cassiopeia.Summoner(name="Kalturi",
                                  region="NA").league_entries:
         print(e.league.name)
     self.assertFalse(
         cassiopeia.get_summoner(name=UNKNOWN_SUMMONER_NAME,
                                 region="NA").exists)
Esempio n. 9
0
def game_search(region, summonername):
    # search for the current game for the  summoner given in the given region
    summoner = cass.get_summoner(name=summonername,region=region)
    # call for current match
    try:
        colour = 0xe74c3c
        current_game = summoner.current_match
        blue_team = current_game.blue_team
        red_team = current_game.red_team
        # grab the bans from both sides
        blue_bans = []
        red_bans = []
        for i in blue_team.bans:
            if(blue_team.bans[i].id != -1):
                blue_bans.append(blue_team.bans[i].name)
        for k in red_team.bans:
            if(red_team.bans[k].id != -1):
                red_bans.append(red_team.bans[k].name)
        # gran the playing champions along with summoner names
        blue_champs = {}
        for i in blue_team.participants:
            blue_champs[i.summoner.name] = i.champion.name
            if(i.summoner.name == summonername):
                colour=0x3498db
        red_champs = {}
        for i in red_team.participants:
            red_champs[i.summoner.name] =i.champion.name
        newMatch = Match(region, summonername,red_champs,blue_champs,red_bans,blue_bans,colour)
    except:
        newMatch = Match(region, summonername,None,None,None,None, None)
    print("Match Searched")
    return newMatch
Esempio n. 10
0
def get_matches(summoner_name, begintime):
    smurf = cass.get_summoner(name=summoner_name)

    # make riot api call (all match histories)
    matches = cass.get_match_history(summoner=smurf, begin_time=begintime)

    # get durations in seconds, calculate total in hours
    durations, champions, wins, kills, deaths = [], [], [], [], []
    for match in matches:
        # get participant object from match
        p = [
            p for p in match.participants if p.summoner.name == summoner_name
        ][0]

        # add participant info to table
        durations.append(match.duration.seconds)
        champions.append(p.champion.name)
        wins.append(p.team.win)
        kills.append(p.stats.kills)
        deaths.append(p.stats.deaths)

    df = pd.DataFrame(
        list(zip(durations, champions, wins, kills, deaths)),
        columns=['durations', 'champions', 'win', 'kills', 'deaths'])
    return df
 def _prepare(self, id_or_name):
     """
     Get's the Teams from a live game by Summoner Name or from an old Match by Match ID
     :param id_or_name: either a Summoner Name or a Match ID
     :return: iterator of the prepared teams; if not exits None
     """
     # Setting the Api key for Cassiopeia and the default region
     cass.set_riot_api_key(self.key)
     cass.set_default_region('EUW')
     if type(id_or_name) is str:
         summoner = cass.get_summoner(name=id_or_name, region='EUW')
         try:
             current_game = summoner.current_match()
         except Exception as e:
             print(str(e))
             return None
     else:
         try:
             current_game = cass.get_match(id_or_name, region='EUW')
         except Exception as e:
             print(str(e))
             return None
     if current_game.mode == cass.data.GameMode.aram:
         print('there are no lanes in Aram')
         return None
     # Preparing the participants per team
     for team in current_game.teams:
         yield self._prepare_team(team), team
Esempio n. 12
0
    def __init__(self, user: hinter.struct.user.User = None):
        # Load summoner information
        if user is not None:
            user = cassiopeia.get_summoner(name=user.username)
        else:
            user = cassiopeia.get_summoner(name=hinter.settings.active_user)
        self.username = user.name

        # Save variables
        self.games = user.match_history
        self.rank = user.ranks[cassiopeia.Queue.ranked_solo_fives]
        self.level = user.level
        self.icon = user.profile_icon

        # Load match history information
        self.games = user.match_history(end_index=200)
Esempio n. 13
0
    def test_match_duration(self):
        nb_deltas = 0
        sum_deltas = 0
        region = 'KR'
        challengers = get_all_challenger_players(region)

        for challenger in challengers:
            summoner_name = challenger.get('summoner_name')
            summoner_id = challenger.get('summoner_id')
            print(summoner_name)
            summoner = cassiopeia.get_summoner(id=summoner_id, region=region)
            print(summoner.id)
            try:
                current_match = summoner.current_match
            except datapipelines.common.NotFoundError:
                continue
            duration = current_match.duration
            print(f'{duration.seconds=}')
            poro_match = porofessor_extractor.get_match_data(
                summoner_name, region)
            if not poro_match:
                continue
            print(f'{poro_match.get("duration").seconds}')
            sum_deltas += duration.seconds - poro_match.get("duration").seconds
            nb_deltas += 1
        print(f'average delta : {sum_deltas//nb_deltas}')
def ward_stats(ign, reg=region, game_num=30):
    me = cass.get_summoner(region=reg, name=ign)
    matches = me.match_history(begin_index=0, end_index=game_num)
    my_wards = []
    teams_wards = []
    enemy_wards = []
    for match in matches:
        mee = match.participants[me]
        my_wards.append(mee.stats.wards_placed)
        for team in match.teams:
            if team.side is mee.side:
                teams_wards.append(
                    sum([p.stats.wards_placed for p in team.participants]))
            else:
                enemy_wards.append(
                    sum([p.stats.wards_placed for p in team.participants]))
    print(f"\n{ign}'s ward stats in the last {game_num} games:")
    print(
        f"    {ign} placed average of {sum([k for k in my_wards])/len(my_wards)} wards"
    )
    print(
        f"    {ign}'s team placed average of {sum([k for k in teams_wards])/len(teams_wards)} wards"
    )
    print(
        f"    Enemy team placed average of {sum([k for k in enemy_wards])/len(enemy_wards)} wards"
    )
def test_masteries_contains_all_champions():
    champions = cassiopeia.get_champions(region="NA")
    summoner = cassiopeia.get_summoner(name=SUMMONER_NAME, region="NA")
    champ_masteries = cassiopeia.get_champion_masteries(summoner=summoner.id, region="NA")
    for cm in champ_masteries:
        assert cm.champion in champions
    for champion in champions:
        assert champion in champ_masteries
Esempio n. 16
0
async def roles(ctx):
    summoner = cass.get_summoner(name='aresyama')
    match = summoner.match_history[0]
    teams = match.teams
    team_1 = teams[0].participants
    player_1 = Player(team_1[0].summoner.name, team_1[0].champion.name)
    best_role = player_1.main_role()
    await ctx.send(best_role)
Esempio n. 17
0
def test_masteries_correct_type():
    summoner = cassiopeia.get_summoner(name=SUMMONER_NAME, region="NA")
    champ_masteries = cassiopeia.get_champion_masteries(summoner=summoner.id,
                                                        region="NA")

    assert isinstance(champ_masteries, SearchableList)
    assert all(
        isinstance(cm, cassiopeia.ChampionMastery) for cm in champ_masteries)
Esempio n. 18
0
def buttonClick():
    if inputNick.get() != "":
        summoner = cassiopeia.get_summoner(name=inputNick.get(),
                                           region=serversList.get())
        if summoner.exists:
            cassiopeia.set_default_region(serversList.get())
            t = threading.Thread(target=showSummoners, args=[summoner])
            t.start()
Esempio n. 19
0
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 []
Esempio n. 20
0
def test_masteries_contains_all_champions():
    champions = cassiopeia.get_champions(region="NA")
    summoner = cassiopeia.get_summoner(name=SUMMONER_NAME, region="NA")
    champ_masteries = cassiopeia.get_champion_masteries(summoner=summoner.id,
                                                        region="NA")
    for cm in champ_masteries:
        assert cm.champion in champions
    for champion in champions:
        assert champion in champ_masteries
Esempio n. 21
0
def profile(region, summonername):
    # search for the summoners top 3 played champions
    champions = ""
    summoner = cass.get_summoner(name=summonername,region=region)

    for i in range(0,3):
        champions += summoner.champion_masteries.pop(i).champion.name + ", "

    return Profile(region,summonername,summoner.level,champions)
Esempio n. 22
0
def test_masteries_correct_type():
    # TODO: Once get_champion_masteries works with passing a name,
    #       replace this with get_champion_masteries(SUMMONER_NAME)
    summoner = cassiopeia.get_summoner(name=SUMMONER_NAME)
    champ_masteries = cassiopeia.get_champion_masteries(summoner.id)

    assert isinstance(champ_masteries, SearchableList)
    assert all(
        isinstance(cm, cassiopeia.ChampionMastery) for cm in champ_masteries)
Esempio n. 23
0
async def account_level(ctx, playername):
    if ctx.author == bot.user:
        return

    summoner = cass.get_summoner(name=playername)
    response = (
        "{name} is a level {level} summoner on the {region} server.".format(
            name=summoner.name, level=summoner.level, region=summoner.region))
    await ctx.send(response)
Esempio n. 24
0
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
Esempio n. 25
0
def test_readme():
    summoner = cass.get_summoner(name="Kalturi", region="NA")
    "{name} is a level {level} summoner on the {region} server.".format(name=summoner.name, level=summoner.level, region=summoner.region)
    champions = cass.get_champions(region="NA")
    random_champion = random.choice(champions)
    "He enjoys playing champions such as {name}.".format(name=random_champion.name)

    challenger_league = cass.get_challenger_league(queue=cass.Queue.ranked_solo_fives, region="NA")
    best_na = challenger_league[0].summoner
    "He's not as good as {name} at League, but probably a better python programmer!".format(name=best_na.name)
Esempio n. 26
0
def test_match_correct_return():
    summoner = cassiopeia.get_summoner(name=SUMMONER_NAME, region="NA")
    match_history = cassiopeia.get_match_history(summoner=summoner)
    first_match = match_history[0]

    match_from_id = cassiopeia.get_match(id=first_match.id, region="NA")

    assert isinstance(match_from_id, cassiopeia.Match)
    assert first_match.id == match_from_id.id
    assert first_match == match_from_id
Esempio n. 27
0
def test_readme():
    summoner = cass.get_summoner(name="Kalturi", region="NA")
    "{name} is a level {level} summoner on the {region} server.".format(name=summoner.name, level=summoner.level, region=summoner.region)
    champions = cass.get_champions(region="NA")
    random_champion = random.choice(champions)
    "He enjoys playing champions such as {name}.".format(name=random_champion.name)

    challenger_league = cass.get_challenger_league(queue=cass.Queue.ranked_solo_fives, region="NA")
    best_na = challenger_league[0].summoner
    "He's not as good as {name} at League, but probably a better python programmer!".format(name=best_na.name)
Esempio n. 28
0
def update_summoner(request):
    summoner_name = request.POST['summoner_name']
    region = normalize_region(request.POST['region'])

    s = cass.get_summoner(name=summoner_name, region=region)
    if s.exists:
        update_summoner_helper(s, region)
    else:
        return HttpResponse(status=404)

    return HttpResponse(status=200)
Esempio n. 29
0
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
Esempio n. 30
0
def aggregate_users(summoner_id, region, max_aggregations=-1):
    try:
        # init
        cass.get_realms(region=region).load()

        summoner_id = summoner_id
        max_aggregations = int(max_aggregations)
        profile = ProfileStats.objects.get(user_id=summoner_id, region=region)
        summoner = cass.get_summoner(id=summoner_id, region=region)

        index = 0
        updated = False
        count = 0

        while True:
            if updated or index >= max_aggregations and max_aggregations > 0 or count >= max_aggregations:
                break

            recent_matches = cass.get_match_history(
                summoner=summoner,
                begin_index=index,
                end_index=index + BATCH_SIZE,
                seasons=[cass.data.Season.from_id(13)])

            batch = []
            for match in recent_matches:
                if profile.last_match_updated == match.creation.timestamp:
                    updated = True
                    break

                if (match.region.value == region):
                    batch.append(match.id)

                if len(batch) == Consts.AGGREGATION_BATCH_SIZE:
                    aggregate_batched_matches.delay(batch, region, summoner_id)
                    batch = []

                count += 1

                if count >= max_aggregations:
                    break

            index += BATCH_SIZE

            if len(batch) > 0:
                aggregate_batched_matches.delay(batch, region, summoner_id)

            if len(recent_matches) == 0:
                break

        return f"Aggregated {summoner_id}, {region}, {count} matches"
    except Exception as e:
        log.warn("Failed to aggregate_user", e, stack_info=True)
        aggregate_users.retry(exc=e)
Esempio n. 31
0
def search(summoner_name):
    summoner = cass.get_summoner(name=summoner_name)
    good_with = summoner.champion_masteries.filter(lambda cm: cm.level > 6)
    return render_template(
        'summoner.html',
        summoner=summoner,
        name=summoner.name,
        level=summoner.level,
        champions=[cm.champion.name for cm in good_with],
        profile_icon_url=summoner.profile_icon.url,
        match_history=summoner.match_history
    )
Esempio n. 32
0
def get_match_history(request):
    region = normalize_region(request.GET['region'])
    offset = int(request.GET['offset'])
    size = int(request.GET['size'])
    try:
        summoner_id = request.GET['summoner_id']
        s = cass.get_summoner(id=summoner_id, region=region)
    except:
        summoner_name = request.GET['summoner_name']
        s = cass.get_summoner(name=summoner_name, region=region)

    if not s.exists:
        return HttpResponse('Summoner does not exist', status=404)

    try:
        matches = Matches.objects.filter(user_id=s.id, region=region).order_by('-timestamp')[offset:size]
    except:
        return HttpResponse(status=404)

    response = list(matches.values())

    return JsonResponse(response, safe=False)
def first_blood_stats(ign, reg=region, game_num=30):
    me = cass.get_summoner(region=reg, name=ign)
    matches = me.match_history(begin_index=0, end_index=game_num)

    fb_and_win_list = []
    game_count = 0

    for match in matches:
        game_count += 1
        mee = match.participants[me]
        my_side = mee.side
        ally_first_blood = False
        i_got_fb = mee.stats.first_blood_kill
        i_got_fb_assist = mee.stats.first_blood_assist
        for team in match.teams:
            if team.first_blood:
                if my_side is team.side:
                    ally_first_blood = True
                break
        fb_and_win_list.append(
            (ally_first_blood, mee.stats.win, i_got_fb, i_got_fb_assist))

    win_count = sum([1 for t in fb_and_win_list if t[1]])
    fb_count = sum([1 for t in fb_and_win_list if t[0]])
    fb_and_win = sum([1 for t in fb_and_win_list if t[0] and t[1]])
    #fb_and_lose = abs(fb_count - fb_and_win)
    not_fb_count = game_count - fb_count
    not_fb_and_win = sum([1 for t in fb_and_win_list if not t[0] and t[1]])
    #not_fb_and_lose = abs(not_fb_count - not_fb_and_win)
    my_fb_count = sum([1 for t in fb_and_win_list if t[2]])
    my_fb_ass_count = sum([1 for t in fb_and_win_list if t[3]])

    print(f"\nOut of {game_count} mathces for {ign}:")
    print(f'Won: {win_count} games --> {win_count/game_count *100}% win rate')
    print(f"    Ally first blood: {fb_count}")
    print(f'        Ally first blood percentage: {fb_count/game_count *100}%')
    print(
        f'            {ign} got {my_fb_count} first bloods --> {my_fb_count/game_count *100}% first blood rate'
    )
    print(
        f"            {ign} got {my_fb_count/fb_count*100}% of team's first blood"
    )
    print(f'            {ign} assisted in {my_fb_ass_count} first blood')
    print(f'    First blood and win: {fb_and_win}')
    print(
        f'        Won {fb_and_win/fb_count *100}% of the game your team got first blood.'
    )
    print(f'    Not first blood and win: {not_fb_and_win}')
    print(
        f'        Won {not_fb_and_win/not_fb_count *100}% of the game enemy team got first blood.'
    )
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)
Esempio n. 35
0
def test_unknown_summoner():
    assert not cassiopeia.get_summoner(name=UNKNOWN_SUMMONER_NAME, region="NA").exists
def test_masteries_correct_type():
    summoner = cassiopeia.get_summoner(name=SUMMONER_NAME, region="NA")
    champ_masteries = cassiopeia.get_champion_masteries(summoner=summoner.id, region="NA")

    assert isinstance(champ_masteries, SearchableList)
    assert all(isinstance(cm, cassiopeia.ChampionMastery) for cm in champ_masteries)