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

[Wyscout V3] Add substitutions to the event stream #368

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

DriesDeprest
Copy link
Contributor

Discussed in: #367

@DriesDeprest
Copy link
Contributor Author

@probberechts does this look like a clean implementation?

Comment on lines 712 to 741
# Step 2: Sort substitution events globally by period and timestamp
substitution_events.sort(key=lambda e: (e.period.id, e.timestamp))

# Step 3: Merge events and substitutions in ascending order
merged_events = []
sub_index = 0
total_subs = len(substitution_events)

for event in events:
# Insert all substitution events that occur before or at the current event's timestamp
while sub_index < total_subs:
sub_event = substitution_events[sub_index]
if sub_event.period.id < event.period.id or (
sub_event.period.id == event.period.id
and sub_event.timestamp <= event.timestamp
):
merged_events.append(sub_event)
sub_index += 1
else:
break

# Add the current event to the merged list
merged_events.append(event)

# Step 4: Add any remaining substitution events
while sub_index < total_subs:
merged_events.append(substitution_events[sub_index])
sub_index += 1

return merged_events
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be write much simpler using

import bisect

def insert(event, sorted_events):
    pos = bisect.bisect_left([e.time for e in sorted_events], event.time)
    events.insert(pos, event)
    
for sub_event in substitution_events:
     insert(sub_event, events)

I am also not entirely sure whether sorting only on time is sufficient. I suppose it can happen that a regular event (e.g., a ball out or throw-in) and a substitution happen in the same second. In that case, the substitution should become before events that restart the game and after events that stop the game.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the help. I've refactored the code to use your more simple design.

In the test file that we use, I did not find any regular events that occur in the same second as the substitutions. But I'm indeed not sure, whether this will be generally true.

Do you think we should already start with merging this implementation of adding substitution events for the Wyscout V3 parser, and later in a separate issue/PR work on better handling the edge case of when a substitution event and a regular event happen on the same second?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@probberechts do you think we can already merge this PR? And in a separate issue/PR work on better handling the edge case of when a substitution event and a regular event happen on the same second (if this even ever occurs)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@probberechts what do you think? :-)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Successfully merging this pull request may close these issues.

2 participants