Skip to main content
Version: 0.0.98

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 -- one enter and one leave point 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 (with window=) 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 lifecycle rows of object_changes (the :func:~ts_shape.eventlog.detect_objects log): one presence per active until 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.

Classes
NameDescription
ObjectKPIsResult of :func:object_kpis.
CarrierLoopsResult of :func:carrier_loops.
Functions
NameDescription
presence_eventsOne enter and one leave point event per object presence.
object_kpisLead time, presence count and dwell per object, dwell per station.
wip_over_timeTime-weighted average and maximum work in process (WIP) per window.
carrier_loopsLoop count and loop times of carriers circulating on a line.
attach_countsQuantity of a counter (parts, scrap) produced per object.

ObjectKPIs​

classsource
ObjectKPIs(
objects: pd.DataFrame,
stations: pd.DataFrame,
throughput: pd.DataFrame | None = None,
) -> None

Result of :func:object_kpis.

Attributes
NameTypeDescription
objectsDataFrameOne 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).
stationsDataFrameOne row per object and station, in order of arrival: oid, type, station, start, end, presence_count, dwell_seconds.
throughputDataFrame | NoneWith 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​

classsource
CarrierLoops(loops: pd.DataFrame, carriers: pd.DataFrame) -> None

Result of :func:carrier_loops.

Attributes
NameTypeDescription
loopsDataFrameOne 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).
carriersDataFrameOne row per carrier: oid, type, station, loop_count and mean_loop_seconds (NaN without a loop).

presence_events​

functionsource
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.

Parameters
NameTypeDescriptionDefault
intervalsObjectData:func:~ts_shape.eventlog.object_intervals output or an event log (see the module docstring).required
object_typestr | NoneKeep only this object type; None keeps every type.None
Returns
TypeDescription
DataFrameDataFrame with systime, oid, type, event
DataFrame("enter" at the presence start, "leave" at its end),
DataFramestation (source_uuid, else the id signal uuid),
DataFramepresence_index (0-based per object, in order of entry), uuid
DataFrameand source_uuid. Sorted by time; at one instant the events of an
DataFrameobject follow its presences (leave A before enter B at a hand-over).
DataFrameTimes keep the input's zone. An empty input gives an empty frame
DataFramewith these columns.

object_kpis​

functionsource
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).

Parameters
NameTypeDescriptionDefault
intervalsObjectData:func:~ts_shape.eventlog.object_intervals output or an event log (see the module docstring).required
object_typestrThe object type to report ("serial").required
windowAnyOptional 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
tzAnyTime zone to convert the times to and lay the windows out in; None keeps the input's.None
Returns
TypeDescription
ObjectKPIsclass:ObjectKPIs with objects, stations and
ObjectKPIsthroughput (None without window). Empty input gives
ObjectKPIsempty tables with the documented columns.

wip_over_time​

functionsource
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.

Parameters
NameTypeDescriptionDefault
intervalsObjectData:func:~ts_shape.eventlog.object_intervals output or an event log (see the module docstring).required
object_typestrThe object type to count ("serial").required
windowAnyWindow ("1h", "8h", "1D", "W", ...).required
tzAnyTime zone to lay the windows out in; None keeps the input's.None
Returns
TypeDescription
DataFrameOne row per window from the first enter to the last leave, with
DataFramestart, end, duration_seconds, object_seconds (object
DataFramepresence time in the window), wip_mean (``object_seconds /
DataFrameduration_seconds, averaged over the whole window) and wip_max``
DataFrame(the most objects present at once in the window). Empty input gives
DataFramean empty frame with these columns.

carrier_loops​

functionsource
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.

Parameters
NameTypeDescriptionDefault
intervalsObjectData:func:~ts_shape.eventlog.object_intervals output or an event log (see the module docstring).required
object_typestrThe carrier object type.'carrier'
start_stationstr | NoneStation 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
Returns
TypeDescription
CarrierLoopsclass:CarrierLoops with loops (one row per loop) and
CarrierLoopscarriers (one row per carrier, including carriers without a full
CarrierLoopsloop). Empty input gives empty tables with the documented columns.

attach_counts​

functionsource
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.

Parameters
NameTypeDescriptionDefault
intervalsObjectData:func:~ts_shape.eventlog.object_intervals output or an event log (see the module docstring).required
dataframeDataFrameLong-format frame holding the counter signal.required
counter_uuidstruuid of the counter signal.required
object_typestrObject type the counts are attributed to.required
value_columnstrColumn of the counter readings.'value_integer'
stationstr | NoneStation 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_columnstrSignal identifier column of dataframe.'uuid'
time_columnstrTimestamp column of dataframe.'systime'
Returns
NameTypeDescription
DataFrameOne row per object present at the station, in order of first
presenceDataFrameoid, type, quantity (float; 0 for an object
DataFramepresent while nothing was produced). A last row with oid
DataFrameholds the unattributed quantity, when there is any. The quantities
DataFrameadd up to the counter's total. Empty inputs give an empty frame with
DataFramethese columns.
Raises
TypeDescription
ColumnNotFoundErrorWhen dataframe lacks a named column.
ValueErrorWhen station is None and the counter has several source_uuid values.