What is League of Legends?
League of Legends is a 2009 MOBA (multiplayer online battle arena) video game made by Riot Games. It is one of the most popular video games, having 3.5 million daily active players. In the game, two teams of five players battle in player-versus-player combat, each team occupying and defending their half of the map. Each of the ten players controls a character, known as a “champion,” with unique abilities and differing play styles.
Which champion to pick?
As of June 9, 2022 there are currently 160 released champions. Such a wide selection can confuse newcomers as they will often not know what to play. The most basic champion statistics will be acquired and analyzed in the following sections. Every Tuesday, 16 out of the 160 total champions are chosen to be free-to-play in unranked games for that week.
How to acquire champion data?
In order to gather required information, League of Legends API is used.
def get_data(url): response = requests.get(url) if response.status_code == 200: print("Successfully fetched the data") return response.json() else: print(f"Something went wrong!") request_url = f'https://euw1.api.riotgames.com/lol/platform/v3/champion-rotations?api_key={API_KEY}' free_champions = get_data(request_url)
By running the given python script, a user gets the following response:
{ "freeChampionIds": [ 1, 5, 14, 15, 20, 26, 36, 38, 45, 60, 63, 268, 420, 427, 432, 498 ], "freeChampionIdsForNewPlayers": [ 222, 254, 427, 82, 131, 147, 54, 17, 18, 37 ], "maxNewPlayerLevel": 10 }
To keep things simple, we take into account 16 mentioned free-to-play champions. Since the given API call gives us 16 numbers instead of champion names, it is necessary to resolve such numbers in order to understand which champion it is.
We can fetch valuable data for all 160 champions by visiting League of Legends Data Dragon.
data_dragon_url = "http://ddragon.leagueoflegends.com/cdn/12.11.1/data/en_US/champion.json" data_dragon = get_data(data_dragon_url)
freeChampionIds
gives us champion unique keys. Each champion has their unique key. An example of a champion from the list is provided below:
"Ivern": { "version": "12.11.1", "id": "Ivern", "key": "427", "name": "Ivern", "title": "the Green Father", "blurb": "Ivern Bramblefoot, known to many as the Green Father, is a peculiar half man, half tree who roams Runeterra's forests, cultivating life everywhere he goes. He knows the secrets of the natural world, and holds deep friendships with all things that grow...", "info": { "attack": 3, "defense": 5, "magic": 7, "difficulty": 7 }, "image": { "full": "Ivern.png", "sprite": "champion1.png", "group": "champion", "x": 192, "y": 48, "w": 48, "h": 48 }, "tags": [, "Support", "Mage" ], "partype": "Mana", "stats": { "hp": 655, "hpperlevel": 99, "mp": 450, "mpperlevel": 60, "movespeed": 330, "armor": 27, "armorperlevel": 4.7, "spellblock": 32, "spellblockperlevel": 2.05, "attackrange": 475, "hpregen": 7, "hpregenperlevel": 0.85, "mpregen": 6, "mpregenperlevel": 0.75, "crit": 0, "critperlevel": 0, "attackdamage": 50, "attackdamageperlevel": 3, "attackspeedperlevel": 3.4, "attackspeed": 0.644 } }
In order to be able to resolve coded champions, we will collect certain information about every champion in the game and create an empty free_champions_resolved DataFrame where we will place our free champions.
champions = pd.DataFrame(columns = ['Image', 'Name', 'Key', 'Health', 'Attack']) free_champions_resolved = champions.copy() for champion in data_dragon['data']: champion_name = data_dragon['data'][champion]['name'] champion_id = data_dragon['data'][champion]['id'] champion_image = f'<img style = "display: block; margin-left: auto; margin-right: auto;"src = "http://ddragon.leagueoflegends.com/cdn/12.11.1/img/champion/{champion_id}.png "alt = ""width = "81"height = "81"/>' champion_key = int(data_dragon['data'][champion]['key']) champion_hp = int (data_dragon['data'][champion]['stats']['hp']) champion_attack= int(data_dragon['data'][champion]['stats']['attackdamage']) champions.loc[len(champions), champions.columns] = champion_image, champion_name, champion_key, champion_hp, champion_attack
To place wanted information in the empty DataFrame we run the following snippet:
for free_champion_id in free_champions['freeChampionIds']: temp_champion = champions.loc[champions['Key'] == free_champion_id] temp_champion_image = temp_champion.values[0][0] temp_champion_name = temp_champion.values[0][1] temp_champion_key = temp_champion.values[0][2] temp_champion_hp = temp_champion.values[0][3] temp_champion_attack = temp_champion.values[0][4] free_champions_resolved.loc[len(free_champions_resolved), free_champions_resolved.columns] = temp_champion_image, temp_champion_name, temp_champion_key, temp_champion_hp, temp_champion_attack free_champions_resolved.pop('Key')
Now, we sort the champions by Attack and Health attributes:
free_champions_resolved = free_champions_resolved.sort_values(['Attack', 'Health'], ascending=[False, False])
For simplicity, we will take into account the top 5 champions:
free_champions_resolved = free_champions_resolved.head(5)
By running these scripts, we have formed our DataFrame:
The image column is the HTML code for a champion image which will be useful in the next section.
How to display data?
It is up to the user how to style the generated table. For text purposes, HTML code is generated using Beautiful Soup.
Our table that presents the top 5 free-to-play champions by Attack and Health attributes can look something like this:
“The Simplest League of Legends Champion Analysis” Tech Bite was brought to you by Omar Čelik, Junior Data Analyst at Atlantbh.
Tech Bites are tips, tricks, snippets or explanations about various programming technologies and paradigms, which can help engineers with their everyday job.