Skip to content
Open
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: 2 additions & 0 deletions kloppy/_providers/hawkeye.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def load(
limit: Optional[int] = None,
coordinates: Optional[str] = None,
show_progress: Optional[bool] = False,
object_id: Optional[str] = None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add this to the docstring?

) -> TrackingDataset:
"""
Load HawkEye tracking data.
Expand Down Expand Up @@ -62,6 +63,7 @@ def load(
sample_rate=sample_rate,
limit=limit,
coordinate_system=coordinates,
object_id=object_id,
)
return deserializer.deserialize(
inputs=HawkEyeInputs(
Expand Down
22 changes: 17 additions & 5 deletions kloppy/infra/serializers/tracking/hawkeye/deserializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ def get_identifier_variable(cls, player_tracking_data):
return identifier
return object_id

@classmethod
def is_priority(cls, object_id):
if object_id in cls.PRIORITY_IDS:
return True
else:
return False


class HawkEyeDeserializer(TrackingDataDeserializer[HawkEyeInputs]):
def __init__(
Expand All @@ -82,9 +89,12 @@ def __init__(
limit: Optional[int] = None,
sample_rate: Optional[float] = None,
coordinate_system: Optional[Union[str, Provider]] = None,
object_id: Optional[str] = None,
):
super().__init__(limit, sample_rate, coordinate_system)
self.object_id: HawkEyeObjectIdentifier = None
self.object_id: HawkEyeObjectIdentifier = (
None if object_id is None else object_id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is identical to

self.object_id = object_id

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also do not see where the user-provided object_id is taken into account.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm running into some issues because I removed this branch, but the goal of the object_id is to allow users to specify an object_id that is not any of those 3 (heId, fifaId or uefaId) in a case when they get their data and it does not have any of these keys to identify player and team objects.

I'll redo this PR at some point.

)
self.pitch_width = pitch_width
self.pitch_length = pitch_length

Expand Down Expand Up @@ -270,17 +280,19 @@ def deserialize(self, inputs: HawkEyeInputs) -> TrackingDataset:
with open_as_file(player_centroid_feed) as player_centroid_data_fp:
player_tracking_data = json.load(player_centroid_data_fp)

self.object_id = HawkEyeObjectIdentifier.get_identifier_variable(
_object_id = HawkEyeObjectIdentifier.get_identifier_variable(
player_tracking_data
)
if HawkEyeObjectIdentifier.is_priority(_object_id):
self.object_id = _object_id

if frame_rate is None:
frame_rate = self.__infer_frame_rate(ball_tracking_data)

if not self._game_id:
self._game_id = ball_tracking_data["details"]["match"]["id"][
self.object_id
]
self._game_id = ball_tracking_data["details"]["match"][
"id"
].get(self.object_id, None)

# Parse the teams, players and periods. A value can be added by
# later feeds, but we will not overwrite existing values.
Expand Down
Loading