Skip to main content
Version: Next

ts_shape.events.production.schedule_adherence

Production schedule adherence: planned quantity vs. what the line made.

OEE answers "how well did the line run?" but not "did it make what the plan asked for?". Those come apart routinely: a line at 92 % OEE running the wrong order is still behind schedule, and a line that lost two hours to a changeover can be on plan if the plan accounted for it.

This detector joins a planned schedule -- period start/end, planned quantity, order id -- against actual production derived from a monotonic counter, and reports per period how far ahead or behind the line is, plus the rate it would have to hold for the rest of the period to recover.

Actual quantities are reset-aware by default (see :mod:ts_shape.utils.counters): a counter that drops to zero at a part change inside a scheduled period would otherwise report the period as catastrophically behind. Pass handle_resets=False for the naive last - first reading.

Classes
NameDescription
ProductionScheduleAdherenceEventsProduction: schedule vs. actual adherence.

ProductionScheduleAdherenceEvents​

classsource
ProductionScheduleAdherenceEvents(
dataframe: pd.DataFrame,
schedule: pd.DataFrame,
*,
event_uuid: str = "prod:schedule_adherence",
time_column: str = "systime",
uuid_column: str = "uuid",
value_column: str = "value_double",
schedule_start_column: str = "start",
schedule_end_column: str = "end",
planned_qty_column: str = "planned_qty",
order_id_column: str = "order_id"
) -> None

Bases: Base

Production: schedule vs. actual adherence.

The schedule is a plain DataFrame — one row per planned period::

schedule = pd.DataFrame({
"start": pd.to_datetime(["2024-05-02 06:00", "2024-05-02 14:00"]),
"end": pd.to_datetime(["2024-05-02 14:00", "2024-05-02 22:00"]),
"planned_qty": [400, 400],
"order_id": ["WO-1001", "WO-1002"],
})

adherence = ProductionScheduleAdherenceEvents(df, schedule)
adherence.adherence_by_period("counter:line-1")

Column names are configurable via the constructor, so an MES export can be passed through without renaming.

Methods:

  • adherence_by_period: Planned vs. actual and recovery rate per period.
  • deviation_events: Point events for periods breaching the deviation bands.
  • adherence_summary: Roll-up across the scheduled horizon.
Functions
NameDescription
adherence_by_periodCompare planned against actual production for every scheduled period.
deviation_eventsEmit one event per period that deviates from plan.
adherence_summaryRoll the per-period adherence up across the scheduled horizon.
Parameters
NameTypeDescriptionDefault
dataframeDataFrameTimeseries frame holding the production counter.required
scheduleDataFramePlanned schedule, one row per period.required
event_uuidstrUUID stamped on emitted events.'prod:schedule_adherence'
time_columnstrTimestamp column of dataframe.'systime'
uuid_columnstrSignal-identifier column of dataframe.'uuid'
value_columnstrCounter-value column of dataframe.'value_double'
schedule_start_columnstrPeriod-start column of schedule.'start'
schedule_end_columnstrPeriod-end column of schedule.'end'
planned_qty_columnstrPlanned-quantity column of schedule.'planned_qty'
order_id_columnstrOptional order-identifier column of schedule. With the default name a schedule without the column is fine — the emitted order_id is then None; a name passed explicitly must exist.'order_id'
Raises
TypeDescription
TypeErrorIf schedule is not a DataFrame.
ColumnNotFoundErrorIf schedule lacks a required column, or an explicitly named order_id_column (a ValueError subclass, so except ValueError keeps working).
ValueErrorIf a period ends before it starts.

adherence_by_period​

methodsource
adherence_by_period(
counter_uuid: str,
*,
handle_resets: bool = True,
as_of: pd.Timestamp | str | None = None,
ahead_pct: float = 105.0,
behind_pct: float = 95.0,
critical_pct: float = 80.0
) -> pd.DataFrame

Compare planned against actual production for every scheduled period.

recovery_required_rate is the units per hour the line must hold over the time still left in the period to finish on plan, evaluated at as_of. It is 0 for a period already at or above plan and NaN once the period is over — a finished period cannot be recovered, and reporting a rate for it would invite planning against a number that means nothing.

