Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Wyscout V3] add shot assist qualifier #347

Merged
merged 4 commits into from
Oct 25, 2024
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
22 changes: 14 additions & 8 deletions kloppy/infra/serializers/event/wyscout/deserializer_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,20 @@ def _check_secondary_event_types(
def _pass_qualifiers(raw_event) -> List[Qualifier]:
qualifiers = _generic_qualifiers(raw_event)

if _check_secondary_event_types(raw_event, ["cross", "cross_blocked"]):
qualifiers.append(PassQualifier(PassType.CROSS))
elif _check_secondary_event_types(raw_event, ["hand_pass"]):
qualifiers.append(PassQualifier(PassType.HAND_PASS))
elif _check_secondary_event_types(raw_event, ["head_pass"]):
qualifiers.append(PassQualifier(PassType.HEAD_PASS))
elif _check_secondary_event_types(raw_event, ["smart_pass"]):
qualifiers.append(PassQualifier(PassType.SMART_PASS))
qualifier_mapping = {
DriesDeprest marked this conversation as resolved.
Show resolved Hide resolved
PassType.CROSS: ["cross", "cross_blocked"],
PassType.HAND_PASS: ["hand_pass"],
PassType.HEAD_PASS: ["head_pass"],
PassType.SMART_PASS: ["smart_pass"],
PassType.SHOT_ASSIST: ["shot_assist"],
PassType.ASSIST: ["assist"],
}

for pass_type, secondary_event_types_values in qualifier_mapping.items():
if _check_secondary_event_types(
raw_event, secondary_event_types_values
):
qualifiers.append(PassQualifier(pass_type))

return qualifiers

Expand Down
3 changes: 2 additions & 1 deletion kloppy/tests/files/wyscout_events_v3.json
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@
"primary": "pass",
"secondary": [
"lateral_pass",
"short_or_medium_pass"
"short_or_medium_pass",
"shot_assist"
]
},
"videoTimestamp": "6.417876"
Expand Down
9 changes: 9 additions & 0 deletions kloppy/tests/test_wyscout.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
Orientation,
FormationType,
Time,
PassType,
PassQualifier,
)

from kloppy import wyscout
Expand Down Expand Up @@ -250,6 +252,13 @@ def test_goalkeeper_event(self, dataset: EventDataset):
== GoalkeeperActionType.SAVE
)

def test_shot_assist_event(self, dataset: EventDataset):
shot_assist_event = dataset.get_event_by_id(663291837)
assert shot_assist_event.event_type == EventType.PASS
assert PassType.SHOT_ASSIST in shot_assist_event.get_qualifier_values(
PassQualifier
)

def test_shot_event(self, dataset: EventDataset):
shot_event = dataset.get_event_by_id(663291840)
assert shot_event.event_type == EventType.SHOT
Expand Down
Loading