Skip to main content
Version: Next

ts_shape.events.production.micro_stop_detection

Classes
NameDescription
MicroStopEventsProduction: Micro-Stop Detection

MicroStopEvents​

classsource
MicroStopEvents(
dataframe: pd.DataFrame,
run_state_uuid: str,
*,
event_uuid: str = "prod:micro_stop",
value_column: str = "value_bool",
time_column: str = "systime",
interval_end: str = "next_change",
data_end: pd.Timestamp | None = None,
run_states: Collection[Any] | None = None,
value_range: tuple[float | None, float | None] | None = None
) -> None

Bases: Base

Production: Micro-Stop Detection

Detect brief idle intervals that individually seem harmless but accumulate into significant availability losses.

Methods:

  • detect_micro_stops: Find idle intervals shorter than max_duration.
  • micro_stop_frequency: Count micro-stops per time window.
  • micro_stop_impact: Time lost to micro-stops per window.
  • micro_stop_patterns: Group micro-stops by hour-of-day or shift.
Example
>>> import pandas as pd
>>> from ts_shape import MicroStopEvents
>>> df = pd.DataFrame({
... "systime": pd.to_datetime([
... "2025-01-01 08:00:00", "2025-01-01 08:10:00", "2025-01-01 08:10:20",
... "2025-01-01 08:30:00", "2025-01-01 08:30:45", "2025-01-01 09:00:00"]),
... "uuid": "run",
... "value_bool": [True, False, True, False, True, True],
... })
>>> stops = MicroStopEvents(df, "run").detect_micro_stops(max_duration="30s")
>>> stops[["start", "end", "duration_seconds"]]
start end duration_seconds
0 2025-01-01 08:10:00 2025-01-01 08:10:20 20.0

The 45 s stop at 08:30 is longer than max_duration and is not listed.

Functions
NameDescription
detect_micro_stopsFind idle intervals shorter than max_duration.
micro_stop_frequencyCount micro-stops per time window.
micro_stop_impactTime lost to micro-stops vs total available time per window.
micro_stop_patternsGroup micro-stops by hour-of-day or shift to find clustering patterns.
Parameters
NameTypeDescriptionDefault
dataframeDataFrameLong-format input data.required
run_state_uuidstrUUID of the boolean run-state signal (True = running, False = idle).required
event_uuidstrUUID assigned to generated events.'prod:micro_stop'
value_columnstrColumn holding the run state. Missing values count as idle.'value_bool'
time_columnstrTimestamp column.'systime'
interval_endstrHow idle/run intervals are closed. "next_change" (default) closes each interval at the next transition, which measures both dense and change-encoded (is_delta) run-state signals. "last_sample" ends each interval at its last sample; on a change-encoded signal (one row per transition) every interval then has zero duration and no lost time is reported.'next_change'
data_endTimestamp | NoneOptional bound for the final, still-open interval when interval_end="next_change".None
run_statesCollection[Any] | NoneValues of the run signal that mean running (e.g. {2} for a mode signal where 2 is automatic, or {"RUN"}); every other known value is not running. None (default) uses value_range or reads the signal as a bool, with a DataQualityWarning when it is not one.None
value_rangetuple[float | None, float | None] | None(lower, upper) inclusive bounds; a value inside counts as running (either bound may be None). Used when run_states is None.None

detect_micro_stops​

methodsource
detect_micro_stops(
max_duration: str = "30s", min_duration: str = "0s"
) -> pd.DataFrame

Find idle intervals shorter than max_duration.

Parameters
NameTypeDescriptionDefault
max_durationstrMaximum duration to qualify as a micro-stop.'30s'
min_durationstrMinimum duration to include (filter very short glitches).'0s'
Returns
TypeDescription
DataFrameDataFrame with columns: start, end, duration_seconds (float),
DataFrameuuid (event uuid), source_uuid (run-state uuid), duration
DataFrame(Timedelta), preceding_run_duration.

micro_stop_frequency​

methodsource
micro_stop_frequency(
window: str = "1h", max_duration: str = "30s"
) -> pd.DataFrame

Count micro-stops per time window.

Parameters
NameTypeDescriptionDefault
windowstrResample window.'1h'
max_durationstrMaximum idle duration to qualify as micro-stop.'30s'
Returns
TypeDescription
DataFrameDataFrame with columns: start, end (start + window),
DataFrameduration_seconds, uuid, source_uuid, count, total_lost_time,
DataFramepct_of_window.
DataFrametotal_lost_time is in seconds; pct_of_window is it as a
DataFramepercentage of the window's real duration_seconds (23 h or
DataFrame25 h for a daily window on a DST change).
DataFrameCanonical twin columns: micro_stop_count (after count),
DataFrametotal_lost_time_seconds (after total_lost_time) and
DataFrameshare_of_window_pct (after pct_of_window); each holds the same values as the deprecated
DataFramecolumn right before it, which is removed in the next major release.

micro_stop_impact​

methodsource
micro_stop_impact(
window: str = "1h", max_duration: str = "30s"
) -> pd.DataFrame

Time lost to micro-stops vs total available time per window.

A stop is classified as a micro-stop by its full duration; its time and the run time are then split at the window boundaries (the ISO 22400-2 time model), so a stop across the hour counts in both hours. Every window from the first interval to the end of the last one is reported (0 when it holds no run or micro-stop time).

Parameters
NameTypeDescriptionDefault
windowstrResample window.'1h'
max_durationstrMaximum idle duration to qualify as micro-stop.'30s'
Returns
TypeDescription
DataFrameDataFrame with columns: start, end (start + window),
DataFrameduration_seconds, uuid, source_uuid, total_run_time,
DataFrametotal_micro_stop_time, performance_loss_pct,
DataFrameavailability_loss_pct.
DataFrametotal_run_time and total_micro_stop_time are in seconds;
DataFrametheir canonical twins total_run_time_seconds and
DataFrametotal_micro_stop_time_seconds follow each of them (the old
DataFramenames are removed in the next major release).
DataFrameperformance_loss_pct is the micro-stop time as a percentage of
DataFramerun + micro-stop time. Minor stops are a performance loss in
DataFrameNakajima's six big losses (idling and minor stoppages), not an
DataFrameavailability loss. availability_loss_pct holds the same value
DataFrameunder its original, misleading name and is kept for
DataFramecompatibility.

micro_stop_patterns​

methodsource
micro_stop_patterns(
hour_grouping: bool = True,
max_duration: str = "30s",
shift_definitions: dict[str, tuple[str, str]] | None = None,
) -> pd.DataFrame

Group micro-stops by hour-of-day or shift to find clustering patterns.

Each stop counts in the hour (or shift) it starts in. The count and lost time are summed per day and averaged over the days that have stops in that hour (or shift).

Parameters
NameTypeDescriptionDefault
hour_groupingboolIf True, group by hour of day. If False, group by shift.True
max_durationstrMaximum idle duration to qualify as micro-stop.'30s'
shift_definitionsdict[str, tuple[str, str]] | NoneShift name -> (start, end) times for hour_grouping=False. Default: three 8-hour shifts shift_1 (06:00-14:00), shift_2 (14:00-22:00) and shift_3 (22:00-06:00), as everywhere in ts-shape. A shift that crosses midnight is one shift per night: its stops after midnight count on the shift's start date.None
Returns
TypeDescription
DataFrameDataFrame with columns: hour (or shift), avg_count, avg_lost_time,
DataFrameavg_lost_time_seconds. avg_lost_time is in seconds; its
DataFramecanonical twin avg_lost_time_seconds follows it (the old name
DataFrameis removed in the next major release).