Skip to main content
Version: Next

ts_shape.events.profiling.orders

Mapping-free order and scrap profiling.

On top of the cycle profile of one PLC (:class:~ts_shape.events.profiling.cycles.CycleProfileEvents):

:func:counter_roles Which counter is the total, the good and the bad count -- learned from the identity good + bad = total per cycle (a lag of up to :data:COUNTER_MAX_LAG_CYCLES cycles allowed), not from names. Equal counters are aliases; a counter with non-integer increments is energy-like (a meter).

:class:OrderProfileEvents Which orders run slow or scrap the most? The order signal is found with :func:~ts_shape.signals.identify.identify_objects (an identifier held over many cycles), else the variant signal. Per order: cycles, run and stop time, speed against the variant's best, good and bad parts and, with a plan, the attainment.

:class:ScrapProfileEvents What precedes a bad part? -- a scrap Pareto without reason codes. Every cycle with a bad-counter increment is a NOK unit; its context (a stop in the cycle, after a stop, after a changeover, a long cycle, an analog deviation, and every rare discrete event in the cycle) is compared with the context of good cycles by enrichment.

Classes
NameDescription
OrderProfileEventsProduction orders: setup, speed against the best, scrap, attainment.
ScrapProfileEventsWhat precedes a bad part: a scrap Pareto without reason codes.

OrderProfileEvents​

classsource
OrderProfileEvents(
dataframe: pd.DataFrame,
*,
cycle_profile: CycleProfileEvents | None = None,
signal_uuids: list[str] | None = None,
plan: pd.DataFrame | None = None,
order_uuid: str | None = None,
min_orders: int = 3,
time_column: str = "systime",
uuid_column: str = "uuid",
event_uuid: str = "prod:order_profile",
**cycle_options: Any
) -> None

Bases: _CounterMixin

Production orders: setup, speed against the best, scrap, attainment.

Example
>>> import ts_shape
>>> frame, truth = ts_shape.make_plc_cycles(
... n_cycles=300, seed=2, order_size=25, scrap_probability=0.03)
>>> orders = ts_shape.OrderProfileEvents(frame)
>>> orders.evaluation_window()["order_uuid"].iloc[0]
'plc:order_no'
Functions
NameDescription
order_recordsOne record per order.
counter_rolesRoles of the counters (total, good, bad ...) learned from the data.
order_registerOrders ranked by lost time, per variant.
evaluation_windowWhether the order profile can be trusted, and why not.
summaryHeadline numbers (JSON-able).
Parameters
NameTypeDescriptionDefault
dataframeDataFrameLong-format signals of one PLC.required
cycle_profileCycleProfileEvents | NoneA computed cycle profile of the same signals to reuse; None (default) builds one.None
signal_uuidslist[str] | NoneSignals to use (default: all).None
planDataFrame | NoneOptional plan with order_id and planned_quantity; adds planned_quantity and attainment_ratio.None
order_uuidstr | NoneThe order signal; None (default) finds it (an identifier held over many cycles, else the variant signal).None
min_ordersintFewer orders are not evaluable.3
time_columnstrTimestamp column.'systime'
uuid_columnstrSignal column.'uuid'
event_uuidstruuid of the order records.'prod:order_profile'
**cycle_optionsAnyOptions of the cycle profile built when cycle_profile is None.{}

order_records​

methodsource
order_records() -> pd.DataFrame

One record per order.

Returns
TypeDescription
DataFramePoint events at the order end: systime, uuid,
DataFramesource_uuid (the order signal), unit_uuid (the order id),
DataFramestart_ns, end_ns, duration_seconds, variant,
DataFramecycle_count, run_seconds (non-pause cycles),
DataFramestop_seconds (pause cycles), median_cycle_seconds,
DataFramespeed_ratio (variant's best cycle / the order's median),
DataFrameloss_seconds (cycle time beyond the variant's best, pause
DataFramecycles included), good_count, scrap_count,
DataFramescrap_ratio and, with a plan, planned_quantity and
DataFrameattainment_ratio.

counter_roles​

methodsource
counter_roles() -> pd.DataFrame

Roles of the counters (total, good, bad ...) learned from the data.

Returns
NameTypeDescription
SeeDataFramefunc:~ts_shape.events.profiling._counters.counter_roles.

order_register​

methodsource
order_register() -> pd.DataFrame

Orders ranked by lost time, per variant.

Returns
TypeDescription
DataFramefunc:~ts_shape.events.profiling._base.potential_register
DataFrameof the orders' loss_seconds per variant, plus
DataFramescrap_count and worst_order (the order with the most loss).

evaluation_window​

methodsource
evaluation_window() -> pd.DataFrame

Whether the order profile can be trusted, and why not.

