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

Fix StatsBomb create_periods #313

Merged
merged 5 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 13 additions & 18 deletions kloppy/infra/serializers/event/statsbomb/deserializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,27 +216,22 @@ def create_team(lineup, ground_type):
return [home_team, away_team]

def create_periods(self, raw_events):
JanVanHaaren marked this conversation as resolved.
Show resolved Hide resolved
half_start_and_end_events = [
event.raw_event
for event in raw_events.values()
if SB.EVENT_TYPE(event.raw_event["type"])
in [
SB.EVENT_TYPE.HALF_START,
SB.EVENT_TYPE.HALF_END,
]
][
::2
] # recorded for each team, take every other
half_start_events = {}
half_end_events = {}
for event in raw_events.values():
event_type = SB.EVENT_TYPE(event.raw_event["type"])
period = event.raw_event["period"]

if event_type == SB.EVENT_TYPE.HALF_START:
half_start_events[period] = event.raw_event
elif event_type == SB.EVENT_TYPE.HALF_END:
half_end_events[period] = event.raw_event

periods = []
for start_event, end_event in zip_longest(
half_start_and_end_events[::2], half_start_and_end_events[1::2]
half_start_events.values(), half_end_events.values()
):
if (
start_event is None
or SB.EVENT_TYPE(start_event["type"])
!= SB.EVENT_TYPE.HALF_START
or SB.EVENT_TYPE(end_event["type"]) != SB.EVENT_TYPE.HALF_END
):
if start_event is None or end_event is None:
raise DeserializationError(
"Failed to determine start and end time of periods."
)
Expand Down
Loading
Loading