Skip to main content
Version: Next

ts_shape.events.production.shift_handover

Automated shift handover report generation.

Standardize shift-to-shift communication:

  • Production summary
  • Quality summary
  • Downtime summary
  • Issues to watch

Two modes of operation:

  1. From raw signals: generate_report(counter_uuid, ok_counter_uuid, ...)
  2. From pre-computed DataFrames: from_shift_data(production_df, quality_df, downtime_df)
Classes
NameDescription
ShiftHandoverEventsGenerate automated shift handover reports.

ShiftHandoverEvents​

classsource
ShiftHandoverEvents(
dataframe: pd.DataFrame,
*,
time_column: str = "systime",
shift_definitions: dict[str, tuple[str, str]] | None = None
) -> None

Bases: Base

Generate automated shift handover reports.

Combines production, quality, and downtime data into a single summary suitable for shift handover meetings.

Merge keys: [date, shift] — the report output is keyed on these columns.

Two usage patterns:

Pattern A — from raw signals (one-step):

report = ShiftHandoverEvents(df)
result = report.generate_report(
counter_uuid='prod', ok_counter_uuid='ok',
nok_counter_uuid='nok', run_state_uuid='state',
targets={'shift_1': 450, 'shift_2': 450},
)

Pattern B — pipeline (compose from upstream modules):

# Step 1: compute upstream DataFrames
prod = ShiftReportEvents(df).shift_production('counter')
qual = QualityEvents(df).nok_by_shift('ok', 'nok')
downtime = DowntimeEvents(df).downtime_by_shift('state')

# Step 2: assemble into handover report
result = ShiftHandoverEvents.from_shift_data(
production_df=prod,
quality_df=qual,
downtime_df=downtime,
targets={'shift_1': 450, 'shift_2': 450},
)

Both patterns return the same output schema.

Run state may be a string state signal (running_value="Running" in value_string) or a boolean run signal (value_bool, True = running); see :meth:generate_report. downtime_seconds is the downtime in seconds; downtime_minutes is kept as a convenience.

Functions
NameDescription
from_shift_dataBuild a handover report from pre-computed shift-level DataFrames.
generate_reportGenerate a shift handover report from raw timeseries signals.
highlight_issuesIdentify issues that need attention.
Parameters
NameTypeDescriptionDefault
dataframeDataFrameLong-format timeseries frame (one row per sample, uuid identifies the signal).required
time_columnstrTimestamp column.'systime'
shift_definitionsdict[str, tuple[str, str]] | NoneMapping of shift name to (start, end) "HH:MM" times. None (default) uses three shifts: 06:00-14:00, 14:00-22:00, 22:00-06:00.None

from_shift_data​

staticmethodsource
from_shift_data(
production_df: pd.DataFrame,
quality_df: pd.DataFrame | None = None,
downtime_df: pd.DataFrame | None = None,
*,
targets: dict[str, float] | None = None,
report_date: str | None = None
) -> pd.DataFrame

Build a handover report from pre-computed shift-level DataFrames.

This is the pipeline-friendly entry-point. Instead of reading raw signals, it accepts DataFrames that were already computed by upstream modules (ShiftReportEvents, QualityEvents, DowntimeEvents, etc.).

Parameters
NameTypeDescriptionDefault
production_dfDataFrameDataFrame with [date, shift, quantity] — e.g. from ShiftReportEvents.shift_production().required
quality_dfDataFrame | NoneDataFrame with [date, shift, ok_parts, nok_parts, quality_pct] — e.g. from QualityEvents.nok_by_shift(). Optional.None
downtime_dfDataFrame | NoneDataFrame with [date, shift, availability_pct, downtime_seconds] — e.g. from DowntimeEvents.downtime_by_shift(). Optional. A frame with only the legacy downtime_minutes still works, with a DeprecationWarning, until the next major release.None
targetsdict[str, float] | NonePer-shift production targets (dict).None
report_datestr | NoneSpecific date (YYYY-MM-DD). If None, uses latest.None
Returns
TypeDescription
DataFrameDataFrame with columns:
DataFramedate, shift, production, production_target, production_achievement_pct,
DataFrameok_parts, nok_parts, quality_pct, availability_pct, downtime_minutes,
DataFramedowntime_seconds. When downtime_df carries only one of
DataFramedowntime_seconds / downtime_minutes, the other is derived
DataFramefrom it.

generate_report​

methodsource
generate_report(
counter_uuid: str,
ok_counter_uuid: str,
nok_counter_uuid: str,
run_state_uuid: str,
*,
targets: dict[str, float] | None = None,
quality_target_pct: float = 98.0,
availability_target_pct: float = 90.0,
running_value: str | bool | Collection[Any] = "Running",
value_column_counter: str = "value_integer",
value_column_state: str = "value_string",
report_date: str | None = None,
handle_resets: bool = True,
production_day: bool = True
) -> pd.DataFrame

Generate a shift handover report from raw timeseries signals.

For pipeline usage with pre-computed DataFrames, use :meth:from_shift_data instead.

