Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions docs/user-guide/concepts/metadata/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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). |


Expand Down
14 changes: 12 additions & 2 deletions kloppy/domain/models/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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")

Expand Down
11 changes: 3 additions & 8 deletions kloppy/infra/serializers/event/sportec/deserializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ class SportecMetadata(NamedTuple):
x_max: float
y_max: float
fps: int
home_coach: str
away_coach: str
officials: list[Official]


Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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,
)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
)

Expand Down
8 changes: 8 additions & 0 deletions kloppy/infra/serializers/event/statsbomb/deserializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions kloppy/infra/serializers/event/wyscout/deserializer_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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)
5 changes: 3 additions & 2 deletions kloppy/infra/serializers/tracking/skillcorner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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(
Expand Down
2 changes: 0 additions & 2 deletions kloppy/infra/serializers/tracking/sportec/deserializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down
4 changes: 2 additions & 2 deletions kloppy/tests/test_skillcorner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions kloppy/tests/test_sportec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions kloppy/tests/test_statsbomb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading