Event#

class osekit.core_api.event.Event(begin: Timestamp, end: Timestamp)#

Events are bounded between begin an end attributes.

Classes that have a begin and an end should inherit from Event.

property duration: Timedelta#

Return the total duration of the data in seconds.

classmethod fill_gaps(events: list[TEvent], filling_class: type[TEvent], **kwargs: any) list[TEvent]#

Return a list with empty events added in the gaps between items.

The created empty events are instantiated from the class filling_class.

Parameters#

events: list[TEvent]

List of events to fill.

filling_class: type[TEvent]

The class used for instantiating empty events in the gaps.

kwargs: any

Additional parameters to pass to the filling instance constructor.

Returns#

list[TEvent]:

List of events with no gaps.

Examples#

>>> from pandas import Timestamp
>>> events = [Event(begin = Timestamp("00:00:00"), end = Timestamp("00:00:10")), Event(begin = Timestamp("00:00:15"), end = Timestamp("00:00:25"))]
>>> events = Event.fill_gaps(events, Event)
>>> [(event.begin.second, event.end.second) for event in events]
[(0, 10), (10, 15), (15, 25)]
get_overlapping_events(events: list[TEvent]) list[TEvent]#

Return a list of events that overlap with the current event.

The events input list must be sorted by begin and end Timestamps.

Parameters#

events: list[TEvent]

The list of events to be filtered by overlap. It must be sorted by begin and end Timestamps.

Returns#

list[TEvent]:

The events from the events input list that overlap with the current event.

overlaps(other: type[Event] | Event) bool#

Return True if the other event shares time with the current event.

Parameters#

other: type[Event] | Event

The other event.

Returns#

bool:

True if the two events are overlapping, False otherwise.

Examples#

>>> from pandas import Timestamp
>>> Event(begin=Timestamp("2024-01-01 00:00:00"),end=Timestamp("2024-01-02 00:00:00")).overlaps(Event(begin=Timestamp("2024-01-01 12:00:00"),end=Timestamp("2024-01-02 12:00:00")))
True
>>> Event(begin=Timestamp("2024-01-01 00:00:00"),end=Timestamp("2024-01-02 00:00:00")).overlaps(Event(begin=Timestamp("2024-01-02 00:00:00"),end=Timestamp("2024-01-02 12:00:00")))
False
classmethod remove_overlaps(events: list[TEvent]) list[TEvent]#

Resolve overlaps between events.

If two events overlap within the whole events collection (that is if one event begins before the end of another event), the earliest event’s end is set to the begin of the latest object. If multiple events overlap with one earlier event, only one is chosen as next. The chosen next event is the one that ends the latest.

Parameters#

events: list

List of events in which to remove the overlaps.

Returns#

list:

The list of events with no overlap.

Examples#

>>> from pandas import Timestamp
>>> events = [Event(begin=Timestamp("00:00:00"),end=Timestamp("00:00:15")), Event(begin=Timestamp("00:00:10"),end=Timestamp("00:00:20"))]
>>> events[0].end == events[1].begin
False
>>> events = Event.remove_overlaps(events)
>>> events[0].end == events[1].begin
True