diff --git a/docs/user-guide/concepts/metadata/index.md b/docs/user-guide/concepts/metadata/index.md index 31a0d647b..632efc346 100644 --- a/docs/user-guide/concepts/metadata/index.md +++ b/docs/user-guide/concepts/metadata/index.md @@ -22,8 +22,6 @@ Match sheet metadata refers to official match-related information. This typicall | [`teams`][kloppy.domain.Metadata.teams] | [`Team`][kloppy.domain.Team] | No | List containing home team and away team metadata. | | [`officials`][kloppy.domain.Metadata.officials] | [`Official`][kloppy.domain.Official] | Yes | List of match officials (i.e., referees). | | [`score`][kloppy.domain.Metadata.score] | [`Score`][kloppy.domain.Score] | Yes | Final score of the match. | -| [`home_coach`][kloppy.domain.Metadata.home_coach] | str | Yes | Name of the home team's coach. | -| [`away_coach`][kloppy.domain.Metadata.away_coach] | str | Yes | Name of the away team's coach. | | [`attributes`][kloppy.domain.Metadata.attributes] | Dict | Yes | Additional metadata such as stadium, weather, or attendance (if available). | diff --git a/kloppy/domain/models/common.py b/kloppy/domain/models/common.py index 64470d0f8..22feb5c21 100644 --- a/kloppy/domain/models/common.py +++ b/kloppy/domain/models/common.py @@ -261,6 +261,7 @@ class Team: ground (Ground): The team's ground (home or away). players (List[Player]): The team's players. starting_formation (FormationType, optional): The team's starting formation. + coach (str, optional): The team's coach. """ team_id: str @@ -271,6 +272,7 @@ class Team: default_factory=TimeContainer, compare=False ) players: list[Player] = field(default_factory=list) + coach: Optional[str] = None def __str__(self): return self.name @@ -1647,8 +1649,6 @@ class Metadata: date: Optional[datetime] = None game_week: Optional[str] = None game_id: Optional[str] = None - home_coach: Optional[str] = None - away_coach: Optional[str] = None officials: Optional[list] = field(default_factory=list) attributes: Optional[dict] = field(default_factory=dict, compare=False) @@ -1665,6 +1665,16 @@ def __post_init__(self): ), ) + @property + @deprecated("Use teams[0].coach instead") + def home_coach(self) -> Optional[str]: + return self.teams[0].coach if self.teams else None + + @property + @deprecated("Use teams[1].coach instead") + def away_coach(self) -> Optional[str]: + return self.teams[1].coach if self.teams else None + T = TypeVar("T", bound="DataRecord") diff --git a/kloppy/infra/serializers/event/sportec/deserializer.py b/kloppy/infra/serializers/event/sportec/deserializer.py index c19a50e4e..229803070 100644 --- a/kloppy/infra/serializers/event/sportec/deserializer.py +++ b/kloppy/infra/serializers/event/sportec/deserializer.py @@ -109,8 +109,6 @@ class SportecMetadata(NamedTuple): x_max: float y_max: float fps: int - home_coach: str - away_coach: str officials: list[Official] @@ -154,6 +152,9 @@ def sportec_metadata_from_xml_elm(match_root) -> SportecMetadata: away_score, ) = match_root.MatchInformation.General.attrib["Result"].split(":") score = Score(home=int(home_score), away=int(away_score)) + + home_team.coach = home_coach + away_team.coach = away_coach teams = [home_team, away_team] if len(home_team.players) == 0 or len(away_team.players) == 0: @@ -256,8 +257,6 @@ def sportec_metadata_from_xml_elm(match_root) -> SportecMetadata: x_max=x_max, y_max=y_max, fps=SPORTEC_FPS, - home_coach=home_coach, - away_coach=away_coach, officials=officials, ) @@ -479,8 +478,6 @@ def deserialize(self, inputs: SportecEventDataInputs) -> EventDataset: pitch_length=sportec_metadata.x_max, pitch_width=sportec_metadata.y_max, ) - home_coach = sportec_metadata.home_coach - away_coach = sportec_metadata.away_coach periods = [] period_id = 0 @@ -702,8 +699,6 @@ def deserialize(self, inputs: SportecEventDataInputs) -> EventDataset: date=date, game_week=game_week, game_id=game_id, - home_coach=home_coach, - away_coach=away_coach, officials=sportec_metadata.officials, ) diff --git a/kloppy/infra/serializers/event/statsbomb/deserializer.py b/kloppy/infra/serializers/event/statsbomb/deserializer.py index d36d4f747..076e24b97 100644 --- a/kloppy/infra/serializers/event/statsbomb/deserializer.py +++ b/kloppy/infra/serializers/event/statsbomb/deserializer.py @@ -81,6 +81,14 @@ def deserialize( event = self.transformer.transform_event(event) events.append(event) + if "home_coach" in additional_metadata: + home_coach = additional_metadata.pop("home_coach") + teams[0].coach = home_coach + + if "away_coach" in additional_metadata: + away_coach = additional_metadata.pop("away_coach") + teams[1].coach = away_coach + metadata = Metadata( teams=teams, periods=periods, diff --git a/kloppy/infra/serializers/event/wyscout/deserializer_v3.py b/kloppy/infra/serializers/event/wyscout/deserializer_v3.py index c91c6dc06..a2c7cef60 100644 --- a/kloppy/infra/serializers/event/wyscout/deserializer_v3.py +++ b/kloppy/infra/serializers/event/wyscout/deserializer_v3.py @@ -806,6 +806,9 @@ def deserialize(self, inputs: WyscoutInputs) -> EventDataset: if away_team_id in coaches and "coach" in coaches[away_team_id]: away_coach = coaches[away_team_id]["coach"].get("shortName") + home_team.coach = home_coach + away_team.coach = away_coach + periods = create_periods(raw_events, start_ts) events = [] @@ -1039,8 +1042,6 @@ def deserialize(self, inputs: WyscoutInputs) -> EventDataset: date=date, game_week=game_week, game_id=game_id, - home_coach=home_coach, - away_coach=away_coach, ) return EventDataset(metadata=metadata, records=events) diff --git a/kloppy/infra/serializers/tracking/skillcorner.py b/kloppy/infra/serializers/tracking/skillcorner.py index 497c7da8e..756053af3 100644 --- a/kloppy/infra/serializers/tracking/skillcorner.py +++ b/kloppy/infra/serializers/tracking/skillcorner.py @@ -478,6 +478,9 @@ def deserialize(self, inputs: SkillCornerInputs) -> TrackingDataset: else None ) + home_team.coach = home_coach + away_team.coach = away_coach + if game_id: game_id = str(game_id) @@ -595,8 +598,6 @@ def _iter(): coordinate_system=transformer.get_to_coordinate_system(), date=date, game_id=game_id, - home_coach=home_coach, - away_coach=away_coach, ) return TrackingDataset( diff --git a/kloppy/infra/serializers/tracking/sportec/deserializer.py b/kloppy/infra/serializers/tracking/sportec/deserializer.py index a21f6b5a5..0fd793445 100644 --- a/kloppy/infra/serializers/tracking/sportec/deserializer.py +++ b/kloppy/infra/serializers/tracking/sportec/deserializer.py @@ -458,8 +458,6 @@ def deserialize(self, inputs: SportecTrackingDataInputs) -> TrackingDataset: date=date, game_week=game_week, game_id=game_id, - home_coach=sportec_metadata.home_coach, - away_coach=sportec_metadata.away_coach, officials=sportec_metadata.officials, ) diff --git a/kloppy/tests/test_skillcorner.py b/kloppy/tests/test_skillcorner.py index cb08aa98d..45cb08c0e 100644 --- a/kloppy/tests/test_skillcorner.py +++ b/kloppy/tests/test_skillcorner.py @@ -147,12 +147,12 @@ def test_correct_deserialization(self, raw_data: Path, meta_data: Path): assert isinstance(game_id, str) assert game_id == "2417" - home_coach = dataset.metadata.home_coach + home_coach = dataset.metadata.teams[0].coach if home_coach: assert isinstance(home_coach, str) assert home_coach == "Hans-Dieter Flick" - away_coach = dataset.metadata.away_coach + away_coach = dataset.metadata.teams[1].coach if away_coach: assert isinstance(away_coach, str) assert away_coach == "Lucien Favre" diff --git a/kloppy/tests/test_sportec.py b/kloppy/tests/test_sportec.py index da6c39258..d19b77152 100644 --- a/kloppy/tests/test_sportec.py +++ b/kloppy/tests/test_sportec.py @@ -178,12 +178,12 @@ def test_enriched_metadata(self, dataset: TrackingDataset): assert isinstance(game_id, str) assert game_id == "DFL-MAT-003BN1" - home_coach = dataset.metadata.home_coach + home_coach = dataset.metadata.teams[0].coach if home_coach: assert isinstance(home_coach, str) assert home_coach == "C. Streich" - away_coach = dataset.metadata.away_coach + away_coach = dataset.metadata.teams[1].coach if away_coach: assert isinstance(away_coach, str) assert away_coach == "M. Rose" diff --git a/kloppy/tests/test_statsbomb.py b/kloppy/tests/test_statsbomb.py index d850a396e..e7e6e8646 100644 --- a/kloppy/tests/test_statsbomb.py +++ b/kloppy/tests/test_statsbomb.py @@ -253,12 +253,12 @@ def test_enriched_metadata(self, dataset): assert isinstance(game_id, str) assert game_id == "3888787" - home_coach = dataset.metadata.home_coach + home_coach = dataset.metadata.teams[0].coach if home_coach: assert isinstance(home_coach, str) assert home_coach == "R. Martínez Montoliù" - away_coach = dataset.metadata.away_coach + away_coach = dataset.metadata.teams[1].coach if away_coach: assert isinstance(away_coach, str) assert away_coach == "F. Fernandes da Costa Santos"