コード例 #1
0
ファイル: scouting.py プロジェクト: Bcastet/Analyst
	def loadmatchlist(this):
		begin_time  = datetime.now()
		fourteen_days = timedelta(days=14)
		begin_time = begin_time-fourteen_days
		begin_time = arrow.get(begin_time)
		this.cass_matchlist = cassiopeia.get_match_history(this.summoner,begin_time = begin_time,queues=[cassiopeia.Queue.ranked_solo_fives],seasons=[cassiopeia.Season.season_9])
		real_matchlist = []
		while 1:
			try:
				match =  this.cass_matchlist.pop()
				real_matchlist.append(cassiopeia.Match(id=match.id))

			except Exception as e:
				real_matchlist.reverse()
				this.cass_matchlist = cassiopeia.get_match_history(this.summoner,begin_time = begin_time,queues=[cassiopeia.Queue.ranked_solo_fives],seasons=[cassiopeia.Season.season_9])
				return real_matchlist
コード例 #2
0
ファイル: lol03.py プロジェクト: sblack4/league-of-legends
    def getMatchData(self, match_id):
        """

        :param matchId:
        :return:
        """
        return cass.get_match_history(match_id)
コード例 #3
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
コード例 #4
0
def test_match_history_8():
    summoner = cass.Summoner(name="chowdog", region="NA")
    mh = cass.get_match_history(summoner=summoner,
                                region=summoner.region,
                                begin_index=0,
                                end_index=20)
    match = mh[0]
    assert len(match.participants) == 10
コード例 #5
0
def test_match_history_3():
    region = "NA"
    summoner = Summoner(name="Kalturi", region=region)
    match_history = cass.get_match_history(summoner=summoner,
                                           queues={Queue.ranked_solo_fives},
                                           begin_time=arrow.get(2017, 2, 7),
                                           end_time=arrow.get(2017, 2, 14))
    assert len(match_history) == 16
コード例 #6
0
def test_match_history_7():
    region = "NA"
    summoner = Summoner(name="Kalturi", region=region)
    match_history = cass.get_match_history(summoner=summoner,
                                           seasons={Season.season_8},
                                           queues={Queue.ranked_solo_fives},
                                           begin_time=arrow.get(2016, 12, 1))
    assert len(match_history) > 0
コード例 #7
0
def test_match_history_8():
    summoner = cass.Summoner(name="chowdog", region="NA")
    mh = cass.get_match_history(summoner=summoner,
                                begin_index=0,
                                end_index=20,
                                queues={Queue.ranked_solo_fives})
    match = mh[0]
    assert len(match.participants) == 10
コード例 #8
0
def test_match_correct_return():
    match_history = cassiopeia.get_match_history(summoner=SUMMONER_NAME, region="NA")
    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
コード例 #9
0
def test_match_history_1():
    region = "NA"
    summoner = Summoner(name="Kalturi",
                        account=34718348,
                        id=21359666,
                        region=region)
    match_history = cass.get_match_history(summoner=summoner,
                                           queues={Queue.ranked_solo_fives})
    assert len(match_history) > 400
コード例 #10
0
def test_match_history_2():
    region = "NA"
    summoner = Summoner(name="Kalturi", region=region)
    match_history = cass.get_match_history(
        summoner=summoner,
        seasons={Season.season_8},
        queues={Queue.ranked_solo_fives},
        begin_time=arrow.now().shift(days=-140),
        end_time=arrow.now())
    assert len(match_history) > 0
コード例 #11
0
ファイル: tasks.py プロジェクト: timewindergg/Rewind
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)
コード例 #12
0
ファイル: test_match.py プロジェクト: mathougui/cassiopeia
def test_match_correct_return():
    match_history = cassiopeia.get_match_history(SUMMONER_NAME)
    first_match = match_history[0]
    first_match_data = first_match._data[cassiopeia.core.match.MatchData]._dto

    match_from_id = cassiopeia.get_match(first_match.id)
    match_from_id_data = match_from_id._data[cassiopeia.core.match.MatchData]._dto

    assert isinstance(match_from_id, cassiopeia.Match)
    #assert first_match_data == match_from_id_data
    assert first_match.id == match_from_id.id
コード例 #13
0
def test_match_history_6():
    region = "NA"
    summoner = Summoner(name="Kalturi",
                        account=34718348,
                        id=21359666,
                        region=region)
    match_history = cass.get_match_history(summoner=summoner,
                                           queues={Queue.ranked_solo_fives},
                                           begin_time=arrow.get(2016, 12, 1),
                                           end_time=arrow.get(2016, 12, 30))
    assert len(match_history) > 0
