From d4162f7eb8d4d7c3b86133dc4cb1e98385d3dba5 Mon Sep 17 00:00:00 2001 From: UnravelSports <64530306+UnravelSports@users.noreply.github.com> Date: Wed, 22 May 2024 19:53:20 +0000 Subject: [PATCH 1/2] Fixed missing Result tag --- kloppy/infra/serializers/event/opta/deserializer.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/kloppy/infra/serializers/event/opta/deserializer.py b/kloppy/infra/serializers/event/opta/deserializer.py index af91d8d7..dfc3f72e 100644 --- a/kloppy/infra/serializers/event/opta/deserializer.py +++ b/kloppy/infra/serializers/event/opta/deserializer.py @@ -726,9 +726,13 @@ def deserialize(self, inputs: OptaInputs) -> EventDataset: ) score = Score(home=home_score, away=away_score) teams = [home_team, away_team] - match_result_type = list(match_result_path.find(f7_root))[ - 0 - ].attrib["Type"] + try: + match_result_type = list(match_result_path.find(f7_root))[ + 0 + ].attrib["Type"] + except AttributeError: + match_result_type = None + periods = _create_periods(match_result_type) if len(home_team.players) == 0 or len(away_team.players) == 0: From 615e4e99dd40547643ad6fb435581b5b9dafcc22 Mon Sep 17 00:00:00 2001 From: Joris Bekkers Date: Tue, 28 May 2024 09:32:35 +0200 Subject: [PATCH 2/2] removed try except --- .../serializers/event/opta/deserializer.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/kloppy/infra/serializers/event/opta/deserializer.py b/kloppy/infra/serializers/event/opta/deserializer.py index dfc3f72e..ff91b506 100644 --- a/kloppy/infra/serializers/event/opta/deserializer.py +++ b/kloppy/infra/serializers/event/opta/deserializer.py @@ -704,9 +704,11 @@ def deserialize(self, inputs: OptaInputs) -> EventDataset: matchdata_path = objectify.ObjectPath( "SoccerFeed.SoccerDocument.MatchData" ) - match_result_path = objectify.ObjectPath( - "SoccerFeed.SoccerDocument.MatchData.MatchInfo.Result" + + result_elements = f7_root.xpath( + "/SoccerFeed/SoccerDocument/MatchData/MatchInfo/Result" ) + team_elms = list( matchdata_path.find(f7_root).iterchildren("TeamData") ) @@ -726,13 +728,12 @@ def deserialize(self, inputs: OptaInputs) -> EventDataset: ) score = Score(home=home_score, away=away_score) teams = [home_team, away_team] - try: - match_result_type = list(match_result_path.find(f7_root))[ - 0 - ].attrib["Type"] - except AttributeError: + + if result_elements and "Type" in result_elements[0].attrib: + match_result_type = result_elements[0].attrib["Type"] + else: match_result_type = None - + periods = _create_periods(match_result_type) if len(home_team.players) == 0 or len(away_team.players) == 0: