diff --git a/kloppy/domain/models/common.py b/kloppy/domain/models/common.py index 003ba028..d042ea07 100644 --- a/kloppy/domain/models/common.py +++ b/kloppy/domain/models/common.py @@ -18,7 +18,7 @@ Iterable, ) -from .position import PositionType, RefereeType +from .position import PositionType from ...utils import deprecated @@ -119,13 +119,20 @@ def __str__(self): return self.value +class OfficialType: + VideoAssistantReferee = "Video Assistant Referee" + MainReferee = "Main Referee" + AssistantReferee = "Assistant Referee" + FourthOfficial = "Fourth Official" + + @dataclass(frozen=True) -class Referee: - referee_id: str +class Official: + official_id: str name: Optional[str] = None first_name: Optional[str] = None last_name: Optional[str] = None - role: Optional[RefereeType] = None + role: Optional[OfficialType] = None @property def full_name(self): @@ -134,8 +141,8 @@ def full_name(self): if self.first_name or self.last_name: return f"{self.first_name} {self.last_name}" if self.role: - return f"{self.role}_{self.referee_id}" - return f"referee_{self.referee_id}" + return f"{self.role}_{self.official_id}" + return f"referee_{self.official_id}" @dataclass(frozen=True) @@ -1035,7 +1042,7 @@ class Metadata: game_id: Optional[str] = None home_coach: Optional[str] = None away_coach: Optional[str] = None - referees: Optional[List] = field(default_factory=list) + officials: Optional[List] = field(default_factory=list) attributes: Optional[Dict] = field(default_factory=dict, compare=False) def __post_init__(self): diff --git a/kloppy/domain/models/position.py b/kloppy/domain/models/position.py index 9c62fe9c..84d08280 100644 --- a/kloppy/domain/models/position.py +++ b/kloppy/domain/models/position.py @@ -92,10 +92,3 @@ def __str__(self): @classmethod def unknown(cls) -> "PositionType": return cls.Unknown - - -class RefereeType: - VideoReferee = "Video Referee" - Referee = "Referee" - Assistant = "Assistant" - FourthOfficial = "Fourth Official" diff --git a/kloppy/infra/serializers/event/sportec/deserializer.py b/kloppy/infra/serializers/event/sportec/deserializer.py index bf184ae9..57d105a4 100644 --- a/kloppy/infra/serializers/event/sportec/deserializer.py +++ b/kloppy/infra/serializers/event/sportec/deserializer.py @@ -29,8 +29,8 @@ CardType, AttackingDirection, PositionType, - Referee, - RefereeType, + Official, + OfficialType, ) from kloppy.exceptions import DeserializationError from kloppy.infra.serializers.event.deserializer import EventDataDeserializer @@ -57,12 +57,12 @@ "LA": PositionType.LeftWing, } -referee_types_mapping: Dict[str, RefereeType] = { - "referee": RefereeType.Referee, - "firstAssistant": RefereeType.Assistant, - "videoReferee": RefereeType.VideoReferee, - "secondAssistant": RefereeType.Assistant, - "fourthOfficial": RefereeType.FourthOfficial, +referee_types_mapping: Dict[str, OfficialType] = { + "referee": OfficialType.MainReferee, + "firstAssistant": OfficialType.AssistantReferee, + "videoReferee": OfficialType.VideoAssistantReferee, + "secondAssistant": OfficialType.AssistantReferee, + "fourthOfficial": OfficialType.FourthOfficial, } logger = logging.getLogger(__name__) @@ -112,7 +112,7 @@ class SportecMetadata(NamedTuple): fps: int home_coach: str away_coach: str - referees: List[Referee] + officials: List[Official] def sportec_metadata_from_xml_elm(match_root) -> SportecMetadata: @@ -227,7 +227,7 @@ def sportec_metadata_from_xml_elm(match_root) -> SportecMetadata: if hasattr(match_root, "MatchInformation") and hasattr( match_root.MatchInformation, "Referees" ): - referees = [] + officials = [] referee_path = objectify.ObjectPath( "PutDataRequest.MatchInformation.Referees" ) @@ -237,9 +237,9 @@ def sportec_metadata_from_xml_elm(match_root) -> SportecMetadata: for referee in referee_elms: ref_attrib = referee.attrib - referees.append( - Referee( - referee_id=ref_attrib["PersonId"], + officials.append( + Official( + official_id=ref_attrib["PersonId"], name=ref_attrib["Shortname"], first_name=ref_attrib["FirstName"], last_name=ref_attrib["LastName"], @@ -247,7 +247,7 @@ def sportec_metadata_from_xml_elm(match_root) -> SportecMetadata: ) ) else: - referees = [] + officials = [] return SportecMetadata( score=score, @@ -258,7 +258,7 @@ def sportec_metadata_from_xml_elm(match_root) -> SportecMetadata: fps=SPORTEC_FPS, home_coach=home_coach, away_coach=away_coach, - referees=referees, + officials=officials, ) @@ -710,7 +710,7 @@ def deserialize(self, inputs: SportecEventDataInputs) -> EventDataset: game_id=game_id, home_coach=home_coach, away_coach=away_coach, - referees=sportec_metadata.referees, + officials=sportec_metadata.officials, ) return EventDataset( diff --git a/kloppy/infra/serializers/tracking/sportec/deserializer.py b/kloppy/infra/serializers/tracking/sportec/deserializer.py index f17dbb3d..7cc08516 100644 --- a/kloppy/infra/serializers/tracking/sportec/deserializer.py +++ b/kloppy/infra/serializers/tracking/sportec/deserializer.py @@ -131,9 +131,11 @@ def deserialize( home_coach = sportec_metadata.home_coach away_coach = sportec_metadata.away_coach - referee_ids = [] - if sportec_metadata.referees: - referee_ids = [x.referee_id for x in sportec_metadata.referees] + official_ids = [] + if sportec_metadata.officials: + official_ids = [ + x.official_id for x in sportec_metadata.officials + ] with performance_logging("parse raw data", logger=logger): date = parse( @@ -199,7 +201,7 @@ def _iter(): ) for player_id, raw_player_data in frame_data.items() if player_id != "ball" - and player_id not in referee_ids + and player_id not in official_ids }, other_data={}, ball_coordinates=Point3D( @@ -249,7 +251,7 @@ def _iter(): game_id=game_id, home_coach=home_coach, away_coach=away_coach, - referees=sportec_metadata.referees, + officials=sportec_metadata.officials, ) return TrackingDataset( diff --git a/kloppy/tests/test_sportec.py b/kloppy/tests/test_sportec.py index 827ff4dd..ac459579 100644 --- a/kloppy/tests/test_sportec.py +++ b/kloppy/tests/test_sportec.py @@ -149,7 +149,7 @@ def test_load_metadata(self, raw_data: Path, meta_data: Path): assert dataset.metadata.periods[1].end_timestamp == timedelta( seconds=4000 + 2996.68 ) - assert len(dataset.metadata.referees) == 4 + assert len(dataset.metadata.officials) == 4 def test_load_frames(self, raw_data: Path, meta_data: Path): dataset = sportec.load_tracking( @@ -251,4 +251,4 @@ def test_referees(self, raw_data_referee: Path, meta_data: Path): coordinates="sportec", only_alive=True, ) - assert len(dataset.metadata.referees) == 4 + assert len(dataset.metadata.officials) == 4