Genealogy (traceability) queries and coherent sub-logs of an :class:EventLog.
The object-to-object table o2o holds directed edges ocel:oid -> ocel:oid_2; ts-shape's part_of edges point from the child to the parent
(a serial is part_of its batch, a batch part_of its material lot).
On that graph:
- :func:
where_used follows the edges backwards, from a parent to
everything it went into: where_used(batch) returns the batch's serials,
the handling units those serials were packed into, and so on.
- :func:
where_from follows them forwards, from a child to everything
it came from: where_from(serial) returns its batch, the batch's
material, ...
- :func:
lineage returns both as one frame with a signed depth
(negative: where the object came from, positive: where it was used, 0:
the object itself).
Each traversal is a breadth-first search over an adjacency built once per
call (int codes, CSR arrays); a level is expanded with array operations, so
100k edges take milliseconds. Every object is reported at its shortest
distance from the start; cycles terminate because an object is visited once.
o2o carries no validity time in ts-shape. A start / end window
therefore restricts the walk to objects present in the window, from the
lifecycle rows of object_changes (active -> released); an
object without lifecycle rows (presence unknown, e.g. one imported from
another system) counts as present. Extra o2o columns, such as a validity
time a user-supplied table carries, are passed through on each row.
Functions
| Name | Description |
|---|
where_used | Everything an object went into: its children, their children, ... |
where_from | Everything an object came from: its parents, their parents, ... |
lineage | Both directions of an object's genealogy as one frame. |
where_used(
log: EventLog,
oid: str,
*,
depth: int | None = None,
start: object = None,
end: object = None,
qualifiers: str | Iterable[str] | None = None
) -> pd.DataFrame
Everything an object went into: its children, their children, ...
Follows o2o edges from ocel:oid_2 back to ocel:oid: for
part_of (child -> parent) where_used(batch) returns the batch's
serials, then the handling units the serials are part of, and so on.
Parameters
| Name | Type | Description | Default |
|---|
log | EventLog | The event log. | required |
oid | str | The object to start from (an ocel:oid). | required |
depth | int | None | Maximum number of steps; None follows the graph to the end. | None |
start | object | Window start (inclusive); naive times are UTC. With start / end only objects present in start, end) (lifecycle rows of object_changes) are reached; objects without lifecycle rows count as present. | None |
end | [object | Window end (exclusive). | None |
qualifiers | str | Iterable[str] | None | The o2o qualifiers to follow; None follows every qualifier except the symmetric co_occurs. | None |
Returns
| Type | Description |
|---|
DataFrame | One row per edge into a newly reached object, sorted by depth, |
DataFrame | oid, via: oid, object_type (from objects; NA when |
DataFrame | the oid is only in o2o), qualifier (of the edge), depth |
DataFrame | (steps from oid, 1 = direct), via (the object one step closer |
DataFrame | to the start), then any extra o2o columns of the edge. An object |
DataFrame | reached over two edges at its shortest depth (two parents) has two |
DataFrame | rows; the start object is not included. |
Raises
| Type | Description |
|---|
ObjectNotFoundError | When oid is neither in objects nor in o2o (a KeyError). |
ValueError | For a negative depth or an empty window. |
Example
>>> import pandas as pd
>>> from ts_shape.eventlog import EventLog, where_used
>>> o2o = pd.DataFrame({"ocel:oid": ["S1", "S2", "HU1"],
... "ocel:oid_2": ["B1", "B1", "S1"],
... "ocel:qualifier": "part_of"})
>>> where_used(EventLog(o2o=o2o), "B1")
oid object_type qualifier depth via
0 S1 <NA> part_of 1 B1
1 S2 <NA> part_of 1 B1
2 HU1 <NA> part_of 2 S1
where_from(
log: EventLog,
oid: str,
*,
depth: int | None = None,
start: object = None,
end: object = None,
qualifiers: str | Iterable[str] | None = None
) -> pd.DataFrame
Everything an object came from: its parents, their parents, ...
Follows o2o edges from ocel:oid to ocel:oid_2: for part_of
(child -> parent) where_from(serial) returns the serial's batch (and
handling unit), the batch's material, and so on.
Parameters
| Name | Type | Description | Default |
|---|
log | EventLog | The event log. | required |
oid | str | The object to start from (an ocel:oid). | required |
depth | int | None | Maximum number of steps; None follows the graph to the end. | None |
start | object | Window start (inclusive), as in :func:where_used. | None |
end | object | Window end (exclusive). | None |
qualifiers | str | Iterable[str] | None | The o2o qualifiers to follow; None follows every qualifier except the symmetric co_occurs. | None |
Returns
| Type | Description |
|---|
DataFrame | The columns of :func:where_used; via is the object one step |
DataFrame | closer to the start (the child of oid's row). |
Raises
| Type | Description |
|---|
ObjectNotFoundError | When oid is neither in objects nor in o2o (a KeyError). |
ValueError | For a negative depth or an empty window. |
lineage(
log: EventLog,
oid: str,
*,
depth: int | None = None,
start: object = None,
end: object = None,
qualifiers: str | Iterable[str] | None = None
) -> pd.DataFrame
Both directions of an object's genealogy as one frame.
Parameters
| Name | Type | Description | Default |
|---|
log | EventLog | The event log. | required |
oid | str | The object to start from (an ocel:oid). | required |
depth | int | None | Maximum number of steps in each direction; None: no limit. | None |
start | object | Window start (inclusive), as in :func:where_used. | None |
end | object | Window end (exclusive). | None |
qualifiers | str | Iterable[str] | None | The o2o qualifiers to follow; None follows every qualifier except the symmetric co_occurs. | None |
Returns
| Name | Type | Description |
|---|
DataFrame | The columns of :func:where_used with a signed depth: the | |
DataFrame | func:where_from rows with negative depth (-1 = direct parent), | |
DataFrame | a row for oid itself at 0 (qualifier and via NA), and | |
the | DataFrame | func:where_used rows with positive depth. Sorted by depth, |
DataFrame | oid, via. In a cycle an object can be both an ancestor and a | |
DataFrame | descendant and then appears on both sides. | |
Raises
| Type | Description |
|---|
ObjectNotFoundError | When oid is neither in objects nor in o2o (a KeyError). |
ValueError | For a negative depth or an empty window. |