PySport / kloppy

kloppy: standardizing soccer tracking- and event data
https://kloppy.pysport.org
BSD 3-Clause "New" or "Revised" License
328 stars 55 forks source link

[Wyscout v2] Bug in deserializing Offensive Duel events which are also an interception #268

Open probberechts opened 6 months ago

probberechts commented 6 months ago

When a duel is also an interception, the Wyscout v2 deserializer deletes the last event before the interception.

https://github.com/PySport/kloppy/blob/0de22851512001a198e4a827dd3285be579ce3f7/kloppy/infra/serializers/event/wyscout/deserializer_v2.py#L626-L629

I guess the reasoning is that a defensive duel is always paired with an offensive duel and this would delete the offensive duel. However, it seems that the "interception" tag (1401) can also be given to the offensive duel. In that case, the wrong event will be deleted. For example, in the sequence of events below, the current implementation would delete the pass event.

{
            "eventId": 8,
            "subEventName": "Simple pass",
            "tags": [
                {
                    "id": 1802
                }
            ],
            "playerId": 36,
            "positions": [
                {
                    "y": 74,
                    "x": 30
                },
                {
                    "y": 64,
                    "x": 30
                }
            ],
            "matchId": 2058007,
            "eventName": "Pass",
            "teamId": 5629,
            "matchPeriod": "2H",
            "eventSec": 1787.213756,
            "subEventId": 85,
            "id": 261447235
        },
        {
            "eventId": 1,
            "subEventName": "Ground attacking duel",
            "tags": [
                {
                    "id": 1401
                },
                {
                    "id": 501
                },
                {
                    "id": 703
                },
                {
                    "id": 1801
                }
            ],
            "playerId": 14816,
            "positions": [
                {
                    "y": 36,
                    "x": 70
                },
                {
                    "y": 42,
                    "x": 74
                }
            ],
            "matchId": 2058007,
            "eventName": "Duel",
            "teamId": 12913,
            "matchPeriod": "2H",
            "eventSec": 1789.1453259999998,
            "subEventId": 11,
            "id": 261446954
        },
        {
            "eventId": 1,
            "subEventName": "Ground defending duel",
            "tags": [
                {
                    "id": 502
                },
                {
                    "id": 701
                },
                {
                    "id": 1802
                }
            ],
            "playerId": 70123,
            "positions": [
                {
                    "y": 64,
                    "x": 30
                },
                {
                    "y": 58,
                    "x": 26
                }
            ],
            "matchId": 2058007,
            "eventName": "Duel",
            "teamId": 5629,
            "matchPeriod": "2H",
            "eventSec": 1789.5934159999997,
            "subEventId": 12,
            "id": 261447236
        }

You can see the corresponding video here: https://youtu.be/GrkiZjoyugA?t=4813. It's the ball touch by Alderweireld.

So, I think we should update the logic here to make sure the correct event gets deleted. Furthermore, I wonder whether it wouldn't be better to convert an Offensive Duel + interception to a Ball receipt (under pressure).