コード例 #14
0
def get_matches(summoner):
    patch = Patch.from_str("10.8", region="NA")
    print(patch.start)
    end_time = patch.end
    if end_time is None:
        end_time = arrow.now()

    match_history = cass.get_match_history(summoner=summoner,
                                           seasons={Season.season_9},
                                           queues={Queue.ranked_solo_fives},
                                           begin_time=1585206000)
    return match_history
コード例 #15
0
def test_match_history_7():
    region = "NA"
    summoner = Summoner(name="Kalturi",
                        account=34718348,
                        id=21359666,
                        region=region)
    match_history = cass.get_match_history(summoner=summoner,
                                           region=region,
                                           seasons={Season.season_7},
                                           queues={Queue.ranked_solo_fives},
                                           begin_time=datetime.datetime(
                                               2016, 12, 1))
    assert len(match_history) > 0
コード例 #16
0
def test_match_history_2():
    region = "NA"
    summoner = Summoner(name="Kalturi",
                        account=34718348,
                        id=21359666,
                        region=region)
    match_history = cass.get_match_history(
        summoner=summoner,
        region=region,
        seasons={Season.season_7},
        queues={Queue.ranked_solo_fives},
        begin_time=datetime.datetime.utcnow() - datetime.timedelta(days=140),
        end_time=datetime.datetime.utcnow())
    assert len(match_history) > 0
コード例 #17
0
def get_match_history(summoner_name, n, offset=0):
    """

    :param summoner_name:
    :param n:
    :param offset:
    :return: generator that returns n-offset matches
    """
    summoner = cass.get_summoner(name=summoner_name)
    while n > offset:
        offset += 1
        yield cass.get_match_history(summoner=summoner,
                                     begin_index=offset - 1,
                                     end_index=offset)
コード例 #18
0
 def getMatchList(self, player, num=100):
     """
     get num matches for player
     :param player: summoner name
     :param num: number of matches
     :return: List[int]
     """
     summoner = cass.get_summoner(name=player)
     print(
         "{accountId}: {name} is a level {level} summoner on the {region} server."
         .format(accountId=summoner.id,
                 name=summoner.name,
                 level=summoner.level,
                 region=summoner.region))
     match_history = cass.get_match_history(summoner, end_index=num)
     print("His match history is length: {}".format(len(match_history)))
     return match_history
コード例 #19
0
ファイル: test_examples.py プロジェクト: sheridonx/cassiopeia
def test_match():
    name = "Kalturi"
    account = 34718348
    id = 21359666
    region = "NA"

    summoner = Summoner(name=name, account=account, id=id, region=region)

    match_history = cass.get_match_history(summoner, queues={Queue.ranked_solo_fives})
    match_history = summoner.match_history
    match_history(seasons={Season.season_7}, queues={Queue.ranked_solo_fives})

    champion_id_to_name_mapping = {champion.id: champion.name for champion in cass.get_champions(region=region)}
    played_champions = Counter()
    for match in match_history:
        champion_id = match.participants[summoner.name].champion.id
        champion_name = champion_id_to_name_mapping[champion_id]
        played_champions[champion_name] += 1

    for champion_name, count in played_champions.most_common(10):
        champion_name, count

    match = match_history[0]
    match.id

    p = match.participants[summoner]
    p.id, p.summoner.region, p.summoner.account.id, p.summoner.name, p.summoner.id, p.champion.id

    for p in match.participants:
        p.id, p.summoner.region, p.summoner.account.id, p.summoner.name, p.summoner.id, p.champion.id, p.team.first_dragon

    for p in match.participants:
        p.id, p.summoner.region, p.summoner.account.id, p.summoner.name, p.summoner.id, p.champion.id, p.team.first_dragon

    match.blue_team.win
    match.red_team.win
    for p in match.blue_team.participants:
        p.summoner.name
コード例 #20
0
def write_matches(summoner_name, n):
    """
    writes n matches as csv files containing events or frames
    :param summoner_name: str of summoner name
    :param n: number of matches you want
    :return: void
    """
    participant_frames_df = pd.DataFrame()
    events_df = pd.DataFrame()

    summoner = cass.get_summoner(name="Faker")
    match_history = cass.get_match_history(summoner=summoner)

    i = 0
    for match in match_history:
        match_id = match.id
        match = cass.get_match(id=match_id)

        p_wins = get_participant_wins(match)

        pf_df, e_df = unpack_timeline(match.timeline, p_wins)
        pf_df['summoner'] = summoner_name
        e_df['summoner'] = summoner_name
        pf_df['match_id'] = match_id
        e_df['match_id'] = match_id

        participant_frames_df = pd.concat([participant_frames_df, pf_df])
        events_df = pd.concat([events_df, e_df])

        i += 1
        if i >= n:
            break

    participant_frames_df.to_csv("participant_frames.csv",
                                 header=True,
                                 index=False)
    events_df.to_csv("events.csv", header=True, index=False)
コード例 #21
0
def test_match():
    name = "Kalturi"
    region = "NA"

    summoner = Summoner(name=name, region=region)

    match_history = cass.get_match_history(summoner, queues={Queue.ranked_solo_fives})
    match_history = summoner.match_history
    match_history(seasons={Season.season_7}, queues={Queue.ranked_solo_fives})

    champion_id_to_name_mapping = {champion.id: champion.name for champion in cass.get_champions(region=region)}
    played_champions = Counter()
    for match in match_history:
        champion_id = match.participants[summoner.name].champion.id
        champion_name = champion_id_to_name_mapping[champion_id]
        played_champions[champion_name] += 1

    for champion_name, count in played_champions.most_common(10):
        champion_name, count

    match = match_history[0]
    match.id

    p = match.participants[summoner]
    p.id, p.summoner.region, p.summoner.account_id, p.summoner.name, p.summoner.id, p.champion.id

    for p in match.participants:
        p.id, p.summoner.region, p.summoner.account_id, p.summoner.name, p.summoner.id, p.champion.id, p.team.first_dragon

    for p in match.participants:
        p.id, p.summoner.region, p.summoner.account_id, p.summoner.name, p.summoner.id, p.champion.id, p.team.first_dragon

    match.blue_team.win
    match.red_team.win
    for p in match.blue_team.participants:
        p.summoner.name
コード例 #22
0
ファイル: views.py プロジェクト: timewindergg/Rewind
def get_current_match_details(s, region, champion_id):
    matchlist = cass.get_match_history(summoner=s, champions=[champion_id], begin_index=0, end_index=10)
    len(matchlist) # to fill matchlist

    try:
        pool = Pool(10)
        pool.map(load_match, matchlist)
        pool.close()
        pool.join()
    except:
        pool.close()
        return HttpResponse(status=500)

    response = {}

    q = {}
    leagues = cass.get_league_positions(summoner=s, region=region)
    for league in leagues:
        q[league.queue.value] = {
            'tier': league.tier.value,
            'division': league.division.value,
            'points': league.league_points
        }
        if league.promos is not None:
            q[league.queue.value]['promos'] = league.promos.progress
            q[league.queue.value]['notPlayed'] = league.promos.not_played

    # summoner stats for past 20 matches on a champion
    stats = {
        "kills": 0,
        "deaths": 0,
        "assists": 0,
        "totalCs": 0,
        "cs10": 0,
        "cs20": 0,
        "cs30": 0,
        "gold10": 0,
        "gold20": 0,
        "gold30": 0,
        "wins": 0,
        "losses": 0
    }
    match_history = []

    games10 = 0
    games20 = 0
    games30 = 0
    cs10 = 0
    cs20 = 0
    cs30 = 0
    gold10 = 0
    gold20 = 0
    gold30 = 0
    match_count = 0
    for match in matchlist:
        if (match.region.value == region):
            match_count += 1

            participants = match.participants
            for participant in participants:
                if participant.summoner.id == s.id:
                    user = participant
                    break

            stats["kills"] += user.stats.kills
            stats["deaths"] += user.stats.deaths
            stats["assists"] += user.stats.assists
            stats["totalCs"] += user.stats.total_minions_killed

            if user.stats.win:
                stats["wins"] += 1
                match_history.append(1)
            else:
                stats["losses"] += 1
                match_history.append(0)

            dur = match.duration.seconds
            try:
                if dur > 10 * 60:
                    gold10 += user.timeline.gold_per_min_deltas['0-10'] * 10
                    cs10 += user.timeline.creeps_per_min_deltas['0-10'] * 10
                    games10 += 1
                if dur > 20 * 60:
                    gold20 += (user.timeline.gold_per_min_deltas['0-10'] + user.timeline.gold_per_min_deltas['10-20']) * 10
                    cs20 += (user.timeline.creeps_per_min_deltas['0-10'] + user.timeline.creeps_per_min_deltas['10-20']) * 10
                    games20 += 1
                if dur > 30 * 60:
                    gold30 += (user.timeline.gold_per_min_deltas['0-10'] + user.timeline.gold_per_min_deltas['10-20'] + user.timeline.gold_per_min_deltas['20-30']) * 10
                    cs30 += (user.timeline.creeps_per_min_deltas['0-10'] + user.timeline.creeps_per_min_deltas['10-20'] + user.timeline.creeps_per_min_deltas['20-30']) * 10
                    games30 += 1
            except:
                log.warn('user timeline data does not exist', match.id)

    stats["kills"] /= 10
    stats["deaths"] /= 10
    stats["assists"] /= 10
    stats["totalCs"] /= 10

    try:
        stats["cs10"] = round(cs10 / games10, 2)
        stats["cs20"] = round(cs20 / games20, 2)
        stats["cs30"] = round(cs30 / games30, 2)
        stats["gold10"] = round(gold10 / games10, 2)
        stats["gold20"] = round(gold20 / games20, 2)
        stats["gold30"] = round(gold30 / games30, 2)
    except:
        # divide by 0
        pass

    build = {}
    boots = {}
    core = {}
    situational = {}
    all_items = {}

    # get recommended build
    if match_count > 0:
        try:
            champ_items = ChampionItems.objects.get(champ_id=user.champion.id)
            items_blob = ujson.loads(champ_items.item_blob)

            blob_items = items_blob.items()
            for item, occurence in blob_items:
                if int(item) in Items.boots:
                    boots[item] = occurence
                elif int(item) in Items.full_items:
                    all_items[item] = occurence

            sorted_all = sorted(all_items, key=all_items.get, reverse=True) 
            core_arr = sorted_all[:3]
            situational_arr = sorted_all[3:8]

            for item in core_arr:
                core[item] = all_items[item]

            for item in situational_arr:
                situational[item] = all_items[item]
        except:
            pass

    build['boots'] = boots
    build['core'] = core
    build['situational'] = situational

    response['stats'] = stats
    response['build'] = build
    response['leagues'] = q

    return response
