Undesirable / Incorrect behaviour TimeContainer
UnravelSports opened this issue · 0 comments
UnravelSports commented
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)