Skip to main content
Version: 0.0.98

ts_shape.events.production.cycle_time_tracking

Cycle time tracking by part number.

Simple, practical module for cycle time analysis:

  • Cycle time per part number
  • Statistics (min, avg, max, std)
  • Slow cycle detection
  • Trend analysis
Classes
NameDescription
CycleTimeEventsTrack cycle times by part number.

CycleTimeEvents​

classsource
CycleTimeEvents(
dataframe: pd.DataFrame,
*,
time_column: str = "systime",
event_uuid: str = "prod:cycle_time"
) -> None

Bases: Base

Track cycle times by part number.

Each UUID represents one signal:

  • part_id_uuid: string signal with current part number
  • cycle_trigger_uuid: boolean/integer signal for cycle completion
Example
>>> import pandas as pd, ts_shape
>>> df = pd.concat([ts_shape.make_id_signal("part", ["A", "B"], hold=30),
... ts_shape.make_timeseries(["cycle"], n_points=60, value_column="value_bool")])
>>> stats = ts_shape.CycleTimeEvents(df).cycle_time_statistics("part", "cycle")
>>> stats[["part_number", "cycle_count", "avg_seconds"]].round(1)
part_number cycle_count avg_seconds
0 A 7 111.4
1 B 5 198.0
Functions
NameDescription
cycle_time_by_partCalculate cycle time for each part number.
cycle_time_statisticsCalculate statistics: min, avg, max, std cycle time by part.
detect_slow_cyclesIdentify cycles that exceed normal time by threshold factor.
detect_unusual_cyclesFind cycles that are unusually long or short, per part.
cycle_time_trendAnalyze cycle time trends for a specific part.
hourly_cycle_time_summaryHourly summary of cycle times by part.
Parameters
NameTypeDescriptionDefault
dataframeDataFrameInput DataFrame with timeseries datarequired
time_columnstrName of timestamp column (default: 'systime')'systime'
event_uuidstrUUID tagged on derived cycle events (the uuid column of point outputs; default: 'prod:cycle_time')'prod:cycle_time'

cycle_time_by_part​

methodsource
cycle_time_by_part(
part_id_uuid: str,
cycle_trigger_uuid: str,
*,
value_column_part: str = "value_string",
value_column_trigger: str = "value_bool",
max_cycle_gap: str | None = None
) -> pd.DataFrame

Calculate cycle time for each part number.

Parameters
NameTypeDescriptionDefault
part_id_uuidstrUUID for part number signalrequired
cycle_trigger_uuidstrUUID for cycle completion triggerrequired
value_column_partstrColumn containing part numbers'value_string'
value_column_triggerstrColumn containing cycle triggers'value_bool'
max_cycle_gapstr | NoneOptional cap (e.g. "5min"). Intervals between consecutive completions longer than this are dropped as inter-cycle downtime rather than reported as a cycle. Without it, a stoppage between completions (a break, a jam) becomes one giant "cycle" that inflates max/avg and is falsely flagged as a slow cycle.None
Returns
TypeDescription
DataFrameDataFrame with columns:
DataFrame- systime: Cycle completion time
DataFrame- uuid: Event UUID of this tracker
DataFrame- source_uuid: The cycle trigger UUID
DataFrame- part_number: Part number/ID
DataFrame- cycle_time_seconds: Cycle time in seconds
Example
>>> import pandas as pd, ts_shape
>>> df = pd.concat([ts_shape.make_id_signal("part", ["A", "B"], hold=30),
... ts_shape.make_timeseries(["cycle"], n_points=60, value_column="value_bool")])
>>> out = ts_shape.CycleTimeEvents(df).cycle_time_by_part("part", "cycle")
>>> out[["part_number", "cycle_time_seconds"]].head(3)
part_number cycle_time_seconds
0 A 60.0
1 A 120.0
2 A 120.0

cycle_time_statistics​

methodsource
cycle_time_statistics(
part_id_uuid: str,
cycle_trigger_uuid: str,
*,
value_column_part: str = "value_string",
value_column_trigger: str = "value_bool",
max_cycle_gap: str | None = None
) -> pd.DataFrame

Calculate statistics: min, avg, max, std cycle time by part.