Parameters
NameTypeDescriptionDefault
counter_uuidstrIdentifier of the monotonic production counter.required
handle_resetsboolTreat a decreasing counter as a reset and count the post-reset value as new production. Default True. The increments are computed once over the whole counter signal; a reading reports the production since the previous reading, so a period [start, end] gets the increments of the readings in (start, end]. The production between the last reading before start and the first reading in the period is counted, and a reading on a boundary shared by two periods is booked once, to the period ending there. When False, actual_qty is max(0, last - first) of the readings in [start, end].True
as_ofTimestamp | str | NoneEvaluation time for the recovery rate. Defaults to the last timestamp present in the data.None
ahead_pctfloatAdherence above this is ahead.105.0
behind_pctfloatAdherence below this is behind.95.0
critical_pctfloatAdherence below this is critical_behind.80.0
Returns
TypeDescription
DataFrameSummary-shape DataFrame: start, end, duration_seconds,
DataFrameuuid, source_uuid, order_id, planned_qty,
DataFrameactual_qty, schedule_adherence_pct, deviation_units,
DataFramedeviation_type, recovery_required_rate,
DataFrameremaining_seconds, sample_count, resets.
Raises
TypeDescription
ValueErrorIf the band thresholds are not ordered critical_pct <= behind_pct <= ahead_pct.

deviation_events​

methodsource
deviation_events(
counter_uuid: str,
*,
handle_resets: bool = True,
as_of: pd.Timestamp | str | None = None,
ahead_pct: float = 105.0,
behind_pct: float = 95.0,
critical_pct: float = 80.0,
include_ahead: bool = False
) -> pd.DataFrame

Emit one event per period that deviates from plan.

Parameters
NameTypeDescriptionDefault
counter_uuidstrIdentifier of the monotonic production counter.required
handle_resetsboolSee :meth:adherence_by_period.True
as_ofTimestamp | str | NoneSee :meth:adherence_by_period.None
ahead_pctfloatAdherence above this is ahead.105.0
behind_pctfloatAdherence below this is behind.95.0
critical_pctfloatAdherence below this is critical_behind.80.0
include_aheadboolAlso emit rows for periods running ahead of plan. Off by default — running ahead is rarely an alert, but it is worth reporting when the plan feeds a downstream commitment.False
Returns
TypeDescription
DataFramePoint-shape DataFrame: systime, uuid, source_uuid,
DataFrameorder_id, planned_qty, actual_qty,
DataFrameschedule_adherence_pct, deviation_units,
DataFramedeviation_type, recovery_required_rate, severity,
DataFramedirection, threshold.

adherence_summary​

methodsource
adherence_summary(
counter_uuid: str,
*,
handle_resets: bool = True,
as_of: pd.Timestamp | str | None = None,
ahead_pct: float = 105.0,
behind_pct: float = 95.0,
critical_pct: float = 80.0
) -> pd.DataFrame

Roll the per-period adherence up across the scheduled horizon.

overall_adherence_pct is computed from the summed quantities, not as the mean of the per-period percentages: a period with a planned quantity of 10 should not weigh as much as one planning 1000.

Parameters
NameTypeDescriptionDefault
counter_uuidstrIdentifier of the monotonic production counter.required
handle_resetsboolSee :meth:adherence_by_period.True
as_ofTimestamp | str | NoneSee :meth:adherence_by_period.None
ahead_pctfloatAdherence above this is ahead.105.0
behind_pctfloatAdherence below this is behind.95.0
critical_pctfloatAdherence below this is critical_behind.80.0
Returns
TypeDescription
DataFrameSummary-shape DataFrame with a single row: start, end,
DataFrameduration_seconds, uuid, source_uuid,
DataFrametotal_planned_qty, total_actual_qty,
DataFrameoverall_adherence_pct, deviation_units, periods,
DataFrameperiods_on_track, periods_behind,
DataFrameperiods_critical_behind, periods_ahead,
DataFrameon_plan_rate_pct, worst_order_id,
DataFrameworst_adherence_pct, sample_count.