Returns
TypeDescription
DataFrameOne row: scope, unit_count (orders), evaluable,
DataFramereason (no_candidate_signal: order id without an order
DataFrameor variant signal), time_resolution_seconds, order_uuid
DataFrameand order_source (given, identifier or variant).

summary​

methodsource
summary() -> dict[str, Any]

Headline numbers (JSON-able).

Returns
TypeDescription
dict[str, Any]evaluable, reason, order_count, order_uuid,
dict[str, Any]worst_order, worst_order_loss_hours and scrap_count.

ScrapProfileEvents​

classsource
ScrapProfileEvents(
dataframe: pd.DataFrame,
*,
cycle_profile: CycleProfileEvents | None = None,
signal_uuids: list[str] | None = None,
bad_uuid: str | None = None,
min_nok: int = 10,
time_column: str = "systime",
uuid_column: str = "uuid",
event_uuid: str = "prod:scrap_profile",
**cycle_options: Any
) -> None

Bases: _CounterMixin

What precedes a bad part: a scrap Pareto without reason codes.

Example
>>> import ts_shape
>>> frame, truth = ts_shape.make_plc_cycles(
... n_cycles=600, seed=4, scrap_probability=0.02, rampup_cycles=4,
... curve_faults={"late_rise": 0.05})
>>> scrap = ts_shape.ScrapProfileEvents(frame)
>>> scrap.evaluation_window()["bad_uuid"].iloc[0]
'plc:bad_counter'
Functions
NameDescription
nok_recordsOne record per cycle with a bad part.
counter_rolesRoles of the counters (total, good, bad ...) learned from the data.
scrap_paretoScrap contexts ranked: where bad parts are over-represented.
evaluation_windowWhether the scrap profile can be trusted, and why not.
summaryHeadline numbers (JSON-able).
Parameters
NameTypeDescriptionDefault
dataframeDataFrameLong-format signals of one PLC.required
cycle_profileCycleProfileEvents | NoneA computed cycle profile of the same signals to reuse; None (default) builds one.None
signal_uuidslist[str] | NoneSignals to use (default: all).None
bad_uuidstr | NoneThe bad-part counter; None (default) learns it (:func:counter_roles).None
min_nokintFewer cycles with a bad part are not evaluable.10
time_columnstrTimestamp column.'systime'
uuid_columnstrSignal column.'uuid'
event_uuidstruuid of the NOK records.'prod:scrap_profile'
**cycle_optionsAnyOptions of the cycle profile built when cycle_profile is None.{}

nok_records​

methodsource
nok_records() -> pd.DataFrame

One record per cycle with a bad part.

Returns
TypeDescription
DataFramePoint events at the cycle end: systime, uuid,
DataFramesource_uuid (the bad counter), unit_uuid (the cycle),
DataFramestart_ns, end_ns, duration_seconds, variant,
DataFramecycle_class, bad_count, context (every context label,
DataFrame;-joined) and assigned_context (the significant context
DataFramewith the highest lift, or unexplained).

counter_roles​

methodsource
counter_roles() -> pd.DataFrame

Roles of the counters (total, good, bad ...) learned from the data.

Returns
NameTypeDescription
SeeDataFramefunc:~ts_shape.events.profiling._counters.counter_roles.

scrap_pareto​

methodsource
scrap_pareto() -> pd.DataFrame

Scrap contexts ranked: where bad parts are over-represented.

Returns
TypeDescription
DataFrameOne row per context (stop_in_cycle, after_stop,
DataFrameafter_changeover, long_cycle, short_cycle,
DataFramedeviation <signal>:<stat>, curve <signal> (a curve-shape
DataFrameanomaly of the cycle profile), event <label>): context,
DataFramenok_count (bad cycles with it), nok_share_ratio,
DataFramerate_in_context_ratio (bad-cycle rate with the context),
DataFramerate_outside_ratio, lift_factor, p_value,
DataFrameq_value and is_significant (q < 0.05, lift >= 2),
DataFramesignificant contexts first by lift.

evaluation_window​

methodsource
evaluation_window() -> pd.DataFrame

Whether the scrap profile can be trusted, and why not.

Returns
TypeDescription
DataFrameOne row: scope (scrap), unit_count (cycles with a bad
DataFramepart), evaluable, reason (``no_candidate_signal: bad
DataFramecounterwithout one),time_resolution_seconds, bad_uuid``
DataFrameand explained_share_ratio (bad cycles with a significant
DataFramecontext).

summary​

methodsource
summary() -> dict[str, Any]

Headline numbers (JSON-able).

Returns
TypeDescription
dict[str, Any]evaluable, reason, nok_cycle_count, bad_uuid,
dict[str, Any]top_context (the significant context with most bad cycles)
dict[str, Any]and explained_share_ratio.