def main():
    # Pull the data
    champion_roles = pull_data()

    # Use individual champions
    darius = Champion(name='Darius', region='NA')
    leesin = Champion(name='Lee Sin', region='NA')
    syndra = Champion(name='Syndra', region='NA')
    draven = Champion(name='Draven', region='NA')
    braum = Champion(name='Braum', region='NA')
    champions = [darius, leesin, syndra, draven, braum]

    roles = get_champion_roles(champions,
                               top=darius,
                               champion_roles=champion_roles)
    print({role.name: champion.name for role, champion in roles.items()})

    # Use Cassiopeia's match.blue_team and/or match.red_team objects
    summoner = Summoner(name="Kalturi", region="NA")
    for match in summoner.match_history:
        roles = get_team_roles(match.blue_team, champion_roles)
        print({role.name: champion.name for role, champion in roles.items()})

        roles = get_team_roles(match.red_team, champion_roles)
        print({role.name: champion.name for role, champion in roles.items()})

        break
예제 #2
0
def getThreadedMatchResults(matches, accountId, region):
    championDict = json.load(
        open(os.path.join(BASE_DIR, "history/static/championKey.json")))
    summonerSpell = json.load(
        open(os.path.join(BASE_DIR, "history/static/summonerSpell.json")))
    champToChampName = requests.get("%s/%s/data/en_US/champion.json" %
                                    (lol_version, lol_patch)).json()["data"]
    champion_roles = pull_data()
    database = dict()
    for match in matches:
        gameId = match["gameId"]
        game = MatchInfo.objects.filter(gameId=region + str(gameId))
        if game.exists():
            gameFromDB = game.first()
            gameData = gameFromDB.getData()
            matchInfo = json.loads(gameData)
            database[gameId] = matchInfo
    pool = mp.Pool()
    function = partial(processMatch, region, championDict, summonerSpell,
                       champToChampName, champion_roles, database)
    matchList = pool.map(function, matches)
    pool.close()
    pool.join()
    for match in matchList:
        gameId = match["gameId"]
        if gameId not in database:
            jsonStr = json.dumps(match)
            MatchInfo.objects.create(gameId=region + str(gameId),
                                     gameData=jsonStr)
        match["timeStatus"] = timeStatus(match["gameCreation"])
        infoByAccountId = match.pop("infoByAccountId")
        match["info"] = infoByAccountId[accountId]
    return matchList
예제 #3
0
def getMatchResults(matches, accountId, region):
    championDict = json.load(
        open(os.path.join(BASE_DIR, "history/static/champions.json")))
    summonerSpell = json.load(
        open(os.path.join(BASE_DIR, "history/static/summonerSpell.json")))
    summoner = requests.get("%s/%s/data/en_US/summoner.json" %
                            (lol_version, lol_patch)).json()["data"]
    itemJson = requests.get("%s/%s/data/en_US/item.json" %
                            (lol_version, lol_patch)).json()["data"]
    champion_roles = pull_data()
    database = dict()
    for match in matches:
        gameId = match["gameId"]
        game = MatchInfo.objects.filter(gameId=region + str(gameId))
        if game.exists():
            gameFromDB = game.first()
            gameData = gameFromDB.getData()
            matchInfo = json.loads(gameData)
            database[gameId] = matchInfo
    matchList = []
    for match in matches:
        matchResult = processMatch(region, championDict, summonerSpell,
                                   summoner, itemJson, champion_roles,
                                   database, match)
        matchList.append(matchResult)
    for match in matchList:
        gameId = match["gameId"]
        if gameId not in database:
            jsonStr = json.dumps(match)
            MatchInfo.objects.create(gameId=region + str(gameId),
                                     gameData=jsonStr)
        match["timeStatus"] = timeStatus(match["gameCreation"])
        infoByAccountId = match.pop("infoByAccountId")
        match["info"] = infoByAccountId[accountId]
    return matchList
예제 #4
0
def main():
    print("Pulling data...")
    champion_roles = pull_data()
    print("Finished pulling data.")
    print()

    champions = [122, 64, 69, 119,
                 201]  # ['Darius', 'Lee Sin', 'Cassiopeia', 'Draven', 'Braum']
    roles = get_roles(champion_roles, champions)
    print(roles)
def main():
    print("Pulling data...")
    champion_roles = pull_data()
    print("Finished pulling data.")
    print()

    # Pull a summoner's most recent match using Cassiopeia
    match = cass.get_match(id=3344134840, region="NA")
    team = match.blue_team
    # Get the roles
    roles = get_team_roles(team, champion_roles)

    # Print the results
    print({role.name: champion.name for role, champion in roles.items()})
