Get Teamfight Tactics (TFT) data with Python and Riot Games API
Leverage your data for analysis and improvement
Introduction
Welcome! In this article, I will show you how to use the Riot Developer Portal, RiotWatcher, and Python to extract data from the TFT world.
Teamfight Tactics is a popular game mode in the online multiplayer game League of Legends. It is a round-based strategy game in which players use teams of powerful champions to fight against each other on a battlefield. Players can collect and upgrade champions, and must use their abilities and tactics wisely to outmaneuver their opponents and emerge victorious. Teamfight Tactics has become very popular among fans of strategy games and has even been featured in professional esports tournaments.
In TFT, players are matched against each other in a round-based battle. Each player starts with a certain amount of gold, which they can use to purchase champions to add to their team. Players can choose from a wide variety of champions, each with their own unique abilities and strengths.
Once a player has chosen their champions, they are placed on a battlefield (board) along with the other players’ champions. The game then plays out in rounds, with each player taking turns to use their champions’ abilities to attack and defend against the other players. The goal is to be the last player standing, either by defeating all of the other players’ champions or by surviving until the end of the game.
Players can also use their gold to upgrade their champions, making them stronger and more effective in battle, or buy experience and level up. As the game progresses, players must carefully manage their resources and make strategic decisions in order to outmaneuver their opponents and emerge victorious.
Teamfight Tactics game involves a lot of complex interactions and strategic decision-making.
If you are interested, I have written an article with some guidelines on how to improve at the game:
As a result, it produces a large amount of data that can be used to analyze and understand the gameplay.
This data can include information about the champions that players choose, the strategies they use, and the outcomes of matches.
Additionally, because Teamfight Tactics is a competitive game, players are always looking for ways to improve their performance and gain an edge over their opponents. This has led to the development of a thriving community of players who create and share tools and resources for analyzing and improving their gameplay. These tools often rely on large amounts of data to provide players with insights and recommendations for how to improve.
Overall, the large amount of data produced by Teamfight Tactics makes it an ideal game for players who are interested in using data analysis and strategy to improve their performance and compete at a higher level.
Big Data for E-sports
The world of esports is rapidly growing and evolving. Esports, or electronic sports, refers to organized competitive video gaming, in which professional players compete against each other in games such as League of Legends, Dota 2, and Fortnite.
The esports industry has experienced significant growth in recent years, with more and more people around the world becoming interested in watching and participating in competitive gaming. This growth has been driven by a number of factors, including the increasing popularity of online gaming, the growth of streaming platforms, and the rising prize pools for esports tournaments.
As a result of this growth, the esports industry has become a global phenomenon, with millions of players and fans around the world. Professional esports players are now considered to be athletes, and esports tournaments are held in major stadiums and arenas around the world.
Overall, the world of esports is an exciting and rapidly growing field, and it is likely to continue to evolve and expand in the coming years.
The potential of big data for e-sports is significant, as it can provide valuable insights and enable more effective decision-making in the world of competitive gaming. By analyzing large sets of data, e-sports organizations and players can gain valuable insights into the performance and behavior of players and teams, and can use this information to improve their strategies and tactics.
Big data can also be used to improve the spectator experience of e-sports. For example, by analyzing data about the performance of individual players and teams, e-sports broadcasters can provide more informative and engaging commentary, and can create more dynamic and interactive viewing experiences.
Additionally, big data can help e-sports organizations to better understand and engage with their audiences. By analyzing data about the behavior and preferences of e-sports fans, organizations can create more tailored and effective marketing and engagement strategies, and can better understand what their audiences want and need.
Overall, the potential of big data for e-sports is vast, and as the field continues to grow and evolve, it is likely that big data will play an increasingly important role in shaping the future of competitive gaming.
Why Python
Python is a popular programming language that is often used for data analysis due to its powerful libraries and easy-to-use syntax. Some of the key reasons why python is well-suited to data analysis include:
- Python has a large and active community of users, which means that there is a wealth of resources available for learning and using the language.
- Python has a number of powerful libraries for data manipulation and analysis, such as Pandas and NumPy, which make it easy to perform complex operations on data.
- Python is a high-level language, which means that it is easy to read and understand, even for people who are new to programming. This makes it a good choice for data analysts who want to quickly and easily explore and analyze their data.
- Python is also a versatile language, which means that it can be used for a wide range of tasks, from web development to scientific computing. This makes it a good choice for data analysts who may need to perform other types of work in addition to data analysis.
Overall, python’s combination of power, ease of use, and versatility make it a popular choice for data analysts who want to quickly and easily manipulate and analyze their data.
Riot Games API
Riot Games API is an application programming interface (API) that allows developers to access and integrate the functionality and data of the popular online multiplayer game League of Legends. The API enables developers to build applications and tools that can interact with the game, such as tools for analyzing game data, tracking player statistics, or providing in-game assistance.
The Riot Games API uses RESTful calls and returns data in JSON format. It provides access to a wide range of game data, including information about players, teams, matches, and leagues. The API also allows developers to access real-time game data, such as the positions of in-game champions or the status of objectives.
Overall, the Riot Games API provides a powerful and flexible way for developers to build tools and applications that can interact with League of Legends, allowing players to get more out of the game and improve their performance.
The Riot Games API requires developers to use an API key in order to access its data and functionality. An API key is a unique identifier that is used to authenticate a developer’s request to the API. It allows the API to identify the developer and ensure that only authorized applications are able to access its data.
The API key is typically passed as a parameter in the URL of the request, and the API uses it to verify the developer’s identity before returning the requested data.
Overall, the use of an API key is a common security measure that helps to ensure that only authorized developers and applications are able to access an API’s data and functionality. It is an important part of the Riot Games API and is required in order to use the API effectively.
Riot Watcher
Riot Watcher is a python library that provides an easy-to-use interface for accessing the Riot Games API. The library simplifies the process of making requests to the API and parsing the resulting data, making it easier for python developers to build applications that interact with League of Legends.
Riot Watcher provides a number of useful features, such as automatic rate limiting, which ensures that developers do not exceed the API’s usage limits. It also provides support for pagination, which allows developers to easily retrieve large amounts of data from the API.
In addition, Riot Watcher includes a number of helper functions that make it easy to access specific types of data from the API, such as information about players, matches, or leagues. This allows developers to quickly and easily build powerful tools and applications that can provide valuable insights and assistance to players of League of Legends.
Application example
The aim of this simple example is to use the API to request information about a summoner and extract information about his match history.
We then choose a region and a summoner name (existing) and use TftWatcher to instantiate a Watcher.
from riotwatcher import TftWatcher
import pandas as pd
import plotly.graph_objects as go
import numpy as np
api_key = '%YOUR API KEY%'
watcher = TftWatcher(api_key)
my_region = 'euw1'
summoner_name = '%YOUR SUMMONER NAME%'
me = watcher.summoner.by_name(my_region, 'LuxannaIRL')
for key in me:
print(key, ':', me[key])
The Riot API uses three IDs for players: summoner IDs, account IDs, and PUUIDs. Different APIs use different IDs, and you should use whichever ID is required by the API you are using.
Summoner and account IDs are only unique per region, and PUUIDs are unique globally.
Because the PUUID is globally unique, when a player transfers regions their PUUID will not change. This allows you to track summoners that have transferred regions. If a player transfers regions, their summoner and account IDs will change.
All IDs are encrypted using encryption keys unique to each project. An ID obtained with your dev key will not work with your production key (and vice versa). When you refresh a key, the encrypted ID will not change.
We, therefore, extract the last 20 matches.
matches_ids = watcher.match.by_puuid(my_region, me['puuid'], count=20)
matches = [watcher.match.by_id(my_region, item) for item in matches_ids]
Each match is represented by a dictionary with two keys: metadata and info.
matches[0].keys()
"""
dict_keys(['metadata', 'info'])
"""
matches[0]['metadata']
"""
{'data_version': '5',
'match_id': 'EUW1_6179693190',
'participants': ['xnNf19nya3s-SUDAdap5rmapcgmPxMlI1f6sNAuzCxybazR3iQ9RNypATXFGZN2-45F1Hn9VGBNYqQ',
'skN1ZXtZhG_VH03A06s7EMkDjaKund-uEkAseQvPUmf5e8oAxMXwo-1Qq4iO7ot4SUkTlihwVMK9Cg',
'o_vQ0F3ulDnLqB_CwcS-v0JAbMNu2G8EslWe0aDUHKNIn19SrqQT8l37VYVcWJl9508ucXacutLsfQ',
'dJa0SUgkP1A1tOOr6BnwKXTr8wtPdXZFwQEZk-q0_OQOxxjTbtZRUdCLvZ2chKsxg81CTyBv0EFyJw',
'Q-CNeovRbk8P9coDadMwNXitMvYPXbPMezl6ZrmT75ICHdXQzMjAMAAagDuFggVomQiMmy_15XmNFA',
'oRs-YqWFL470pWhztKppHnxCoRS1PcmNrMppIo0-Qis89X27AyPfPCjMSraRtp9iNZ4KBsmOXgugWA',
'U0qAdNFKLMpI44bW_mAkPxUg8aSb-ASV7USaYFUcoSseZhtysPeb8VDgAPqqw5-BRCwmwq9ParXN2g',
'O97SRuh9BjuoeKYILK6hLKWK__w5zMxCkw_jWfYTllcuNv952GSUvaslFnGdgeYddd_nz6EXK8p1gg']}
"""
matches[0]['info'].keys()
"""
dict_keys(['game_datetime', 'game_length', 'game_version', 'participants', 'queue_id', 'tft_game_type', 'tft_set_core_name', 'tft_set_number'])
"""
As anticipated, we have a huge amount of data available that can be used for data analysis, machine learning, and software development!
By way of example, let us extract the resulting data for a single match.
my_match_data = matches[0]['info']['participants'][matches[0]['metadata']['participants'].index(me['puuid'])]
my_match_data.keys()
"""
dict_keys(['augments', 'companion', 'gold_left', 'last_round', 'level', 'placement', 'players_eliminated', 'puuid', 'time_eliminated', 'total_damage_to_players', 'traits', 'units'])
"""
my_match_data['augments']
"""
['TFT6_Augment_Electrocharge1',
'TFT8_Augment_DravenCarry',
'TFT6_Augment_Ascension']
"""
my_match_data['placement']
"""
2
"""
my_match_data['units'][:2]
"""
[{'character_id': 'TFT8_WuKong',
'itemNames': [],
'items': [],
'name': '',
'rarity': 0,
'tier': 2},
{'character_id': 'TFT8_Draven',
'itemNames': ['TFT_Item_InfinityEdge',
'TFT_Item_UnstableConcoction',
'TFT_Item_JeweledGauntlet'],
'items': [19, 49, 39],
'name': '',
'rarity': 1,
'tier': 2}]
"""
All extracted data are in JSON format: we can use a good tool like JSON Crack to visualize them.
import json
with open('units.json', 'w') as file:
json.dump(my_match_data['units'], file, indent=4)
We can of course make graphical representations of our data: let’s create a plot showing our placements over the last 20 matches.
from __future__ import annotations
def get_placement_trend(matches: list | np.ndarray) -> np.ndarray:
"""
:param matches: list of matches
:return np.ndarray placement_trend:
"""
placement_trend = []
for match in matches:
my_match_data = match['info']['participants'][match['metadata']['participants'].index(me['puuid'])]
placement_trend.append(int(my_match_data['placement']))
return np.array(placement_trend, dtype=np.int32)
placements = get_placement_trend(matches=matches)
x = np.arange(len(placements))
fig = go.Figure()
fig.add_trace(go.Scatter(
x=x, y=placements,
name='sin',
mode='markers',
marker_color=placements
))
fig.update_traces(mode='markers', marker_line_width=2, marker_size=10)
fig.update_layout(title='Positioning trend', width=800)
You can find the full code here:
If you are interested in a similar analysis carried out for League of Legends, take a look at this article:
Greetings
To conclude, this article has discussed how to use the Riot Developer Portal, RiotWatcher, and Python to extract data from the TFT world.
We talked about:
- Big Data for E-sports
- Python for data analysis
- Riot Games API
- Riot Watcher
- An application example
As we have seen, the large amount of data produced by Teamfight Tactics makes it an ideal game for players who are interested in using data analysis and strategy to improve their performance and compete at a higher level.
Thank you for reading.