data_tools.schema.Event#

class data_tools.schema.Event(start: str | datetime, stop: str | datetime, name: str = None, attributes: dict = None, flags: List[str] = None)#

Bases: object

Represents an event that took place between start and stop (accessible as datetime.datetime objects or as ISO 8601 formatted strings), with a name and optionally any additional attributes such as attributes[“realtime”] or attributes[“test”].

__init__(start: str | datetime, stop: str | datetime, name: str = None, attributes: dict = None, flags: List[str] = None)#

Create an Event from either ISO8601 strings or datetime.datetime objects. Any datetime.datetime objects or ISO8601 strings MUST contain timezone information.

Optionally, name the event with name, and with additional attributes.

Parameters:
  • start – The start time of this Event

  • stop – The end time of this Event

  • name – The name of this event, optional, defaulted to “Unnamed Event”

  • flags – A list of strings that indicate flags that are present.

  • attributes (dict) – A dictionary of any additional attributes and/or metadata for this Event

Methods

__init__(start, stop[, name, attributes, flags])

Create an Event from either ISO8601 strings or datetime.datetime objects.

from_dict(data_dict)

Obtain an event from a dictionary.

to_dict()

Compile this Event to its dictionary representation.

Attributes

attributes

Obtain a dictionary of additional metadata or relevant attributes for this Event.

flags

Obtain the flags of this event as a list.

name

The name of the event, if this event is named, or "Unnamed Event" if not.

start

Obtain the end time of this Event as a datetime.datetime object.

start_as_iso_str

45.12Z

stop

Obtain the end time of this Event as a datetime.datetime object.

stop_as_iso_str

45.12Z

property attributes: dict#

Obtain a dictionary of additional metadata or relevant attributes for this Event.

property flags: List[str]#

Obtain the flags of this event as a list. May be empty.

static from_dict(data_dict: dict)#

Obtain an event from a dictionary. Dictionary must contain a key “start” containing an ISO8601 string or datetime.datetime object, a key “stop” containing an ISO8601 string or datetime.datetime object, and optionally a name.

datetime.datetime objects and ISO8601 strings MUST contain timezone information.

Parameters:

data_dict – valid dictionary containing data

Returns:

an Event hydrated with the provided data

property name: str#

The name of the event, if this event is named, or “Unnamed Event” if not.

property start: datetime#

Obtain the end time of this Event as a datetime.datetime object.

property start_as_iso_str: str#

45.12Z

Type:

Return the start time of this Event as an ISO8601 string, such as 2024-11-07T15

Type:

30

property stop: datetime#

Obtain the end time of this Event as a datetime.datetime object.

property stop_as_iso_str: str#

45.12Z

Type:

Return the stop time of this Event as an ISO8601 string, such as 2024-11-07T15

Type:

30

to_dict() dict#

Compile this Event to its dictionary representation.

Returns:

the representation of this Event as a dictionary