ts_shape.events.production.order_traceability
Value-based traceability across stations.
Given multiple station UUIDs that each carry a string signal (any shared identifier — serial number, order number, batch ID, lot number, etc.), build an end-to-end timeline showing when each identifier was at each station, with durations and total lead times.
Typical use case: every machine on a production line writes the current identifier to its own UUID. This module joins those signals to answer "when was identifier X at station A, then B, then C?"
| Name | Description |
|---|---|
ValueTraceabilityEvents | Trace a shared identifier across multiple stations. |
ValueTraceabilityEvents
ValueTraceabilityEvents(
dataframe: pd.DataFrame,
station_uuids: dict[str, str],
*,
event_uuid: str = "prod:value_trace",
value_column: str = "value_string",
time_column: str = "systime",
exclude: Exclude = None
) -> None
Bases: Base
Trace a shared identifier across multiple stations.
Each station has its own UUID that carries a string value (the identifier currently being processed — serial number, order ID, batch code, etc.). This module detects when a given identifier appears at each station and builds a timeline.
Example usage
trace = ValueTraceabilityEvents( df, station_uuids={ 'station_a_uuid': 'Station A', 'station_b_uuid': 'Station B', 'station_c_uuid': 'Station C', }, )
Full timeline of every identifier across all stations
timeline = trace.build_timeline()
Lead time from first to last station
lead = trace.lead_time()
Where is each identifier right now?
status = trace.current_status()
Station dwell-time statistics
dwell = trace.station_dwell_statistics()
| Name | Description |
|---|---|
build_timeline | Build a full timeline of every identifier at every station. |
lead_time | Compute end-to-end lead time per identifier. |
current_status | Determine the last-known station for each identifier. |
station_dwell_statistics | Compute dwell-time statistics per station (across all identifiers). |
to_intervals | The timeline as an object interval table (one row per visit). |
| Name | Type | Description | Default |
|---|---|---|---|
dataframe | DataFrame | Input DataFrame with timeseries data. | required |
station_uuids | dict[str, str] | Mapping of UUID -> human-readable station name. e.g. {'uuid_abc': 'Station A', 'uuid_def': 'Station B'} | required |
event_uuid | str | UUID to tag derived events with. | 'prod:value_trace' |
value_column | str | Column holding the identifier string value. | 'value_string' |
time_column | str | Name of timestamp column. | 'systime' |
exclude | Exclude | Readings that are not identifiers, read like :attr:ts_shape.eventlog.ObjectSpec.exclude: "misreads" (:func:ts_shape.utils.id_codes.is_misread: NOREAD, #N/A, 0, 65535, blanks, ...), a collection of values, or a callable returning a boolean mask over a station's readings in time order. Between two readings of the same identifier an excluded reading is a gap (the identifier is held across it); anywhere else it is an empty reading. None (default) keeps every reading; "misreads" is planned to become the default in the next major release. | None |
build_timeline
build_timeline(
*,
infer_dwell_from_next: bool = False,
interval_end: IntervalEnd = "last_sample"
) -> pd.DataFrame
Build a full timeline of every identifier at every station.
| Name | Type | Description | Default |
|---|---|---|---|
infer_dwell_from_next | bool | When False (default), an interval's end is the last sample of the identifier at that station, so a station that logs the identifier only once on arrival (the common event/change-encoded case) reports a dwell of 0. When True, each visit's end is set to the same identifier's next station arrival, so the dwell is the honest arrival-here → arrival-at-next-station time. The last visit per identifier stays open (keeps its own last sample). | False |
interval_end | IntervalEnd | Where a visit ends on its station signal. "last_sample" (default): at the identifier's last sample there. "next_change": at the station's next different reading (the next identifier, or an empty / missing one), so the identifier is held until it changes, like :func:ts_shape.eventlog.object_intervals; a station's last visit is held until the last timestamp of the station signals. infer_dwell_from_next is applied afterwards. | 'last_sample' |
| Type | Description |
|---|---|
DataFrame | DataFrame with columns: |
DataFrame | - identifier: The shared identifier string. |
DataFrame | - station_uuid: UUID of the station signal. |
DataFrame | - station_name: Human-readable station name. |
DataFrame | - start: Timestamp when the identifier appeared at the station. |
DataFrame | - end: Timestamp of the last sample at the station (see interval_end). |
DataFrame | - duration_seconds: Time spent at the station. |
DataFrame | - sample_count: Number of data points. |
DataFrame | - station_sequence: Order of visit (1-based) per identifier. |
DataFrame | - uuid: Event UUID. |
DataFrame | - source_uuid: UUID of the station signal (same as station_uuid). |
lead_time
lead_time() -> pd.DataFrame
Compute end-to-end lead time per identifier.
| Type | Description |
|---|---|
DataFrame | DataFrame with columns: |
DataFrame | - identifier |
DataFrame | - first_station: Name of first station visited. |
DataFrame | - last_station: Name of last station visited. |
DataFrame | - first_seen: Earliest timestamp across all stations. |
DataFrame | - last_seen: Latest timestamp across all stations (the latest visit end, also when visits overlap). |
DataFrame | - lead_time_seconds: Total time from first seen to last seen. |
DataFrame | - stations_visited: Number of distinct stations visited. |
DataFrame | - station_path: Arrow-separated ordered station names. |
DataFrame | - uuid: Event UUID. |
DataFrame | - start: Same as first_seen. |
DataFrame | - end: Same as last_seen. |
DataFrame | - duration_seconds: Same as lead_time_seconds (float seconds). |
DataFrame | - source_uuid: Comma-joined station UUIDs in visit order (each listed once). |
current_status
current_status(
*,
infer_dwell_from_next: bool = False,
interval_end: IntervalEnd = "last_sample"
) -> pd.DataFrame
Determine the last-known station for each identifier.
| Name | Type | Description | Default |
|---|---|---|---|
infer_dwell_from_next | bool | Forwarded to :meth:build_timeline. Note the current (last) station's dwell is still open, so this mainly affects identifiers whose latest visit has a later arrival. | False |
interval_end | IntervalEnd | Forwarded to :meth:build_timeline. | 'last_sample' |
| Type | Description |
|---|---|
DataFrame | DataFrame with columns: |
DataFrame | - identifier |
DataFrame | - current_station: Name of the last station where seen. |
DataFrame | - current_station_uuid: UUID of that station. |
DataFrame | - arrived_at: When the identifier arrived at the current station. |
DataFrame | - time_at_station_seconds: Dwell time at the current station so far. |
DataFrame | - uuid: Event UUID. |
station_dwell_statistics
station_dwell_statistics(
*,
infer_dwell_from_next: bool = False,
interval_end: IntervalEnd = "last_sample"
) -> pd.DataFrame
Compute dwell-time statistics per station (across all identifiers).
| Name | Type | Description | Default |
|---|---|---|---|
infer_dwell_from_next | bool | Forwarded to :meth:build_timeline. Pass True when stations log an identifier once on arrival, so dwell is measured arrival-here → arrival-at-next-station instead of collapsing to zero. | False |
interval_end | IntervalEnd | Forwarded to :meth:build_timeline; "next_change" measures dwell to the station's next reading. | 'last_sample' |
| Type | Description |
|---|---|
DataFrame | DataFrame with columns: |
DataFrame | - station_name |
DataFrame | - station_uuid |
DataFrame | - identifier_count: Number of distinct identifiers seen. |
DataFrame | - min_dwell_seconds |
DataFrame | - avg_dwell_seconds |
DataFrame | - max_dwell_seconds |
DataFrame | - total_dwell_seconds |
to_intervals
to_intervals(
*, object_type: str = "serial", interval_end: IntervalEnd = "last_sample"
) -> pd.DataFrame
The timeline as an object interval table (one row per visit).
The result has the columns of
:func:ts_shape.eventlog.object_intervals plus station, so it
feeds :func:~ts_shape.eventlog.presence_events,
:func:~ts_shape.eventlog.object_kpis,
:func:~ts_shape.eventlog.wip_over_time,
:func:~ts_shape.eventlog.attach_counts,
:func:~ts_shape.eventlog.relate and
:func:~ts_shape.eventlog.link_events_to_objects directly.
| Name | Type | Description | Default |
|---|---|---|---|
object_type | str | Object type of the identifiers ("serial", "work_order", "batch", ...). | 'serial' |
interval_end | IntervalEnd | Forwarded to :meth:build_timeline. "next_change" gives the presences :func:~ts_shape.eventlog.object_intervals gives for the station signals (every non-empty value an id). | 'last_sample' |
| Type | Description |
|---|---|
DataFrame | DataFrame with columns: |
DataFrame | - oid: The identifier (text; 12.0 renders as "12"). |
DataFrame | - type: object_type. |
DataFrame | - start / end: The visit, in UTC (naive input is read as UTC). |
DataFrame | - duration_seconds |
DataFrame | - uuid: The station signal. |
DataFrame | - source_uuid: The station signal. |
DataFrame | - station: The station name; the analysis functions use it as the station (to :func:~ts_shape.eventlog.relate it is an object attribute, recorded at each visit). |
DataFrame | Ordered by identifier, then start. No visit gives an empty frame |
DataFrame | with these columns. |