Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undesirable / Incorrect behaviour TimeContainer #337

Open
UnravelSports opened this issue Jul 15, 2024 · 0 comments
Open

Undesirable / Incorrect behaviour TimeContainer #337

UnravelSports opened this issue Jul 15, 2024 · 0 comments
Assignees

Comments

@UnravelSports
Copy link
Contributor

UnravelSports commented Jul 15, 2024

The TimeContainer was added to store player positions, however it seems that (haven’t tested it with other data) when loading the open skillcorner data default match, I sometimes get an “empty” TimeContainer, something like this:

TimeContainer[Position]({'P1T00:00': Position(position_id=3, name='Left Center Back', coordinates=None)})
TimeContainer[Position]({'P1T00:00': Position(position_id=9, name='Left Midfield', coordinates=None)})
TimeContainer[Position]({'P1T00:00': Position(position_id=4, name='Right Center Back', coordinates=None)})
<TimeContainer>
<TimeContainer>
TimeContainer[Position]({'P1T00:00': Position(position_id=4, name='Right Center Back', coordinates=None)})
TimeContainer[Position]({'P1T00:00': Position(position_id=10, name='Right Midfield', coordinates=None)})
TimeContainer[Position]({'P1T00:00': Position(position_id=8, name='Center Midfield', coordinates=None)})

I don't think this should happen, if only because if I now try to call player.positions.at_start() it throws a KeyError because it has no self.items. Why are we raising a KeyError. It should instead be something like Position.NOT_SET (assuming this is the reason the TimeContainer is empty).

def at_start(self):
        """Return the value at the beginning of the match"""
        if not self.items:
            raise KeyError

        first_item: Time = self.items.keys()[0]

        tmp_period = first_item.period
        while tmp_period.prev_period:
            tmp_period = tmp_period.prev_period

        return self.value_at(Time.from_period(tmp_period, "start"))

Above is the code that raises the issue. Below is an MRE.

from kloppy import skillcorner

dataset = skillcorner.load_open_data(
    coordinates="secondspectrum", 
    include_empty_frames=False,
    limit=10
)

for frame in dataset:
    for pid in frame.players_data:
        print(pid.positions)
@koenvo koenvo self-assigned this Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants