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

Add support for inserting events in a EventDataset #415

Open
probberechts opened this issue Jan 23, 2025 · 0 comments
Open

Add support for inserting events in a EventDataset #415

probberechts opened this issue Jan 23, 2025 · 0 comments

Comments

@probberechts
Copy link
Contributor

A recurring requirement seems to be having the ability to insert events into an existing EventDataset. Some use cases are:

To support these needs, I propose adding an insert method to the EventDataset interface.

Sometimes the correct position can be easily determined by parameters such as the index, the ID of the preceding or succeeding event. or an exact timestamp. However, when the exact position is unknown, the insert method should be able to determine the optimal insert location based on a set of constraints. For example, if the approximate time of a substitution is known, the event should be inserted within a window where the ball state is dead, closest to the given timestamp. Similarly, pressing events should be inserted into sequences where the opponent team is in possession.


Below is the API that Copilot suggests. I'm not sure whether this is exactly what we want, but I think it provides a good starting point.

class EventDataset:
    def insert(
        self, 
        event: Event, 
        position: Optional[int] = None, 
        before_event_id: Optional[str] = None, 
        after_event_id: Optional[str] = None, 
        timestamp: Optional[datetime] = None, 
        constraints: Optional[Callable[[Event, EventDataset], bool]] = None
    ) -> None:
        """
        Inserts an event into the dataset at the appropriate position.

        Parameters:
        ----------
        event : Event
            The event to be inserted into the dataset.
        
        position : Optional[int], default=None
            The exact index where the event should be inserted. If provided, 
            overrides all other positioning parameters.
        
        before_event_id : Optional[str], default=None
            The ID of the event before which the new event should be inserted. 
            Ignored if `position` is provided.

        after_event_id : Optional[str], default=None
            The ID of the event after which the new event should be inserted. 
            Ignored if `position` or `before_event_id` is provided.

        timestamp : Optional[datetime], default=None
            The timestamp of the event, used to determine its position based 
            on chronological order if no other positional parameters are specified.

        constraints : Optional[Callable[[Event, EventDataset], bool]], default=None
            A custom function that takes the event and dataset as arguments and 
            evaluates whether the event satisfies specific conditions to determine 
            its position. Useful for more complex insertion logic, such as inserting 
            into a valid contextual window (e.g., dead ball states or possession sequences).

        Returns:
        -------
        None
            The method modifies the dataset in place.

        Raises:
        ------
        ValueError
            If the insertion position cannot be determined or is invalid.
        
        Notes:
        ------
        - If multiple parameters are provided to specify the position, the precedence is:
          1. `position`
          2. `before_event_id`
          3. `after_event_id`
          4. `timestamp`
          5. `constraints`
        - If none of the above parameters are specified, the method raises a `ValueError`.
        """
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

1 participant