Skip to main content
Version: Next

ts_shape.eventlog.model

The :class:EventLog dataclass — the OCEL 2.0 relational tables.

Classes
NameDescription
EventLogCanonical ts-shape event log in OCEL 2.0 shape.

EventLog​

classsource
EventLog(
events: pd.DataFrame = schema.empty_events(),
objects: pd.DataFrame = schema.empty_objects(),
relations: pd.DataFrame = schema.empty_relations(),
o2o: pd.DataFrame = schema.empty_o2o(),
object_changes: pd.DataFrame = schema.empty_object_changes(),
) -> None

Canonical ts-shape event log in OCEL 2.0 shape.

Five relational tables, mirroring the OCEL 2.0 standard:

  • events — one row per detected event (+ event attributes),
  • objects — the objects events refer to (ocel:oid / ocel:type),
  • relations — event-to-object (E2O) relations with qualifiers,
  • o2o — object-to-object relations with qualifiers,
  • object_changes — time-varying object attribute values.

objects / relations are empty when the source detector has no natural object association (e.g. a global cross-signal correlation statistic); o2o / object_changes are empty unless supplied. Use :attr:has_objects to check before calling :func:to_event_log_xes.

Example

Built by :func:~ts_shape.to_event_log from a detector's output:

>>> import ts_shape
>>> df = ts_shape.make_timeseries(["temp"], n_outliers=3)
>>> out = ts_shape.OutlierDetectionEvents(df, "value_double").detect_outliers_zscore()
>>> log = ts_shape.to_event_log(
... out, detector="OutlierDetectionEvents.detect_outliers_zscore")
>>> len(log.events), log.has_objects
(4, True)
>>> log.events[["ocel:activity", "ocel:timestamp"]].head(2)
ocel:activity ocel:timestamp
0 quality.outlier.zscore 2025-01-01 01:34:30+00:00
1 quality.outlier.zscore 2025-01-01 03:21:00+00:00
Functions
NameDescription
filter_by_packReturn a sub-log containing only the events emitted by one pack.
filter_by_objectReturn a sub-log containing only the events related to one object.
filter_by_object_typeReturn a sub-log containing only the objects of some types.
filter_by_timeReturn a sub-log of the half-open time window [start, end).
where_usedEverything oid went into; see :func:~ts_shape.eventlog.where_used.
where_fromEverything oid came from; see :func:~ts_shape.eventlog.where_from.
lineageBoth directions with a signed depth; see :func:~ts_shape.eventlog.lineage.

has_objects​

propertysource
has_objects: bool

Whether the log contains at least one object in objects.

filter_by_pack​

methodsource
filter_by_pack(pack: str) -> EventLog

Return a sub-log containing only the events emitted by one pack.

Objects, relations, object-to-object links, and object changes are restricted to those referenced by the kept events.

Parameters
NameTypeDescriptionDefault
packstrPack name to match against the ts_shape:pack column.required
Returns
TypeDescription
EventLogA new EventLog restricted to the matching events.

filter_by_object​

methodsource
filter_by_object(oid: str, type_: str | None = None) -> EventLog

Return a sub-log containing only the events related to one object.

Events are selected through the event-to-object relations table; the other tables are restricted to the objects those events use.

Parameters
NameTypeDescriptionDefault
oidstrObject identifier (ocel:oid) to match.required
type_str | NoneOptional object type (ocel:type) to match as well.None
Returns
TypeDescription
EventLogA new EventLog restricted to the events related to the object.

filter_by_object_type​

methodsource
filter_by_object_type(
types: str | Iterable[str],
*,
keep_events: Literal["linked", "all"] = "linked"
) -> EventLog

Return a sub-log containing only the objects of some types.

objects keeps every object of types (also one no event links to); relations, o2o (both ends) and object_changes are restricted to those objects, so no table references a dropped one.

Parameters
NameTypeDescriptionDefault
typesstr | Iterable[str]Object type(s) (ocel:type) to keep.required
keep_eventsLiteral['linked', 'all']"linked" keeps the events related to at least one kept object; "all" keeps every event (their relations to other objects are dropped).'linked'
Returns
TypeDescription
EventLogA new EventLog restricted to the objects of types.
Raises
TypeDescription
ValueErrorFor an unknown keep_events.

filter_by_time​

methodsource
filter_by_time(start: object = None, end: object = None) -> EventLog

Return a sub-log of the half-open time window start, end).

  • events: those whose ocel:timestamp is in the window.
  • objects: those present in the window (a lifecycle active -> released span of object_changes overlaps it), those without lifecycle rows (presence unknown), and every object a kept event relates to.
  • relations of the kept events; o2o with both ends kept.
  • object_changes of the kept objects inside the window, plus each field's last value before start (the state at the window start).
Parameters
NameTypeDescriptionDefault
start[objectWindow start (inclusive); None: unbounded. Naive times are UTC.None
endobjectWindow end (exclusive); None: unbounded.None
Returns
TypeDescription
EventLogA new EventLog restricted to the window.
Raises
TypeDescription
ValueErrorWhen start is not before end.

where_used​

methodsource
where_used(
oid: str,
*,
depth: int | None = None,
start: object = None,
end: object = None,
qualifiers: str | Iterable[str] | None = None
) -> pd.DataFrame

Everything oid went into; see :func:~ts_shape.eventlog.where_used.

Parameters
NameTypeDescriptionDefault
oidstrThe object to start from.required
depthint | NoneMaximum number of steps; None: no limit.None
startobjectWindow start (inclusive).None
endobjectWindow end (exclusive).None
qualifiersstr | Iterable[str] | NoneThe o2o qualifiers to follow (default: all but co_occurs).None
Returns
TypeDescription
DataFrameoid, object_type, qualifier, depth, via (+ extra
DataFrameo2o columns).

where_from​

methodsource
where_from(
oid: str,
*,
depth: int | None = None,
start: object = None,
end: object = None,
qualifiers: str | Iterable[str] | None = None
) -> pd.DataFrame

Everything oid came from; see :func:~ts_shape.eventlog.where_from.

Parameters
NameTypeDescriptionDefault
oidstrThe object to start from.required
depthint | NoneMaximum number of steps; None: no limit.None
startobjectWindow start (inclusive).None
endobjectWindow end (exclusive).None
qualifiersstr | Iterable[str] | NoneThe o2o qualifiers to follow (default: all but co_occurs).None
Returns
TypeDescription
DataFrameoid, object_type, qualifier, depth, via (+ extra
DataFrameo2o columns).

lineage​

methodsource
lineage(
oid: str,
*,
depth: int | None = None,
start: object = None,
end: object = None,
qualifiers: str | Iterable[str] | None = None
) -> pd.DataFrame

Both directions with a signed depth; see :func:~ts_shape.eventlog.lineage.

Parameters
NameTypeDescriptionDefault
oidstrThe object to start from.required
depthint | NoneMaximum number of steps per direction; None: no limit.None
startobjectWindow start (inclusive).None
endobjectWindow end (exclusive).None
qualifiersstr | Iterable[str] | NoneThe o2o qualifiers to follow (default: all but co_occurs).None
Returns
NameTypeDescription
TheDataFramemeth:where_from rows at negative depth, oid at 0,
theDataFramemeth:where_used rows at positive depth.