Skip to main content
Version: 0.0.98

ts_shape.events.maintenance.reliability

Reliability: MTBF, MTTR and Weibull life analysis from a failure-state signal.

Input is one held state signal whose value says whether the asset is failed (down for repair) -- a fault bit, a breakdown status code, a maintenance mode. The timeline is built with :func:ts_shape.signals.primitives.intervals, so each state holds until the next change and a logging gap longer than max_gap is "no data": it counts as neither operating nor repair time.

Definitions (hours throughout):

  • operating time -- time in a non-failed state.
  • repair time (TTR) -- time in a failed state. Consecutive failed intervals separated only by a data gap are one failure.
  • TBF -- operating time between the end of one repair and the next failure.
  • mtbf_hours = operating time / failures (the common definition).
  • mtbf_iso22400_hours = operating time / (failures + 1): ISO 22400-2 averages over the FE + 1 operating periods, including the one still running at the end of the window.
  • mttr_hours = repair time / failures.
  • availability_pct = operating / (operating + repair): inherent availability, the share of known time the asset was not failed.

The Weibull fit treats the operating period still running at the end of the data as right-censored (it has not failed yet), which is what keeps the life estimate from being biased low.

Classes
NameDescription
ReliabilityEventsMaintenance: reliability KPIs from a failure-state signal.

ReliabilityEvents​

classsource
ReliabilityEvents(
dataframe: pd.DataFrame,
run_state_uuid: str,
*,
failure_states: Sequence[object] = (True,),
value_column: str = "value_bool",
max_gap: str | pd.Timedelta | None = None,
data_end: str | pd.Timestamp | None = None,
event_uuid: str = "maint:reliability",
time_column: str = "systime"
) -> None

Bases: Base

Maintenance: reliability KPIs from a failure-state signal.

  • failure_events: One interval per failure, with its repair time and the operating time before it.
  • mtbf_mttr: MTBF, MTTR, availability and failure rate, overall or per calendar window.
  • weibull_fit: Weibull life model of the times between failures, with right censoring; shape beta tells infant mortality / random / wear-out.
  • reliability_at: Reliability and hazard at given operating times from the fitted model, optionally conditional on the current age.
Example
>>> import pandas as pd, ts_shape
>>> t = pd.date_range("2025-01-01", periods=8, freq="1h")
>>> df = pd.DataFrame({"systime": t, "uuid": "fault", "value_bool":
... [False, False, True, False, False, False, True, False]})
>>> kpi = ts_shape.ReliabilityEvents(df, "fault").mtbf_mttr()
>>> kpi[["failures", "mtbf_hours", "mttr_hours", "availability_pct"]].round(1)
failures mtbf_hours mttr_hours availability_pct
0 2 2.5 1.0 71.4
Functions
NameDescription
failure_eventsOne interval per failure.
mtbf_mttrMTBF, MTTR, availability and failure rate.
weibull_fitTwo-parameter Weibull model of the times between failures.
reliability_atReliability and hazard from the fitted Weibull model.
run_state_uuid: The failure-state signal.
failure_states: Values meaning "failed / down for repair". The
default ``(True,)`` fits a fault bit; for a status code pass
e.g. ``("BREAKDOWN", "REPAIR")``.
value_column: Column holding the state.
max_gap: Longest time a state is held; longer gaps are no data.
Default None: every state is held until the next sample, however
long the gap.
data_end: End of the observation (e.g. "now"); the last state
holds until then. Default: the last sample.
event_uuid: ``uuid`` of the emitted events.
time_column: Timestamp column.

failure_events​

methodsource
failure_events() -> pd.DataFrame

One interval per failure.

Returns
TypeDescription
DataFrameIntervals start (failure) to end (back in service) with
DataFramerepair_hours (known failed time; data gaps excluded),
DataFrameoperating_hours_before (operating time since the previous
DataFramerepair) and first_observed (True when that operating period
DataFramebegan before the data did, so its length is a lower bound).

mtbf_mttr​

methodsource
mtbf_mttr(window: str | None = None, tz: str | None = None) -> pd.DataFrame

MTBF, MTTR, availability and failure rate.

Parameters
NameTypeDescriptionDefault
windowstr | NoneCalendar window (e.g. "1D", "7D", "MS"); None = one row over the whole observation. A failure belongs to the window it starts in; operating and repair time are split exactly at window boundaries.None
tzstr | NoneTimezone for the window grid (DST-correct day lengths). Default: the data's timezone.None
Returns
TypeDescription
DataFrameSummary rows (start, end, duration_seconds, uuid,
DataFramesource_uuid) with
DataFrameoperating_hours, repair_hours, no_data_hours,
DataFramefailures, mtbf_hours, mtbf_iso22400_hours,
DataFramemttr_hours, availability_pct and
DataFramefailure_rate_per_hour. Ratios with no failures (or no
DataFrameknown time) are NaN.

weibull_fit​

methodsource
weibull_fit(include_initial: bool = False) -> pd.DataFrame

Two-parameter Weibull model of the times between failures.

Fitted by maximum likelihood (scipy.stats.weibull_min, location fixed at 0). The operating period still running at the end of the data is right-censored.

Parameters
NameTypeDescriptionDefault
include_initialboolAlso use the operating time before the first failure as a complete observation. Off by default: that period started before the data did, so the asset's age at the first failure is unknown.False
Returns
TypeDescription
DataFrameOne row: beta (shape), eta_hours (scale: 63.2 % have
DataFramefailed by then), mttf_hours (eta * Gamma(1 + 1/beta)),
DataFrameb10_hours (10 % have failed by then), n_failures /
DataFramefailure_count (failure intervals fitted), n_censored /
DataFramecensored_count (right-censored intervals) and
DataFramefailure_pattern (infant_mortality for beta < 0.9,
DataFramerandom up to 1.1, else wear_out).
DataFrameEmpty when fewer than two failure intervals are available.
DataFrameWhen the times between failures (almost) all have the same
DataFramelength, the model has no finite fit: the parameters are NaN,
DataFramefailure_pattern is "unknown" and a
DataFrameclass:~ts_shape.errors.DataQualityWarning is emitted.
DataFrameCanonical twin columns: failure_count (after n_failures),
DataFramecensored_count (after n_censored); each holds the same
DataFramevalues as the deprecated column right before it, which is removed
DataFramein the next major release.

reliability_at​

methodsource
reliability_at(
hours: Sequence[float],
age_hours: float = 0.0,
include_initial: bool = False,
) -> pd.DataFrame

Reliability and hazard from the fitted Weibull model.

Parameters
NameTypeDescriptionDefault
hoursSequence[float]Operating hours ahead to evaluate.required
age_hoursfloatOperating hours already survived since the last repair. Reliability is then conditional: R(age + t) / R(age) -- "given it has run 200 h, how likely is it to run another 100 h?".0.0
include_initialboolPassed to :meth:weibull_fit.False
Returns
TypeDescription
DataFrameOne row per value of hours: hours, age_hours,
DataFramereliability, failure_probability and
DataFramehazard_per_hour (instantaneous failure rate at age + t).
DataFrameEmpty when there are too few failures to fit; NaN values when
DataFramethe fit is degenerate (see :meth:weibull_fit).