Skip to main content
Version: 0.0.98

ts_shape.events.profiling.units

Run the cycle profile and the mapping-free unit profilers in one go.

:func:profile_units prepares the signals of one PLC once (:func:ts_shape.events.profiling.runner.prepare_signals), computes the cycle profile once, and runs every requested unit profiler on top of it -- stops, changeovers, start-ups, orders, scrap, handshakes, curve signatures, setting changes and control loops. Each profiler's tables and summary land in one :class:~ts_shape.events.profiling.result.ProfileResult; the :class:~ts_shape.events.profiling.result.UnitProfilesResult collects them and says, per profiler, whether it is evaluable and why not.

The profilers are not listed here: every class that declares PROFILE_KIND (see :class:~ts_shape.events.profiling._base. _ProfilerBase) is found, with the tables it names in PROFILE_TABLES.

Functions
NameDescription
run_profilerRun one profiler class and collect its declared tables and summary.
profile_unitsProfile one PLC: the cycle profile plus the requested unit profilers.

run_profiler​

functionsource
run_profiler(
cls: type[_ProfilerBase],
frame: pd.DataFrame,
profile: CycleProfileEvents | None = None,
**options: Any
) -> ProfileResult

Run one profiler class and collect its declared tables and summary.

Parameters
NameTypeDescriptionDefault
clstype[_ProfilerBase]A profiler class (it declares PROFILE_KIND and PROFILE_TABLES).required
frameDataFramePrepared long-format signals.required
profileCycleProfileEvents | NoneThe cycle profile to reuse (passed when the class needs cycles).None
**optionsAnyOptions; those the class names in PROFILE_OPTIONS are passed to its constructor, the rest are ignored.{}
Returns
TypeDescription
ProfileResultclass:~ts_shape.events.profiling.result.ProfileResult of kind
ProfileResultPROFILE_KIND.

profile_units​

functionsource
profile_units(
timeseries: pd.DataFrame,
metadata: pd.DataFrame | None = None,
*,
profilers: Sequence[str] = DEFAULT_PROFILERS,
plan: pd.DataFrame | None = None,
exclude: Sequence[str] = DEFAULT_EXCLUDE,
top_n: int = 10,
**cycle_options: Any
) -> UnitProfilesResult

Profile one PLC: the cycle profile plus the requested unit profilers.

A profiler that fails is reported (evaluable False, reason error: ...) instead of stopping the others.

Parameters
NameTypeDescriptionDefault
timeseriesDataFrameRaw frame of a ts-shape timeseries loader (one PLC).required
metadataDataFrame | NoneOptional metadata table; labels only.None
profilersSequence[str]Names from :data:PROFILERS to run besides the cycle profile (default: all).DEFAULT_PROFILERS
planDataFrame | NoneOptional production plan for the order profiler (order_id, planned_quantity).None
excludeSequence[str]Signals to drop (personal data; see :func:~ts_shape.events.profiling.runner.prepare_signals).DEFAULT_EXCLUDE
top_nintInfluencers kept per comparison (cycle profile).10
**cycle_optionsAnyPassed to :class:~ts_shape.CycleProfileEvents.{}
Returns
TypeDescription
UnitProfilesResultclass:~ts_shape.events.profiling.result.UnitProfilesResult with
UnitProfilesResultresults["cycles"] (the :func:~ts_shape.events.profiling.runner.profile_cycles
UnitProfilesResulttables) and one result per profiler; summary holds each
UnitProfilesResultprofiler's headline numbers.
Raises
TypeDescription
ValueErrorFor an unknown profiler name.
Example
>>> import ts_shape
>>> from ts_shape.events.profiling.units import profile_units
>>> frame, _ = ts_shape.make_plc_cycles(
... n_cycles=300, seed=3, stop_causes=4, stop_probability=0.08)
>>> result = profile_units(frame, profilers=["stops"])
>>> sorted(result.results)
['cycles', 'stops']