diff --git a/kloppy/infra/serializers/event/statsbomb/deserializer.py b/kloppy/infra/serializers/event/statsbomb/deserializer.py index f88e6a3e..d5bf4dcf 100644 --- a/kloppy/infra/serializers/event/statsbomb/deserializer.py +++ b/kloppy/infra/serializers/event/statsbomb/deserializer.py @@ -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 diff --git a/kloppy/tests/issues/test_issue_171.py b/kloppy/tests/issues/test_issue_171.py new file mode 100644 index 00000000..8678f8dc --- /dev/null +++ b/kloppy/tests/issues/test_issue_171.py @@ -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"