ts_shape.eventlog.analysis
Object analytics: lead time, dwell, WIP, carrier loops and counts per object.
The object layer (:mod:ts_shape.eventlog.objects) says when each serial,
carrier or batch was present where. This module turns those presences into
the numbers a line is run by:
- :func:
presence_events-- oneenterand oneleavepoint event per presence. Through :func:~ts_shape.eventlog.to_event_log(detector"eventlog.presence_events") every event links to its object, so a serial-centric XES log has real traces: enter station A, leave A, enter B. - :func:
object_kpis-- per object lead time, presence count and dwell, dwell per station, and (withwindow=) throughput per window. - :func:
wip_over_time-- time-weighted average and maximum work in process per window. - :func:
carrier_loops-- loop count and loop times of circulating carriers. - :func:
attach_counts-- parts (or scrap) per object from a counter signal.
Input
Every function takes the interval table of
:func:~ts_shape.eventlog.object_intervals (columns oid, type,
start, end; uuid / source_uuid when present) or an
:class:~ts_shape.eventlog.EventLog:
- a log built from :func:
presence_events(to_event_log(..., detector="eventlog.presence_events"), alone or concatenated with other logs): the presences are rebuilt from its enter / leave events, stations included; - else the
lifecyclerows ofobject_changes(the :func:~ts_shape.eventlog.detect_objectslog): one presence peractiveuntil the next lifecycle change. Those presences have no station (<NA>).
Rows without an oid, type, start or end are skipped; a
presence that ends before it starts raises ValueError.
Stations
The station of a presence is where the object is: the presence's
source_uuid, or its id signal uuid when it has none (one reader per
station). Presences are half-open [start, end), as everywhere in the
object layer.
Time zones
Times keep the zone of the input (tz-aware stays in its zone, naive stays
naive). tz= converts them first (naive times are read as UTC, like the
rest of the event log); windows are laid out in that zone, so a daily window
on a DST day lasts 23 or 25 hours. The interval table of
:func:~ts_shape.eventlog.object_intervals is in UTC: pass tz= for
local days and shifts.
| Name | Description |
|---|---|
ObjectKPIs | Result of :func:object_kpis. |
CarrierLoops | Result of :func:carrier_loops. |
| Name | Description |
|---|---|
presence_events | One enter and one leave point event per object presence. |
object_kpis | Lead time, presence count and dwell per object, dwell per station. |
wip_over_time | Time-weighted average and maximum work in process (WIP) per window. |
carrier_loops | Loop count and loop times of carriers circulating on a line. |
attach_counts | Quantity of a counter (parts, scrap) produced per object. |
ObjectKPIs
ObjectKPIs(
objects: pd.DataFrame,
stations: pd.DataFrame,
throughput: pd.DataFrame | None = None,
) -> None
Result of :func:object_kpis.
| Name | Type | Description |
|---|---|---|
objects | DataFrame | One row per object: oid, type, start (first enter), end (last leave), lead_time_seconds, presence_count, station_count (known stations), dwell_seconds (the sum of its presence durations; presences at two stations at once both count, so it can exceed the lead time). |
stations | DataFrame | One row per object and station, in order of arrival: oid, type, station, start, end, presence_count, dwell_seconds. |
throughput | DataFrame | None | With window=, one row per window: start, end, duration_seconds, completed_count (objects whose last leave falls in the window) and mean_lead_time_seconds of those (NaN when none). None without window. |
CarrierLoops
CarrierLoops(loops: pd.DataFrame, carriers: pd.DataFrame) -> None
Result of :func:carrier_loops.
| Name | Type | Description |
|---|---|---|
loops | DataFrame | One row per loop: oid, type, station (the start station), loop_index (0-based per carrier), start (an arrival at the start station), end (the next arrival there) and duration_seconds (the loop time). |
carriers | DataFrame | One row per carrier: oid, type, station, loop_count and mean_loop_seconds (NaN without a loop). |
presence_events
presence_events(
intervals: ObjectData, *, object_type: str | None = None
) -> pd.DataFrame
One enter and one leave point event per object presence.
Turn them into an event log with to_event_log(frame, detector="eventlog.presence_events"): the activity is
production.presence.<event>.<station> and every event links to its
object (oid of type type) and to the source_uuid asset, so
to_event_log_xes(log, case_object_type="serial") gives one trace per
serial: enter station A, leave A, enter B, leave B.
| Name | Type | Description | Default |
|---|---|---|---|
intervals | ObjectData | :func:~ts_shape.eventlog.object_intervals output or an event log (see the module docstring). | required |
object_type | str | None | Keep only this object type; None keeps every type. | None |
| Type | Description |
|---|---|
DataFrame | DataFrame with systime, oid, type, event |
DataFrame | ("enter" at the presence start, "leave" at its end), |
DataFrame | station (source_uuid, else the id signal uuid), |
DataFrame | presence_index (0-based per object, in order of entry), uuid |
DataFrame | and source_uuid. Sorted by time; at one instant the events of an |
DataFrame | object follow its presences (leave A before enter B at a hand-over). |
DataFrame | Times keep the input's zone. An empty input gives an empty frame |
DataFrame | with these columns. |
object_kpis
object_kpis(
intervals: ObjectData,
*,
object_type: str,
window: Any = None,
tz: Any = None
) -> ObjectKPIs
Lead time, presence count and dwell per object, dwell per station.
The lead time of an object runs from its first enter to its last leave. An object still present at the end of the data ends there (its last presence ends at the last observation).
| Name | Type | Description | Default |
|---|---|---|---|
intervals | ObjectData | :func:~ts_shape.eventlog.object_intervals output or an event log (see the module docstring). | required |
object_type | str | The object type to report ("serial"). | required |
window | Any | Optional window ("1h", "1D", "W", ...) for the throughput table: objects completing (last leave) per window. The windows cover the data from the first enter to the last leave, windows without completions included. | None |
tz | Any | Time zone to convert the times to and lay the windows out in; None keeps the input's. | None |
| Type | Description |
|---|---|
ObjectKPIs | class:ObjectKPIs with objects, stations and |
ObjectKPIs | throughput (None without window). Empty input gives |
ObjectKPIs | empty tables with the documented columns. |
wip_over_time
wip_over_time(
intervals: ObjectData, *, object_type: str, window: Any, tz: Any = None
) -> pd.DataFrame
Time-weighted average and maximum work in process (WIP) per window.
WIP at an instant is the number of objects of object_type present
anywhere: an object counts once while at two stations at once, and not
twice at a hand-over (presences are half-open). Presences are split at
the window bounds (:func:~ts_shape.utils.time_accounting.split_intervals)
and the windows come from
:func:~ts_shape.utils.time_accounting.grouper_periods, so a daily
window on a DST day lasts 23 or 25 hours.
| Name | Type | Description | Default |
|---|---|---|---|
intervals | ObjectData | :func:~ts_shape.eventlog.object_intervals output or an event log (see the module docstring). | required |
object_type | str | The object type to count ("serial"). | required |
window | Any | Window ("1h", "8h", "1D", "W", ...). | required |
tz | Any | Time zone to lay the windows out in; None keeps the input's. | None |
| Type | Description |
|---|---|
DataFrame | One row per window from the first enter to the last leave, with |
DataFrame | start, end, duration_seconds, object_seconds (object |
DataFrame | presence time in the window), wip_mean (``object_seconds / |
DataFrame | duration_seconds, averaged over the whole window) and wip_max`` |
DataFrame | (the most objects present at once in the window). Empty input gives |
DataFrame | an empty frame with these columns. |
carrier_loops
carrier_loops(
intervals: ObjectData,
*,
object_type: str = "carrier",
start_station: str | None = None
) -> CarrierLoops
Loop count and loop times of carriers circulating on a line.
A loop is the time between two successive arrivals of a carrier at the loop's start station; every presence there is an arrival.
| Name | Type | Description | Default |
|---|---|---|---|
intervals | ObjectData | :func:~ts_shape.eventlog.object_intervals output or an event log (see the module docstring). | required |
object_type | str | The carrier object type. | 'carrier' |
start_station | str | None | Station the loops start at (a source_uuid, or the id signal uuid of a reader without one). None: each carrier's first station, the one it is first seen at. | None |
| Type | Description |
|---|---|
CarrierLoops | class:CarrierLoops with loops (one row per loop) and |
CarrierLoops | carriers (one row per carrier, including carriers without a full |
CarrierLoops | loop). Empty input gives empty tables with the documented columns. |
attach_counts
attach_counts(
intervals: ObjectData,
dataframe: pd.DataFrame,
counter_uuid: str,
*,
object_type: str,
value_column: str = "value_integer",
station: str | None = None,
uuid_column: str = "uuid",
time_column: str = "systime"
) -> pd.DataFrame
Quantity of a counter (parts, scrap) produced per object.
The increment a counter reports at reading t_i was produced during
(t_{i-1}, t_i]. It is shared between the objects present at the
counter's station in that time, in proportion to the time each was
present (constant production rate between two readings). When several
objects are present at once, the shares are scaled down so that they
never add up to more than the increment. The part of an increment
produced while no object was present is reported as unattributed.
Counter resets follow :func:~ts_shape.utils.counters.counter_increments:
a reading lower than the one before is a reset, and its value is the
production since the reset. The first reading is the baseline (no
production); missing or non-numeric readings are skipped. Readings at
the same time are summed.
| Name | Type | Description | Default |
|---|---|---|---|
intervals | ObjectData | :func:~ts_shape.eventlog.object_intervals output or an event log (see the module docstring). | required |
dataframe | DataFrame | Long-format frame holding the counter signal. | required |
counter_uuid | str | uuid of the counter signal. | required |
object_type | str | Object type the counts are attributed to. | required |
value_column | str | Column of the counter readings. | 'value_integer' |
station | str | None | Station whose objects receive the counts. None: the counter's source_uuid; a counter without one counts for the objects present at any station. | None |
uuid_column | str | Signal identifier column of dataframe. | 'uuid' |
time_column | str | Timestamp column of dataframe. | 'systime' |
| Name | Type | Description |
|---|---|---|
DataFrame | One row per object present at the station, in order of first | |
presence | DataFrame | oid, type, quantity (float; 0 for an object |
DataFrame | present while nothing was produced). A last row with oid | |
DataFrame | holds the unattributed quantity, when there is any. The quantities | |
DataFrame | add up to the counter's total. Empty inputs give an empty frame with | |
DataFrame | these columns. |
| Type | Description |
|---|---|
ColumnNotFoundError | When dataframe lacks a named column. |
ValueError | When station is None and the counter has several source_uuid values. |