diff --git a/kloppy/infra/serializers/event/wyscout/deserializer_v3.py b/kloppy/infra/serializers/event/wyscout/deserializer_v3.py index a354d3f0..95bd331b 100644 --- a/kloppy/infra/serializers/event/wyscout/deserializer_v3.py +++ b/kloppy/infra/serializers/event/wyscout/deserializer_v3.py @@ -282,12 +282,12 @@ def _parse_carry(raw_event: Dict, next_event: Dict, start_ts: Dict) -> Dict: ) if next_event is not None: - period_id = int(next_event["matchPeriod"].replace("H", "")) + period_id = _parse_period_id(next_event["matchPeriod"]) end_timestamp = _create_timestamp_timedelta( next_event, start_ts, period_id ) else: - period_id = int(raw_event["matchPeriod"].replace("H", "")) + period_id = _parse_period_id(raw_event["matchPeriod"]) end_timestamp = _create_timestamp_timedelta( raw_event, start_ts, period_id ) @@ -511,6 +511,19 @@ def _players_to_dict(players: List[Player]): return {player.player_id: player for player in players} +def _parse_period_id(raw_period: str) -> int: + if "H" in raw_period: + period_id = int(raw_period.replace("H", "")) + elif "E" in raw_period: + period_id = 2 + int(raw_period.replace("E", "")) + elif raw_period == "P": + period_id = 5 + else: + raise DeserializationError(f"Unknown period {raw_period}") + + return period_id + + class WyscoutDeserializerV3(EventDataDeserializer[WyscoutInputs]): @property def provider(self) -> Provider: @@ -572,14 +585,14 @@ def deserialize(self, inputs: WyscoutInputs) -> EventDataset: next_period_id = None if (idx + 1) < len(raw_events["events"]): next_event = raw_events["events"][idx + 1] - next_period_id = int( - next_event["matchPeriod"].replace("H", "") + next_period_id = _parse_period_id( + next_event["matchPeriod"] ) team_id = str(raw_event["team"]["id"]) team = teams[team_id] player_id = str(raw_event["player"]["id"]) - period_id = int(raw_event["matchPeriod"].replace("H", "")) + period_id = _parse_period_id(raw_event["matchPeriod"]) if len(periods) == 0 or periods[-1].id != period_id: periods.append(