コード例 #23
0
def test_matches_raises_with_unknown_summoner():
    with pytest.raises(NotFoundError):
        summoner = cassiopeia.get_summoner(name=UNKNOWN_SUMMONER_NAME, region="NA")
        match_history = cassiopeia.get_match_history(summoner=summoner)
        match = match_history[0]
コード例 #24
0
def test_matches_return_type():
    summoner = cassiopeia.get_summoner(name=SUMMONER_NAME, region="NA")
    match_history = cassiopeia.get_match_history(summoner=summoner)

    assert isinstance(match_history, SearchableList)
    assert all(isinstance(m, cassiopeia.Match) for m in match_history)
コード例 #25
0
ファイル: getSummoners.py プロジェクト: tynanseltzer/lolDraft
cass.set_default_region("NA")

# Step 1: Generate a bunch of summoners

# summoners = ["Imaqtpie"] # Seed

with open('../input/summoners.txt') as f:
    summoners = f.read().splitlines()
    print("Length of summoners.txt: " + str(len(summoners)))

for i in range(2, 10):  # Change on crashes

    summoner = cass.get_summoner(name=summoners[i])
    print("Querying match history of " + summoners[i])
    match_history = cass.get_match_history(summoner=summoner,
                                           seasons={Season.season_8},
                                           queues={Queue.ranked_solo_fives})

    # for participant in match_history[0].participants:
    #     print(participant.summoner.name)

    j = 0
    for match in match_history:  # Check match history of this summoner
        for participant in match.participants:  # Get new summoners
            if participant.summoner.name not in summoners:
                summoners.append(participant.summoner.name)
        if j == 50:
            # Save summoners to file
            print("Writing summoners to file...")
            with open('summoners.txt', 'w') as f:
                for item in summoners:
コード例 #26
0
ファイル: test_match.py プロジェクト: mathougui/cassiopeia
def test_matches_return_type():
    match_history = cassiopeia.get_match_history(SUMMONER_NAME)

    assert isinstance(match_history, SearchableList)
    assert all(isinstance(m, cassiopeia.Match) for m in match_history)
コード例 #27
0
ファイル: new_match.py プロジェクト: RileyAbr/CSCI479-Project
import requests
import json
import time
import pymongo
import cassiopeia as cass
from RIOTAPIKEY import key

# Cassioepeia info
RIOTAPIKEY = key
cass.set_riot_api_key(RIOTAPIKEY)
cass.set_default_region("NA")

print(time.time())
sum_name = ''  #Set this to a Summoner you would like to look up
sum = cass.get_summoner(name=sum_name)

new_match = cass.get_match_history(sum)

print(new_match)
コード例 #28
0
ファイル: test_match.py プロジェクト: mathougui/cassiopeia
def test_matches_raises_with_unknown_summoner():
    with pytest.raises(NotFoundError):
        match_history = cassiopeia.get_match_history(UNKNOWN_SUMMONER_NAME)
        match_history[0]