From c8cd1e3b70b7f769ef92b82bd1840e9541133d84 Mon Sep 17 00:00:00 2001 From: Joris Bekkers Date: Wed, 10 Jul 2024 14:17:35 +0200 Subject: [PATCH] made sure functionality is correct, if player doesn't exist, create player --- .../serializers/tracking/tracab/tracab_dat.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/kloppy/infra/serializers/tracking/tracab/tracab_dat.py b/kloppy/infra/serializers/tracking/tracab/tracab_dat.py index cfe3ad0a..dcd3f07e 100644 --- a/kloppy/infra/serializers/tracking/tracab/tracab_dat.py +++ b/kloppy/infra/serializers/tracking/tracab/tracab_dat.py @@ -72,11 +72,7 @@ def _frame_from_line(cls, teams, period, line, frame_rate): ) player = team.get_player_by_jersey_number(jersey_no) - if player: - players_data[player] = PlayerData( - coordinates=Point(float(x), float(y)), speed=float(speed) - ) - else: + if not player: player = Player( player_id=f"{team.ground}_{jersey_no}", team=team, @@ -84,6 +80,10 @@ def _frame_from_line(cls, teams, period, line, frame_rate): ) team.players.append(player) + players_data[player] = PlayerData( + coordinates=Point(float(x), float(y)), speed=float(speed) + ) + ( ball_x, ball_y, @@ -182,7 +182,6 @@ def deserialize(self, inputs: TRACABInputs) -> TrackingDataset: ) ) - if meta_data.get("HomeTeam") and meta_data.get("AwayTeam"): home_team = self.create_team( meta_data["HomeTeam"], Ground.HOME, start_frame_id @@ -191,8 +190,12 @@ def deserialize(self, inputs: TRACABInputs) -> TrackingDataset: meta_data["AwayTeam"], Ground.AWAY, start_frame_id ) else: - home_team = Team(team_id="home", name="home", ground=Ground.HOME) - away_team = Team(team_id="away", name="away", ground=Ground.AWAY) + home_team = Team( + team_id="home", name="home", ground=Ground.HOME + ) + away_team = Team( + team_id="away", name="away", ground=Ground.AWAY + ) teams = [home_team, away_team] with performance_logging("Loading data", logger=logger):