Parameters
NameTypeDescriptionDefault
counter_uuidstrUUID of production counter.required
ok_counter_uuidstrUUID of good parts counter.required
nok_counter_uuidstrUUID of the NOK part counter.required
run_state_uuidstrUUID of machine state signal.required
targetsdict[str, float] | NonePer-shift production targets.None
quality_target_pctfloatQuality target percentage.98.0
availability_target_pctfloatAvailability target percentage.90.0
running_valuestr | bool | Collection[Any]Value indicating machine is running. A bool matches a boolean run signal (value_bool by default); a boolean run signal is also used, with True as running, when the state rows carry no value_column_state value. A set, list or tuple of values (e.g. {2} for a mode signal) matches any of them.'Running'
value_column_counterstrColumn for counter values.'value_integer'
value_column_statestrColumn for state values.'value_string'
report_datestr | NoneSpecific date (YYYY-MM-DD). If None, uses latest date.None
handle_resetsboolWhen True (default), treat a decreasing counter as a reset and count the production after the reset for production, ok_parts and nok_parts. A shift boundary is exactly where counters commonly reset, so max(0, last - first) (handle_resets=False) under-reports any shift containing a reset. The increments are computed once over each whole signal (before report_date is selected); the increment between two readings is spread over the time between them and split at the shift boundaries in proportion to time, so the shifts add up to the signal totals and production / ok_parts / nok_parts can be fractional; with handle_resets=False the production between two shifts' readings is lost. The result gains a resets column with the number of production-counter resets in each shift.True
production_dayboolWhen True, an overnight shift's post-midnight readings are attributed to the shift's start date, so a night shift is one contiguous (date, shift) group instead of being split across two calendar dates. Default True. Only affects schedules with an overnight shift.True
Returns
TypeDescription
DataFrameDataFrame with columns:
DataFramestart, end, duration_seconds (the shift window from
DataFrameshift_definitions, tz-aware in the data's tz; an overnight
DataFrameshift ends on the next day), date, shift, production,
DataFrameproduction_target, production_achievement_pct, ok_parts,
DataFramenok_parts, quality_pct, availability_pct, downtime_minutes
DataFrame(convenience), downtime_seconds, and resets (only when
DataFramehandle_resets=True).

highlight_issues​

methodsource
highlight_issues(
counter_uuid: str | None = None,
ok_counter_uuid: str | None = None,
nok_counter_uuid: str | None = None,
run_state_uuid: str | None = None,
*,
report_df: pd.DataFrame | None = None,
thresholds: dict[str, float] | None = None,
targets: dict[str, float] | None = None,
running_value: str | bool | Collection[Any] = "Running",
value_column_counter: str = "value_integer",
value_column_state: str = "value_string",
report_date: str | None = None,
as_frame: bool = True
) -> pd.DataFrame | list[dict[str, Any]]

Identify issues that need attention.

Can be called in two ways:

  1. From raw signals (provide UUIDs): highlight_issues('prod', 'ok', 'nok', 'state', thresholds={...})

  2. From a pre-built report DataFrame: highlight_issues(report_df=my_report, thresholds={...})

Parameters
NameTypeDescriptionDefault
counter_uuidstr | NoneUUID of production counter (raw-signal mode).None
ok_counter_uuidstr | NoneUUID of good parts counter (raw-signal mode).None
nok_counter_uuidstr | NoneUUID of the NOK part counter (raw-signal mode).None
run_state_uuidstr | NoneUUID of machine state signal (raw-signal mode).None
report_dfDataFrame | NonePre-computed report DataFrame (pipeline mode). If provided, UUID arguments are ignored.None
thresholdsdict[str, float] | NoneMinimum acceptable values for each metric. Defaults to production_achievement_pct=95, quality_pct=98, availability_pct=90.None
targetsdict[str, float] | NonePer-shift production targets.None
running_valuestr | bool | Collection[Any]Value indicating machine is running (a string, a bool, or a set of values that mean running).'Running'
value_column_counterstrColumn for counter values.'value_integer'
value_column_statestrColumn for state values.'value_string'
report_datestr | NoneSpecific date (YYYY-MM-DD).None
as_frameboolWhen True (default), return a DataFrame (see below). as_frame=False returns the list of dicts; it is deprecated, emits a DeprecationWarning and will be removed in the next major release.True
Returns
TypeDescription
DataFrame | list[dict[str, Any]]With as_frame=True (default), one row per issue with columns
:attr:ISSUE_COLUMNS``start, end, duration_seconds (the shift
DataFrame | list[dict[str, Any]]window of the report row; NaT / NaN when the report has none,
DataFrame | list[dict[str, Any]]e.g. one built by :meth:from_shift_data), date, shift, metric,
DataFrame | list[dict[str, Any]]value, threshold, severity, severity_level (warn / critical).
DataFrame | list[dict[str, Any]]With as_frame=False (deprecated), a list of dicts with keys
DataFrame | list[dict[str, Any]]shift, metric, value, threshold, severity.
DataFrame | list[dict[str, Any]]severity is 'warning' (within 5% of threshold) or 'critical'.
Raises
TypeDescription
ValueErrorIf report_df is None and any of the four signal UUIDs is missing, so no report can be built.