Closed UnravelSports closed 4 months ago
Yeah I thought as much (in regards to the try except). I've changed the implementation slightly because list(match_result_path.find(f7_root))
would throw the AttributeError.
I've also looked through the code and I don't think there will be any issues with having initialized 2 Periods without the second period actually having started yet. The below part (found In Line 770 - 783 makes me believe that if a Period hasn't started yet setting a start time will be skipped and period.start_timestamp
will simply be left as None
(how it is initialized).
From simply running this script on a game that was at minute ~15 (so, incomplete / live) file, I also didn't encounter any problems with initializing a second "empty" period.
If you want I can run some more tests, but I'm not quite sure what else to check :)
if type_id == EVENT_TYPE_START_PERIOD:
logger.debug(
f"Set start of period {period.id} to {timestamp}"
)
period.start_timestamp = timestamp
elif type_id == EVENT_TYPE_END_PERIOD:
logger.debug(
f"Set end of period {period.id} to {timestamp}"
)
period.end_timestamp = timestamp
else:
if not period.start_timestamp:
# not started yet
continue
Let's try this again....
A really simple fix here. When loading opta event data (as shown below) for an incomplete f7 (read: during live matches) we get an AttributeError.
Error looks as follows:
Normally, in a completed game we'd have a Result tag that looks something like this:
But, because the game is not finished yet there simply is no "Result" tag.
Doing a simple try / except block like below resolves this issue and creates a correct Kloppy EventDataset.
Not 100% sure if using a try-except block here is the best solution, but it works.