In [1]:
Copied!
from kloppy import metrica
dataset = metrica.load_open_data(limit=10)
from kloppy import metrica
dataset = metrica.load_open_data(limit=10)
Exploring the data¶
When you want to show the name of a player you are advised to use str(player)
. This will call the magic __str__
method that handles fallbacks for missing data. By default it will return full_name
, and fallback to 1) first_name last_name
2) player_id
.
In [2]:
Copied!
metadata = dataset.metadata
home_team, away_team = metadata.teams
[f"{player} ({player.jersey_no})" for player in home_team.players]
metadata = dataset.metadata
home_team, away_team = metadata.teams
[f"{player} ({player.jersey_no})" for player in home_team.players]
Out[2]:
['home_11 (11)', 'home_1 (1)', 'home_2 (2)', 'home_3 (3)', 'home_4 (4)', 'home_5 (5)', 'home_6 (6)', 'home_7 (7)', 'home_8 (8)', 'home_9 (9)', 'home_10 (10)', 'home_12 (12)', 'home_13 (13)', 'home_14 (14)']
In [3]:
Copied!
print(f"{home_team.ground} - {home_team}")
print(f"{away_team.ground} - {away_team}")
print(f"{home_team.ground} - {home_team}")
print(f"{away_team.ground} - {away_team}")
home - Home away - Away
Working with tracking data¶
The actual tracking data is available at dataset.frames
. This list holds all frames. Each frame has a players_coordinates
dictionary that is indexed by Player
entities and has values of the Point
type.
In [4]:
Copied!
first_frame = dataset.frames[0]
print(f"Number of players in the frame: {len(first_frame.players_coordinates)}")
from pprint import pprint
print("List home team players coordinates")
pprint([
player_coordinates
for player, player_coordinates
in first_frame.players_coordinates.items()
if player.team == home_team
])
first_frame = dataset.frames[0]
print(f"Number of players in the frame: {len(first_frame.players_coordinates)}")
from pprint import pprint
print("List home team players coordinates")
pprint([
player_coordinates
for player, player_coordinates
in first_frame.players_coordinates.items()
if player.team == home_team
])
Number of players in the frame: 22 List home team players coordinates [Point(x=0.00082, y=0.51762), Point(x=0.32648, y=0.34678), Point(x=0.33701, y=0.51137), Point(x=0.30927, y=0.64471), Point(x=0.32137, y=0.78738), Point(x=0.41094, y=0.27410999999999996), Point(x=0.41698, y=0.52157), Point(x=0.39125, y=0.6745), Point(x=0.45388, y=0.78826), Point(x=0.52697, y=0.6202), Point(x=0.55243, y=0.56731)]
In [ ]:
Copied!