PySport / kloppy

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

Issue: Sportec 2019 events data serializer #84

Open MKlaasman opened 3 years ago

MKlaasman commented 3 years ago

While using events data for the 2019-2020 Bundesliga Season. I ran into an error while loading in the Sportec data. This problem does not occur for 2020-2021 season's data.

Example code:

from kloppy import load_sportec_event_data
dataset = load_sportec_event_data(events_path, 
                                  matchinfo_path
                                 )

Error message:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-9-e862fa286ec2> in <module>
      3 from kloppy import SportecEventSerializer
      4 
----> 5 dataset = load_sportec_event_data(events_path, 
      6                                   matchinfo_path
      7                                  )

C:\ProgramData\Anaconda3\lib\site-packages\kloppy\helpers.py in load_sportec_event_data(event_data_filename, match_data_filename, options)
    125     ) as match_data:
    126 
--> 127         return serializer.deserialize(
    128             inputs={"event_data": event_data, "match_data": match_data},
    129             options=options,

C:\ProgramData\Anaconda3\lib\site-packages\kloppy\infra\serializers\event\sportec\serializer.py in deserialize(self, inputs, options)
    303                     )
    304                     if period_id == 1:
--> 305                         team_left = event_chain[SPORTEC_EVENT_NAME_KICKOFF][
    306                             "TeamLeft"
    307                         ]

KeyError: 'TeamLeft'
koenvo commented 3 years ago

You might have closed this by accident.

solution to this issue could be:

  1. Check if teamleft attribute is set
  2. If not, extract direction of play from first pass? First pass is always on own half, right?
schmidtfx commented 3 years ago

Anyone working on a fix?

koenvo commented 3 years ago

I didn’t start yet. And afaik no one else started

schmidtfx commented 3 years ago

You might have closed this by accident.

solution to this issue could be:

  1. Check if teamleft attribute is set
  2. If not, extract direction of play from first pass? First pass is always on own half, right?

The problem with the 2. is that there is no guarantee that the first pass is into the own half. Remember the old way of kickoffs? The first pass used to be into the opponents half. Alternatively, one could get all passes in the first half of the home team goalkeeper, calculate the mean and see in which half of the pitch they fall into.

koenvo commented 3 years ago

That sounds like a great solution @schmidtfx . Similar to https://github.com/PySport/kloppy/blob/master/kloppy/domain/services/__init__.py#L16