Skip to content

Commit

Permalink
Merge pull request #347 from my-game-plan/feature/wyscout-shot-assist
Browse files Browse the repository at this point in the history
[Wyscout V3] add shot assist qualifier
  • Loading branch information
koenvo authored Oct 25, 2024
2 parents 2895ae7 + c0e5206 commit f542462
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
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 @@ -166,14 +166,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 = {
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 @@ -21,6 +21,8 @@
PassResult,
FormationType,
Time,
PassType,
PassQualifier,
)

from kloppy import wyscout
Expand Down Expand Up @@ -262,6 +264,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

0 comments on commit f542462

Please sign in to comment.