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.
| Name | Description |
|---|---|
run_profiler | Run one profiler class and collect its declared tables and summary. |
profile_units | Profile one PLC: the cycle profile plus the requested unit profilers. |
run_profiler
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.
| Name | Type | Description | Default |
|---|---|---|---|
cls | type[_ProfilerBase] | A profiler class (it declares PROFILE_KIND and PROFILE_TABLES). | required |
frame | DataFrame | Prepared long-format signals. | required |
profile | CycleProfileEvents | None | The cycle profile to reuse (passed when the class needs cycles). | None |
**options | Any | Options; those the class names in PROFILE_OPTIONS are passed to its constructor, the rest are ignored. | {} |
| Type | Description |
|---|---|
ProfileResult | class:~ts_shape.events.profiling.result.ProfileResult of kind |
ProfileResult | PROFILE_KIND. |
profile_units
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.
| Name | Type | Description | Default |
|---|---|---|---|
timeseries | DataFrame | Raw frame of a ts-shape timeseries loader (one PLC). | required |
metadata | DataFrame | None | Optional metadata table; labels only. | None |
profilers | Sequence[str] | Names from :data:PROFILERS to run besides the cycle profile (default: all). | DEFAULT_PROFILERS |
plan | DataFrame | None | Optional production plan for the order profiler (order_id, planned_quantity). | None |
exclude | Sequence[str] | Signals to drop (personal data; see :func:~ts_shape.events.profiling.runner.prepare_signals). | DEFAULT_EXCLUDE |
top_n | int | Influencers kept per comparison (cycle profile). | 10 |
**cycle_options | Any | Passed to :class:~ts_shape.CycleProfileEvents. | {} |
| Type | Description |
|---|---|
UnitProfilesResult | class:~ts_shape.events.profiling.result.UnitProfilesResult with |
UnitProfilesResult | results["cycles"] (the :func:~ts_shape.events.profiling.runner.profile_cycles |
UnitProfilesResult | tables) and one result per profiler; summary holds each |
UnitProfilesResult | profiler's headline numbers. |
| Type | Description |
|---|---|
ValueError | For 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']