ts_shape.events.production.duty_cycle
| Name | Description |
|---|---|
DutyCycleEvents | Production: Duty Cycle Analysis |
DutyCycleEvents
DutyCycleEvents(
dataframe: pd.DataFrame,
signal_uuid: str,
*,
event_uuid: str = "prod:duty_cycle",
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: Duty Cycle Analysis
Analyze on/off patterns from a boolean signal: duty cycle percentage, interval listing, transition counts, and excessive cycling detection.
Methods:
- duty_cycle_by_window: On-time percentage per time window.
- on_off_intervals: List every on and off interval with duration.
- cycle_count: Number of on/off transitions per window.
- excessive_cycling: Flag windows with too many transitions.
| Name | Description |
|---|---|
on_off_intervals | List every on and off interval with duration. |
duty_cycle_by_window | Percentage of time the signal is True per window. |
cycle_count | Number of on/off transitions per window. |
excessive_cycling | Flag windows where transition count exceeds threshold. |
| Name | Type | Description | Default |
|---|---|---|---|
dataframe | DataFrame | Long-format input data. | required |
signal_uuid | str | UUID of the boolean on/off signal (True = on). | required |
event_uuid | str | UUID assigned to generated events. | 'prod:duty_cycle' |
value_column | str | Column holding the on/off state. A missing value (None, NaN, pd.NA) is unknown, not off: the time from such a row to the next sample is in neither on_time nor off_time, no on/off interval covers it, and it is no transition. Ratios use observed (known-state) time. | 'value_bool' |
time_column | str | Timestamp column. | 'systime' |
interval_end | str | How on/off intervals are closed. "next_change" (default) closes each interval at the next transition, which measures both dense and change-encoded (is_delta) signals. "last_sample" ends each interval at its last sample; on a change-encoded signal (one row per transition) every on/off interval then has zero duration. | 'next_change' |
data_end | Timestamp | None | Optional bound for the final, still-open interval when interval_end="next_change"; :meth:duty_cycle_by_window (time-weighted) and :meth:cycle_count then also report the windows up to data_end. A naive value or text on tz-aware data is local time of the data's timezone. | None |
run_states | Collection[Any] | None | Values 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_range | tuple[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 |
on_off_intervals
on_off_intervals(*, max_gap: str | pd.Timedelta | None = None) -> pd.DataFrame
List every on and off interval with duration.
| Name | Type | Description | Default |
|---|---|---|---|
max_gap | str | Timedelta | None | Longest time between two samples an interval may span (e.g. "15min"). A longer gap is "no data": the interval before it ends at its last sample and a new interval starts after the gap, even if the state is unchanged. None (default): no limit. | None |
| Type | Description |
|---|---|
DataFrame | DataFrame with columns: start, end, duration_seconds (float), |
DataFrame | uuid (event uuid), source_uuid (signal uuid), state (on/off), |
DataFrame | duration (Timedelta). |
duty_cycle_by_window
duty_cycle_by_window(
window: str = "1h", *, time_weighted: bool = True, max_gap: Any = "auto"
) -> pd.DataFrame
Percentage of time the signal is True per window.
| Name | Type | Description | Default |
|---|---|---|---|
window | str | Resample window. | '1h' |
time_weighted | bool | When True (default), each sample is weighted by the gap to the next sample, so the duty cycle reflects wall-clock on-time on change-encoded and irregularly sampled signals; on_time and off_time are the covered seconds in the window. When False, the duty cycle is the mean of the boolean samples in the window, which equals the time share only under uniform sampling (On@09:00, Off@09:59 reads 50 %). | True |
max_gap | Any | Time-weighted only. A gap between two samples longer than this ("15min", Timedelta) is a logging gap: its time is unknown_seconds, neither on nor off. "auto" (default) uses the signal's inferred max_gap (five times the sampling period of a sampled signal; no cap for a change-encoded one, whose long gaps are real holds -- pass a value when the export has holes). None applies no cap. | 'auto' |
Each interval between two samples is split at the window
boundaries, so on_time + off_time + unknown_seconds never
exceeds the window's length (time-weighted).
Samples with a missing value are unknown time: in neither on_time
nor off_time (time-weighted) or not averaged (sample mean), and
duty_cycle_pct is the on share of the known time (NaN for a window
without any). With the constructor's data_end (time-weighted),
the last sample's state is held until data_end and the windows up
to it are reported.
| Type | Description |
|---|---|
DataFrame | DataFrame with columns: start, end (start + window), |
DataFrame | duration_seconds, uuid, source_uuid, on_time, on_time_seconds, |
DataFrame | off_time, off_time_seconds, duty_cycle_pct, unknown_seconds. On |
DataFrame | and off time are in seconds; unknown_seconds is the time in |
DataFrame | the window with a missing value or inside a gap longer than |
DataFrame | max_gap (time-weighted; 0 for the sample mean). |
DataFrame | Canonical twin columns: on_time_seconds (after on_time), |
DataFrame | off_time_seconds (after off_time); each holds the same |
DataFrame | values as the deprecated column right before it, which is removed |
DataFrame | in the next major release. |
cycle_count
cycle_count(window: str = '1h') -> pd.DataFrame
Number of on/off transitions per window.
A transition is a change between two known states; samples with a
missing value are skipped. With the constructor's data_end the
windows up to data_end are reported (with zero transitions after
the last sample).
| Name | Type | Description | Default |
|---|---|---|---|
window | str | Resample window. | '1h' |
| Type | Description |
|---|---|
DataFrame | DataFrame with columns: start, end (start + window), |
DataFrame | duration_seconds, uuid, source_uuid, on_count, off_count, |
DataFrame | total_transitions. |
excessive_cycling
excessive_cycling(
max_transitions: int = 20, window: str = "1h"
) -> pd.DataFrame
Flag windows where transition count exceeds threshold.
Excessive cycling indicates hunting, instability, or wear risk.
| Name | Type | Description | Default |
|---|---|---|---|
max_transitions | int | Threshold for flagging. | 20 |
window | str | Resample window. | '1h' |
| Type | Description |
|---|---|
DataFrame | DataFrame with columns: start, end (start + window), |
DataFrame | duration_seconds, uuid, source_uuid, transition_count, |
DataFrame | avg_on_duration, avg_on_duration_seconds, avg_off_duration, |
DataFrame | avg_off_duration_seconds. The averages are in seconds. |
DataFrame | Canonical twin columns: avg_on_duration_seconds (after |
DataFrame | avg_on_duration), avg_off_duration_seconds (after |
DataFrame | avg_off_duration); each holds the same values as the |
DataFrame | deprecated column right before it, which is removed in the next |
DataFrame | major release. |