Parameters
NameTypeDescriptionDefault
part_id_uuidstrUUID for part number signalrequired
cycle_trigger_uuidstrUUID for cycle completion triggerrequired
value_column_partstrColumn containing part numbers'value_string'
value_column_triggerstrColumn containing cycle triggers'value_bool'
max_cycle_gapstr | NoneOptional cap (e.g. "5min") forwarded to :meth:cycle_time_by_part: intervals between consecutive completions longer than this are dropped as inter-cycle downtime. Default None keeps every interval.None
Returns
TypeDescription
DataFrameDataFrame with statistics per part:
DataFrame- part_number: Part number/ID
DataFrame- count: Number of cycles (deprecated twin of cycle_count)
DataFrame- cycle_count: Number of cycles
DataFrame- min_seconds: Minimum cycle time
DataFrame- avg_seconds: Average cycle time
DataFrame- max_seconds: Maximum cycle time
DataFrame- std_seconds: Standard deviation
DataFrame- median_seconds: Median cycle time
DataFrame- p10_seconds: 10th percentile, the best demonstrated cycle time (a target taken from the data, not from master data)
DataFrame- p90_seconds: 90th percentile
DataFrame- mad_seconds: Median absolute deviation from the median (robust spread; unscaled)
DataFrameCanonical twin columns: cycle_count (after count); it
DataFrameholds the same values as the deprecated column right before it,
DataFramewhich is removed in the next major release.
Example
>>> import pandas as pd, ts_shape
>>> df = pd.concat([ts_shape.make_id_signal("part", ["A", "B"], hold=30),
... ts_shape.make_timeseries(["cycle"], n_points=60, value_column="value_bool")])
>>> stats = ts_shape.CycleTimeEvents(df).cycle_time_statistics("part", "cycle")
>>> stats[["part_number", "cycle_count", "median_seconds", "max_seconds"]]
part_number cycle_count median_seconds max_seconds
0 A 7 120.0 180.0
1 B 5 150.0 420.0

detect_slow_cycles​

methodsource
detect_slow_cycles(
part_id_uuid: str,
cycle_trigger_uuid: str,
*,
threshold_factor: float = 1.5,
value_column_part: str = "value_string",
value_column_trigger: str = "value_bool",
max_cycle_gap: str | None = None
) -> pd.DataFrame

Identify cycles that exceed normal time by threshold factor.

Parameters
NameTypeDescriptionDefault
part_id_uuidstrUUID for part number signalrequired
cycle_trigger_uuidstrUUID for cycle completion triggerrequired
threshold_factorfloatCycles slower than median * factor are flagged (default: 1.5)1.5
value_column_partstrColumn containing part numbers'value_string'
value_column_triggerstrColumn containing cycle triggers'value_bool'
max_cycle_gapstr | NoneOptional cap (e.g. "5min") forwarded to :meth:cycle_time_by_part: intervals between consecutive completions longer than this are dropped as inter-cycle downtime. Default None keeps every interval.None
Returns
TypeDescription
DataFrameDataFrame with slow cycles:
DataFrame- systime: Cycle completion time
DataFrame- uuid: Event UUID of this tracker
DataFrame- source_uuid: The cycle trigger UUID
DataFrame- part_number: Part number/ID
DataFrame- cycle_time_seconds: Actual cycle time
DataFrame- median_seconds: Expected (median) cycle time
DataFrame- deviation_factor: How many times slower than expected
DataFrame- is_slow: Flag (always True in returned data)
Example
>>> import pandas as pd, ts_shape
>>> df = pd.concat([ts_shape.make_id_signal("part", ["A", "B"], hold=30),
... ts_shape.make_timeseries(["cycle"], n_points=60, value_column="value_bool")])
>>> slow = ts_shape.CycleTimeEvents(df).detect_slow_cycles("part", "cycle")
>>> slow[["part_number", "cycle_time_seconds", "deviation_factor"]]
part_number cycle_time_seconds deviation_factor
0 A 180.0 1.5
1 B 240.0 1.6
2 B 420.0 2.8

detect_unusual_cycles​

methodsource
detect_unusual_cycles(
part_id_uuid: str,
cycle_trigger_uuid: str,
*,
n_sigma: float = 3.0,
value_column_part: str = "value_string",
value_column_trigger: str = "value_bool",
max_cycle_gap: str | None = None
) -> pd.DataFrame

Find cycles that are unusually long or short, per part.

Unlike :meth:detect_slow_cycles (a fixed factor on the slow side only) the bounds are statistical and two-sided: a cycle is unusual when its log cycle time lies more than n_sigma robust sigmas (scaled median absolute deviation, at least 1 %) from the part's median log cycle time. Working on the log makes the bounds relative, so they transfer between a 5 s and a 300 s cycle. For pauses kept as their own class and a profile without signal mapping see :class:~ts_shape.events.profiling.cycles.CycleProfileEvents.

Parameters
NameTypeDescriptionDefault
part_id_uuidstrUUID for part number signalrequired
cycle_trigger_uuidstrUUID for cycle completion triggerrequired
n_sigmafloatRobust sigmas beyond which a cycle is unusual.3.0
value_column_partstrColumn containing part numbers'value_string'
value_column_triggerstrColumn containing cycle triggers'value_bool'
max_cycle_gapstr | NoneOptional cap forwarded to :meth:cycle_time_by_part.None
Returns
TypeDescription
DataFrameDataFrame with the unusual cycles:
DataFrame- systime, uuid, source_uuid, part_number, cycle_time_seconds
DataFrame- median_seconds: The part's median cycle time
DataFrame- lower_limit_seconds / upper_limit_seconds: The robust bounds
DataFrame- z_score: Robust z-score of the log cycle time
DataFrame- cycle_class: "short" or "long"
DataFrame- direction: "below" or "above" the robust band
Example
>>> import pandas as pd, ts_shape
>>> t = pd.Timestamp("2025-01-01") + pd.to_timedelta(
... [0, 60, 121, 180, 242, 300, 330, 391, 450, 600], unit="s")
>>> df = pd.concat([
... pd.DataFrame({"systime": t, "uuid": "done", "value_integer": range(10)}),
... pd.DataFrame({"systime": t[:1], "uuid": "part", "value_string": ["A"]})])
>>> out = ts_shape.CycleTimeEvents(df).detect_unusual_cycles(
... "part", "done", value_column_trigger="value_integer")
>>> out[["cycle_time_seconds", "cycle_class"]]
cycle_time_seconds cycle_class
0 30.0 short
1 150.0 long

