Skip to content

Commit

Permalink
Merge pull request #174 from PySport/bugfix/home-away-team-statsbomb
Browse files Browse the repository at this point in the history
Fix for issue 171
  • Loading branch information
koenvo authored Mar 5, 2023
2 parents 65c88dd + 451a339 commit a463385
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
9 changes: 8 additions & 1 deletion kloppy/infra/serializers/event/statsbomb/deserializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,14 @@ def deserialize(self, inputs: StatsBombInputs) -> EventDataset:

with performance_logging("load data", logger=logger):
raw_events = json.load(inputs.event_data)
home_lineup, away_lineup = json.load(inputs.lineup_data)
lineups = json.load(inputs.lineup_data)

# First event (Starting-XI) determines home team
if raw_events[0]["team"]["id"] == lineups[0]["team_id"]:
home_lineup, away_lineup = lineups
else:
away_lineup, home_lineup = lineups

if inputs.three_sixty_data:
three_sixty_data = {
item["event_uuid"]: item
Expand Down
16 changes: 16 additions & 0 deletions kloppy/tests/issues/test_issue_171.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import os

from kloppy import statsbomb


class TestIssue171:
def test_determine_statsbomb_home_away_teams(self):
base_dir = os.path.dirname(__file__)

dataset = statsbomb.load(
event_data=f"{base_dir}/../files/statsbomb_3788741_event.json",
lineup_data=f"{base_dir}/../files/statsbomb_3788741_lineup.json",
coordinates="statsbomb",
)

assert dataset.metadata.teams[0].name == "Turkey"

0 comments on commit a463385

Please sign in to comment.