예제 #6
0
def getLiveMatchData(match, summonerId, region):
    championDict = json.load(
        open(os.path.join(BASE_DIR, "history/static/champions.json")))
    summonerSpell = json.load(
        open(os.path.join(BASE_DIR, "history/static/summonerSpell.json")))
    summoner = requests.get("%s/%s/data/en_US/summoner.json" %
                            (lol_version, lol_patch)).json()["data"]
    map = json.load(open(os.path.join(BASE_DIR, "history/static/runes.json")))
    matchInfo = dict()
    gameStartTime = match["gameStartTime"]
    if gameStartTime == 0:
        matchInfo["gameDelta"] = 0
    else:
        matchInfo["gameDelta"] = int(datetime.datetime.now().timestamp() -
                                     gameStartTime // 1000)
    participantDataMap = dict()
    champion_roles = pull_data()
    unsortedChampListBlue = []
    unsortedChampListRed = []
    for participant in match["participants"]:
        data = dict()
        data["summonerName"] = participant["summonerName"]
        data["summonerId"] = participant["summonerId"]
        championId = participant["championId"]
        champion = championDict[str(championId)]
        data["champion"] = champion
        data["spell1Id"] = summonerSpell[str(participant["spell1Id"])]
        data["spell2Id"] = summonerSpell[str(participant["spell2Id"])]
        data["spell1Name"] = summoner[data["spell1Id"]]["name"]
        data["spell1Tooltip"] = summoner[data["spell1Id"]]["description"]
        data["spell2Name"] = summoner[data["spell2Id"]]["name"]
        data["spell2Tooltip"] = summoner[data["spell2Id"]]["description"]
        runes = []
        perks = participant["perks"]["perkIds"]
        for rune in perks:
            rune_url = map.get(str(rune))
            if rune_url:
                runes.append(rune_url)
        data["runes"] = runes
        participantDataMap[championId] = data
        if participant["teamId"] == 100:
            unsortedChampListBlue.append(championId)
        else:
            unsortedChampListRed.append(championId)
    matchInfo["participantData"] = getParticipantData(champion_roles,
                                                      participantDataMap,
                                                      unsortedChampListBlue,
                                                      unsortedChampListRed)
    return matchInfo
예제 #7
0
def enemyTeamList():
    global championList, roles
    championList = []
    champion_roles = pull_data()
    roles = get_team_roles(team, champion_roles)
    for role, champion in roles.items():
        championList.append(champion)

    raw_data = []
    nickWindow.image = []
    for champion in championList:
        raw_data.append(
            requests.get(cassiopeia.get_champion(champion.name).image.url))

    for i in range(len(raw_data)):
        im = Image.open(io.BytesIO(raw_data[i].content))
        im = im.resize((72, 72), Image.ANTIALIAS)
        nickWindow.image.append(ImageTk.PhotoImage(im))
        canvaTop.create_image((72 * i + 36), 36, image=nickWindow.image[i])
예제 #8
0
import json
import pickle
import pandas as pd
import cassiopeia as cass

from IPython.display import clear_output
from roleidentification import get_roles, pull_data

NUMBER_OF_LINES = 217883
champion_roles = pull_data()
champions_mapper = {champion.id: champion.name for champion in cass.get_champions("EUW")}

summoners = {}

summoners_columns_mapper = {
    'total_games': 0,
    'wins': 1
}

role_names = ['TOP', 'JUNGLE', 'MIDDLE', 'BOTTOM', 'UTILITY']
columns_by_role = ['kills', 'deaths', 'assists', 'gold_earned', 'total_damage_dealt_to_champions',
                   'total_minions_killed', 'vision_score', 'vision_wards_bought', 'total_games', 'wins']

index = len(summoners_columns_mapper)
for role_name in role_names:
    for column in columns_by_role:
        column_key = role_name + '_' + column
        summoners_columns_mapper[column_key] = index
        index += 1

columns_mapper = {}
예제 #9
0
파일: match.py 프로젝트: filipkhan/Pyot
from typing import List, Iterator, Dict
import asyncio

from pyot.utils import AutoData, dict_key_value_swap
from pyot.core.functional import turbo_copy, handle_import_error
from .__core__ import PyotCore, PyotStatic

try:
    import roleml
except (ImportError, ValueError):
    pass

try:
    import roleidentification
    champion_roles = AutoData(
        lambda: defaultdict(lambda: {}, roleidentification.pull_data()))
except ImportError:
    pass

# PYOT STATIC OBJECTS


class MatchPositionData(PyotStatic):
    x: int
    y: int


class MatchBanData(PyotStatic):
    champion_id: int
    pick_turn: int
예제 #10
0
    async def live_match(self,
                         ctx: commands.Context,
                         *,
                         name: str = "Empadão de Tatu"):
        """!live <summoner_name> => Retorna o lobby da partida ao vivo do invocador
        - O invocador DEVE estar em uma partida ao vivo
        - É possível obter informações sobre os participantes da partida em tempo real, utilizando dos botões disponíveis no Embed
        """

        try:
            summoner = watcher.summoner.by_name(region, name)
        except Exception:
            no_summ_embed = discord.Embed(
                description=f"Não consegui encontrar o invocador **{name}**!")
            return await ctx.send(embed=no_summ_embed)

        try:
            spec = watcher.spectator.by_summoner(region, summoner["id"])
        except Exception:
            no_live_match_embed = discord.Embed(
                description=
                f'Parece que o invocador **{summoner["name"]}** não está em uma partida no momento!'
            )
            return await ctx.send(embed=no_live_match_embed)

        participants = spec["participants"]

        blue_champion_id_list = []
        red_champion_id_list = []
        count = 0
        for row in participants:
            # Get list of champions in Blue/Red side
            if count < 5:
                blue_champion_id_list.append(row["championId"])
                count += 1
            else:
                red_champion_id_list.append(row["championId"])
                count += 1
        # Get the Blue/Red side champions roles
        champion_roles = pull_data()
        blue_team = get_roles(champion_roles, blue_champion_id_list)
        red_team = get_roles(champion_roles, red_champion_id_list)

        def get_rank(summonerId):
            current_rank = watcher.league.by_summoner(region, summonerId)
            player_rank = ""

            if current_rank == []:
                player_rank = "UNRANKED"
            else:
                for item in current_rank:
                    if item["queueType"] == "RANKED_SOLO_5x5":
                        player_rank = f'{item["tier"]} {item["rank"]} ({item["leaguePoints"]} LP)'

            return player_rank

        for row in participants:
            # BLUE TEAM
            if row["championId"] == blue_team["TOP"]:
                rank = get_rank(row["summonerId"])
                blue_team.update({
                    "TOP": {
                        "name": row["summonerName"],
                        "id": row["summonerId"],
                        "champion": dd.get_champion_name(row["championId"]),
                        "championId": row["championId"],
                        "rank": rank,
                    }
                })
            elif row["championId"] == blue_team["JUNGLE"]:
                rank = get_rank(row["summonerId"])
                blue_team.update({
                    "JUNGLE": {
                        "name": row["summonerName"],
                        "id": row["summonerId"],
                        "champion": dd.get_champion_name(row["championId"]),
                        "championId": row["championId"],
                        "rank": rank,
                    }
                })
            elif row["championId"] == blue_team["MIDDLE"]:
                rank = get_rank(row["summonerId"])
                blue_team.update({
                    "MIDDLE": {
                        "name": row["summonerName"],
                        "id": row["summonerId"],
                        "champion": dd.get_champion_name(row["championId"]),
                        "championId": row["championId"],
                        "rank": rank,
                    }
                })
            elif row["championId"] == blue_team["BOTTOM"]:
                rank = get_rank(row["summonerId"])
                blue_team.update({
                    "BOTTOM": {
                        "name": row["summonerName"],
                        "id": row["summonerId"],
                        "champion": dd.get_champion_name(row["championId"]),
                        "championId": row["championId"],
                        "rank": rank,
                    }
                })
            elif row["championId"] == blue_team["UTILITY"]:
                rank = get_rank(row["summonerId"])
                blue_team.update({
                    "UTILITY": {
                        "name": row["summonerName"],
                        "id": row["summonerId"],
                        "champion": dd.get_champion_name(row["championId"]),
                        "championId": row["championId"],
                        "rank": rank,
                    }
                })

            # RED TEAM
            if row["championId"] == red_team["TOP"]:
                rank = get_rank(row["summonerId"])
                red_team.update({
                    "TOP": {
                        "name": row["summonerName"],
                        "id": row["summonerId"],
                        "champion": dd.get_champion_name(row["championId"]),
                        "championId": row["championId"],
                        "rank": rank,
                    }
                })
            elif row["championId"] == red_team["JUNGLE"]:
                rank = get_rank(row["summonerId"])
                red_team.update({
                    "JUNGLE": {
                        "name": row["summonerName"],
                        "id": row["summonerId"],
                        "champion": dd.get_champion_name(row["championId"]),
                        "championId": row["championId"],
                        "rank": rank,
                    }
                })
            elif row["championId"] == red_team["MIDDLE"]:
                rank = get_rank(row["summonerId"])
                red_team.update({
                    "MIDDLE": {
                        "name": row["summonerName"],
                        "id": row["summonerId"],
                        "champion": dd.get_champion_name(row["championId"]),
                        "championId": row["championId"],
                        "rank": rank,
                    }
                })
            elif row["championId"] == red_team["BOTTOM"]:
                rank = get_rank(row["summonerId"])
                red_team.update({
                    "BOTTOM": {
                        "name": row["summonerName"],
                        "id": row["summonerId"],
                        "champion": dd.get_champion_name(row["championId"]),
                        "championId": row["championId"],
                        "rank": rank,
                    }
                })
            elif row["championId"] == red_team["UTILITY"]:
                rank = get_rank(row["summonerId"])
                red_team.update({
                    "UTILITY": {
                        "name": row["summonerName"],
                        "id": row["summonerId"],
                        "champion": dd.get_champion_name(row["championId"]),
                        "championId": row["championId"],
                        "rank": rank,
                    }
                })

        live_match_embed = discord.Embed(
            title=f'Partida ao vivo de {summoner["name"]}',
            url="https://br.op.gg/summoner/userName="******"+".join(name.split(" ")),
        )

        live_match_embed.add_field(
            name="Summoner",
            value=f'🔹 {blue_team["TOP"]["name"]}\n' +
            f'🔹 {blue_team["JUNGLE"]["name"]}\n' +
            f'🔹 {blue_team["MIDDLE"]["name"]}\n' +
            f'🔹 {blue_team["BOTTOM"]["name"]}\n' +
            f'🔹 {blue_team["UTILITY"]["name"]}\n' + "\n" +
            f'🔸 {red_team["TOP"]["name"]}\n' +
            f'🔸 {red_team["JUNGLE"]["name"]}\n' +
            f'🔸 {red_team["MIDDLE"]["name"]}\n' +
            f'🔸 {red_team["BOTTOM"]["name"]}\n' +
            f'🔸 {red_team["UTILITY"]["name"]}\n',
            inline=True,
        )

        live_match_embed.add_field(
            name="Champion",
            value=f'{dd.EMOJI_TOP} {blue_team["TOP"]["champion"]}\n' +
            f'{dd.EMOJI_JUNGLE} {blue_team["JUNGLE"]["champion"]}\n' +
            f'{dd.EMOJI_MIDDLE} {blue_team["MIDDLE"]["champion"]}\n' +
            f'{dd.EMOJI_BOTTOM} {blue_team["BOTTOM"]["champion"]}\n' +
            f'{dd.EMOJI_UTILITY} {blue_team["UTILITY"]["champion"]}\n' + "\n" +
            f'{dd.EMOJI_TOP} {red_team["TOP"]["champion"]}\n' +
            f'{dd.EMOJI_JUNGLE} {red_team["JUNGLE"]["champion"]}\n' +
            f'{dd.EMOJI_MIDDLE} {red_team["MIDDLE"]["champion"]}\n' +
            f'{dd.EMOJI_BOTTOM} {red_team["BOTTOM"]["champion"]}\n' +
            f'{dd.EMOJI_UTILITY} {red_team["UTILITY"]["champion"]}\n',
            inline=True,
        )

        live_match_embed.add_field(
            name="Rank",
            value=f'® {blue_team["TOP"]["rank"]}\n' +
            f'® {blue_team["JUNGLE"]["rank"]}\n' +
            f'® {blue_team["MIDDLE"]["rank"]}\n' +
            f'® {blue_team["BOTTOM"]["rank"]}\n' +
            f'® {blue_team["UTILITY"]["rank"]}\n' + "\n" +
            f'® {red_team["TOP"]["rank"]}\n' +
            f'® {red_team["JUNGLE"]["rank"]}\n' +
            f'® {red_team["MIDDLE"]["rank"]}\n' +
            f'® {red_team["BOTTOM"]["rank"]}\n' +
            f'® {red_team["UTILITY"]["rank"]}\n',
            inline=True,
        )

        message = await ctx.send(embed=live_match_embed)

        # Lidando com os "botões"
        #
        await message.add_reaction("🔹")
        await message.add_reaction("🔸")
        await message.add_reaction("1️⃣")
        await message.add_reaction("2️⃣")
        await message.add_reaction("3️⃣")
        await message.add_reaction("4️⃣")
        await message.add_reaction("5️⃣")
        await message.add_reaction("❌")

        def check(reaction, user):
            return user == ctx.author

        reaction = None
        blue_flag = 1
        red_flag = 0
        command_call_flag_control = 1

        call_summ_msg_embed = discord.Embed(
            description=
            "Utilize os botões acima para obter informações sobre os invocadores"
        )
        call_summ_msg = await ctx.send(embed=call_summ_msg_embed)
        while True:

            if str(reaction) == "🔹":
                blue_flag = 1
                red_flag = 0
            if str(reaction) == "🔸":
                blue_flag = 0
                red_flag = 1

            if str(reaction) == "1️⃣":
                if blue_flag:
                    await ctx.invoke(
                        self.bot.get_command("summ"),
                        name=blue_team["TOP"]["name"],
                        current_champion=blue_team["TOP"]["championId"],
                        command_call_flag=command_call_flag_control,
                        msg=call_summ_msg,
                    )
                else:
                    await ctx.invoke(
                        self.bot.get_command("summ"),
                        name=red_team["TOP"]["name"],
                        current_champion=red_team["TOP"]["championId"],
                        command_call_flag=command_call_flag_control,
                        msg=call_summ_msg,
                    )
            elif str(reaction) == "2️⃣":
                if blue_flag:
                    await ctx.invoke(
                        self.bot.get_command("summ"),
                        name=blue_team["JUNGLE"]["name"],
                        current_champion=blue_team["JUNGLE"]["championId"],
                        command_call_flag=command_call_flag_control,
                        msg=call_summ_msg,
                    )
                else:
                    await ctx.invoke(
                        self.bot.get_command("summ"),
                        name=red_team["JUNGLE"]["name"],
                        current_champion=red_team["JUNGLE"]["championId"],
                        command_call_flag=command_call_flag_control,
                        msg=call_summ_msg,
                    )
            elif str(reaction) == "3️⃣":
                if blue_flag:
                    await ctx.invoke(
                        self.bot.get_command("summ"),
                        name=blue_team["MIDDLE"]["name"],
                        current_champion=blue_team["MIDDLE"]["championId"],
                        command_call_flag=command_call_flag_control,
                        msg=call_summ_msg,
                    )
                else:
                    await ctx.invoke(
                        self.bot.get_command("summ"),
                        name=red_team["MIDDLE"]["name"],
                        current_champion=red_team["MIDDLE"]["championId"],
                        command_call_flag=command_call_flag_control,
                        msg=call_summ_msg,
                    )
            elif str(reaction) == "4️⃣":
                if blue_flag:
                    await ctx.invoke(
                        self.bot.get_command("summ"),
                        name=blue_team["BOTTOM"]["name"],
                        current_champion=blue_team["BOTTOM"]["championId"],
                        command_call_flag=command_call_flag_control,
                        msg=call_summ_msg,
                    )
                else:
                    await ctx.invoke(
                        self.bot.get_command("summ"),
                        name=red_team["BOTTOM"]["name"],
                        current_champion=red_team["BOTTOM"]["championId"],
                        command_call_flag=command_call_flag_control,
                        msg=call_summ_msg,
                    )
            elif str(reaction) == "5️⃣":
                if blue_flag:
                    await ctx.invoke(
                        self.bot.get_command("summ"),
                        name=blue_team["UTILITY"]["name"],
                        current_champion=blue_team["UTILITY"]["championId"],
                        command_call_flag=command_call_flag_control,
                        msg=call_summ_msg,
                    )
                else:
                    await ctx.invoke(
                        self.bot.get_command("summ"),
                        name=red_team["UTILITY"]["name"],
                        current_champion=red_team["UTILITY"]["championId"],
                        command_call_flag=command_call_flag_control,
                        msg=call_summ_msg,
                    )
            elif str(reaction) == "❌":
                await call_summ_msg.delete()
                await message.clear_reactions()
                await message.delete()
                return

            try:
                reaction, user = await self.bot.wait_for("reaction_add",
                                                         timeout=90.0,
                                                         check=check)

                if str(reaction) == "🔹" and not blue_flag:
                    await message.remove_reaction("🔸", user)
                elif str(reaction) == "🔸" and not red_flag:
                    await message.remove_reaction("🔹", user)
                else:
                    await message.remove_reaction(reaction, user)
            except Exception:
                break

        await message.clear_reactions()