cycle_time_trend​

methodsource
cycle_time_trend(
part_id_uuid: str,
cycle_trigger_uuid: str,
part_number: str,
*,
window_size: int = 20,
value_column_part: str = "value_string",
value_column_trigger: str = "value_bool",
max_cycle_gap: str | None = None,
stable_band_ratio: float = 0.01
) -> pd.DataFrame

Analyze cycle time trends for a specific part.

Parameters
NameTypeDescriptionDefault
part_id_uuidstrUUID for part number signalrequired
cycle_trigger_uuidstrUUID for cycle completion triggerrequired
part_numberstrSpecific part number to analyzerequired
window_sizeintNumber of cycles for moving average (default: 20)20
value_column_partstrColumn containing part numbers'value_string'
value_column_triggerstrColumn containing cycle triggers'value_bool'
max_cycle_gapstr | NoneOptional cap (e.g. "5min") forwarded to :meth:cycle_time_by_part: intervals between consecutive completions longer than this are dropped as inter-cycle downtime. Default None keeps every interval.None
stable_band_ratiofloatA change of the moving average within this fraction of the part's median cycle time is stable (default 0.01 = 1 %). The band scales with the cycle, so the same setting fits a 5 s and a 300 s cycle; earlier versions used a fixed band of +-0.5 s.0.01
Returns
TypeDescription
DataFrameDataFrame with trend data:
DataFrame- systime: Cycle completion time
DataFrame- cycle_time_seconds: Actual cycle time
DataFrame- moving_avg: Moving average cycle time (deprecated twin)
DataFrame- moving_avg_seconds: Moving average cycle time in seconds
DataFrame- trend: 'improving', 'stable', or 'degrading'
Example
>>> import pandas as pd, ts_shape
>>> df = pd.concat([ts_shape.make_id_signal("part", ["A", "B"], hold=30),
... ts_shape.make_timeseries(["cycle"], n_points=60, value_column="value_bool")])
>>> trend = ts_shape.CycleTimeEvents(df).cycle_time_trend(
... "part", "cycle", "A", window_size=3)
>>> trend[["cycle_time_seconds", "moving_avg_seconds", "trend"]].tail(3)
cycle_time_seconds moving_avg_seconds trend
4 60.0 120.0 improving
5 120.0 120.0 stable
6 120.0 100.0 improving

hourly_cycle_time_summary​

methodsource
hourly_cycle_time_summary(
part_id_uuid: str,
cycle_trigger_uuid: str,
*,
value_column_part: str = "value_string",
value_column_trigger: str = "value_bool",
max_cycle_gap: str | None = None
) -> pd.DataFrame

Hourly summary of cycle times by part.

Parameters
NameTypeDescriptionDefault
part_id_uuidstrUUID for part number signalrequired
cycle_trigger_uuidstrUUID for cycle completion triggerrequired
value_column_partstrColumn containing part numbers'value_string'
value_column_triggerstrColumn containing cycle triggers'value_bool'
max_cycle_gapstr | NoneOptional cap (e.g. "5min") forwarded to :meth:cycle_time_by_part: intervals between consecutive completions longer than this are dropped as inter-cycle downtime. Default None keeps every interval.None
Returns
TypeDescription
DataFrameDataFrame with hourly statistics:
DataFrame- hour: Hour timestamp
DataFrame- part_number: Part number/ID
DataFrame- cycles_completed: Number of cycles
DataFrame- avg_cycle_time / avg_cycle_time_seconds: Average cycle time
DataFrame- min_cycle_time / min_cycle_time_seconds: Fastest cycle
DataFrame- max_cycle_time / max_cycle_time_seconds: Slowest cycle
DataFrameAll cycle times are in seconds. Canonical twin columns:
DataFrameavg_cycle_time_seconds, min_cycle_time_seconds,
DataFramemax_cycle_time_seconds, each right after its deprecated
DataFrameunitless column (same values), which is removed in the next major
DataFramerelease.
Example
>>> import pandas as pd, ts_shape
>>> df = pd.concat([ts_shape.make_id_signal("part", ["A", "B"], hold=30),
... ts_shape.make_timeseries(["cycle"], n_points=60, value_column="value_bool")])
>>> hourly = ts_shape.CycleTimeEvents(df).hourly_cycle_time_summary("part", "cycle")
>>> hourly[["part_number", "cycles_completed", "avg_cycle_time_seconds"]]
part_number cycles_completed avg_cycle_time_seconds
0 A 7 111.428571
1 B 5 198.000000