PySport / kloppy

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

Add current formation and opponent formation info to event, start with parser for Opta #243

Closed DriesDeprest closed 10 months ago

DriesDeprest commented 10 months ago

I want to add current formation and current opponent formation information to events. This would allow us to more easily filter out events of a team or player when they were playing in a certain formation or against a certain formation. E.g. only analyse events where Lionel Messi was playing as a LW in a 4-4-2 against a 4-3-3.

DriesDeprest commented 10 months ago

@koenvo @JanVanHaaren sorry to bother, but I'm failing to understand why I'm getting this error in the test logs below: TypeError: GenericEvent.init() missing 2 required positional arguments: 'formation' and 'opponent_formation'

Why is the error message saying 'formation' and 'opponent_formation' are required, while I label them as Optional in my class?

formation: Optional[FormationType]
opponent_formation: Optional[FormationType]
koenvo commented 10 months ago

Thanks for the PR Dries!

In this case the state builder would be a good fit. Have you seen https://kloppy.pysport.org/examples/state/#Add-state---lineup ? Would this work for your case?

DriesDeprest commented 10 months ago

I forgot about the state builder. Yes, indeed, the state builder solves my use case.

However, Wyscout doesn't have a formation change event, it rather encapsulates the formation and opponent formation in each event, see: https://github.com/PySport/kloppy/blob/master/kloppy/tests/files/wyscout_events_v3.json#L57-L127. How would you suggest that we pass the current (opponent) formation information to the events for this data provider?

Would you save the formation information of the prior event in the Wyscout deserializer and check for a difference, and if so create an "artificial" formation change event?

koenvo commented 10 months ago

The "artificial" formation change event sounds like a great solution.

DriesDeprest commented 10 months ago

Okay, will make a new PR which creates artificial formation change event for Wyscout.