From 3bb5d43fe404bd4b45ca267e6e292f89e394e517 Mon Sep 17 00:00:00 2001 From: driesdeprest Date: Thu, 30 Nov 2023 15:32:02 +0100 Subject: [PATCH 1/3] Add tackle as duel type and recognize StatsPerform challenge event --- kloppy/domain/models/event.py | 1 + .../serializers/event/opta/deserializer.py | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/kloppy/domain/models/event.py b/kloppy/domain/models/event.py index 2226b930..f335eede 100644 --- a/kloppy/domain/models/event.py +++ b/kloppy/domain/models/event.py @@ -468,6 +468,7 @@ class DuelType(Enum): GROUND = "GROUND" LOOSE_BALL = "LOOSE_BALL" SLIDING_TACKLE = "SLIDING_TACKLE" + TACKLE = "TACKLE" @dataclass diff --git a/kloppy/infra/serializers/event/opta/deserializer.py b/kloppy/infra/serializers/event/opta/deserializer.py index 805625c4..81df28b3 100644 --- a/kloppy/infra/serializers/event/opta/deserializer.py +++ b/kloppy/infra/serializers/event/opta/deserializer.py @@ -65,6 +65,7 @@ EVENT_TYPE_TAKE_ON = 3 EVENT_TYPE_TACKLE = 7 EVENT_TYPE_AERIAL = 44 +EVENT_TYPE_CHALLENGE = 45 EVENT_TYPE_50_50 = 67 EVENT_TYPE_INTERCEPTION = 8 EVENT_TYPE_CLEARANCE = 12 @@ -95,7 +96,12 @@ ] BALL_OUT_EVENTS = [EVENT_TYPE_BALL_OUT, EVENT_TYPE_CORNER_AWARDED] -DUEL_EVENTS = [EVENT_TYPE_TACKLE, EVENT_TYPE_AERIAL, EVENT_TYPE_50_50] +DUEL_EVENTS = [ + EVENT_TYPE_TACKLE, + EVENT_TYPE_AERIAL, + EVENT_TYPE_50_50, + EVENT_TYPE_CHALLENGE, +] BALL_OWNING_EVENTS = ( EVENT_TYPE_PASS, @@ -378,15 +384,15 @@ def _parse_duel( raw_qualifiers: Dict[int, str], type_id: int, outcome: int ) -> Dict: qualifiers = _get_event_qualifiers(raw_qualifiers) - if type_id == EVENT_TYPE_TACKLE: - qualifiers.extend([DuelQualifier(value=DuelType.GROUND)]) - elif type_id == EVENT_TYPE_AERIAL: + if type_id in [EVENT_TYPE_TACKLE, EVENT_TYPE_CHALLENGE]: qualifiers.extend( [ - DuelQualifier(value=DuelType.LOOSE_BALL), - DuelQualifier(value=DuelType.AERIAL), + DuelQualifier(value=DuelType.GROUND), + DuelQualifier(value=DuelType.TACKLE), ] ) + elif type_id == EVENT_TYPE_AERIAL: + qualifiers.append(DuelQualifier(value=DuelType.AERIAL)) elif type_id == EVENT_TYPE_50_50: qualifiers.extend( [ From 91ebd737740e5cd40e2823aa9aadfa15b3d39660 Mon Sep 17 00:00:00 2001 From: driesdeprest Date: Thu, 30 Nov 2023 15:40:23 +0100 Subject: [PATCH 2/3] Fix test now that aerial event does not have loose ball qualifier anymore --- kloppy/tests/test_opta.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/kloppy/tests/test_opta.py b/kloppy/tests/test_opta.py index 820ba4b5..d95b2339 100644 --- a/kloppy/tests/test_opta.py +++ b/kloppy/tests/test_opta.py @@ -154,10 +154,9 @@ def test_correct_deserialization(self, f7_data: str, f24_data: str): ) # 2318695229 # Check DuelQualifiers - assert ( - dataset.events[7].get_qualifier_values(DuelQualifier)[1].value - == DuelType.AERIAL - ) + assert DuelQualifier(value=DuelType.AERIAL) in dataset.events[ + 7 + ].get_qualifier_values(DuelQualifier) assert ( dataset.events[8].get_qualifier_values(DuelQualifier)[1].value == DuelType.GROUND From ed5c72e1f2e9cc2267be1a95bc2d72976914ad8d Mon Sep 17 00:00:00 2001 From: driesdeprest Date: Mon, 11 Dec 2023 18:43:47 +0100 Subject: [PATCH 3/3] Use tuple for code consistency --- kloppy/infra/serializers/event/opta/deserializer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kloppy/infra/serializers/event/opta/deserializer.py b/kloppy/infra/serializers/event/opta/deserializer.py index 81df28b3..8071168f 100644 --- a/kloppy/infra/serializers/event/opta/deserializer.py +++ b/kloppy/infra/serializers/event/opta/deserializer.py @@ -384,7 +384,7 @@ def _parse_duel( raw_qualifiers: Dict[int, str], type_id: int, outcome: int ) -> Dict: qualifiers = _get_event_qualifiers(raw_qualifiers) - if type_id in [EVENT_TYPE_TACKLE, EVENT_TYPE_CHALLENGE]: + if type_id in (EVENT_TYPE_TACKLE, EVENT_TYPE_CHALLENGE): qualifiers.extend( [ DuelQualifier(value=DuelType.GROUND),