ts_shape.events.profiling.handshakes
Mapping-free handshake profiling: who makes the machine wait?
:class:HandshakeProfileEvents finds request / acknowledge pairs between the
boolean signals of one PLC without being told which signal talks to which:
an edge A that is (almost) always answered by an edge B of another
signal before A happens again, and B (almost) never comes without a
preceding A -- robot_ready↑ → press_open↑, req_conveyor↑ → ack_conveyor↑. Per pair:
- the waiting time of every occurrence and its register (median, P10, P90, potential = median - P10);
pair_kind:four_phasewhen the full request/acknowledge protocol is seen (A↑ → B↑ → A↓ → B↓), elsetwo_phase;waits_on:partnerwhen the answer time varies (someone else decides when to answer),fixedwhen it is a constant delay (a timer or a fixed sequence in the same program);- with cycles: the share of the cycle the wait takes and how much of the cycle time variance it explains.
An answer logged at the same timestamp as its request is not counted: on polled data a handshake faster than the poll cannot be told from two signals written in the same scan, and its wait cannot be measured.
| Name | Description |
|---|---|
HandshakeProfileEvents | Request / acknowledge pairs and the time spent waiting on them. |
HandshakeProfileEvents
HandshakeProfileEvents(
dataframe: pd.DataFrame,
*,
cycle_profile: CycleProfileEvents | None = None,
signal_uuids: list[str] | None = None,
min_follow_ratio: float = MIN_FOLLOW_RATIO,
min_occurrences: int = 30,
time_column: str = "systime",
uuid_column: str = "uuid",
event_uuid: str = "prod:handshake_profile",
**cycle_options: Any
) -> None
Bases: _UnitProfiler
Request / acknowledge pairs and the time spent waiting on them.
Example
>>> import ts_shape
>>> frame, truth = ts_shape.make_plc_cycles(
... n_cycles=300, seed=1, handshake_partner=True)
>>> pairs = ts_shape.HandshakeProfileEvents(frame).handshake_pairs()
>>> "plc:req_conveyor↑ → plc:ack_conveyor↑" in set(pairs["pair"])
True
| Name | Description |
|---|---|
handshake_pairs | The request / answer pairs found, with their evidence. |
handshake_records | One interval per answered request. |
handshake_register | What each handshake wait costs, linked to the cycle. |
evaluation_window | Whether each pair can be trusted, and why not. |
summary | Headline numbers (JSON-able). |
| Name | Type | Description | Default |
|---|---|---|---|
dataframe | DataFrame | Long-format signals of one PLC. | required |
cycle_profile | CycleProfileEvents | None | A computed cycle profile of the same signals to reuse; None (default) builds one. | None |
signal_uuids | list[str] | None | Signals to use (default: all). | None |
min_follow_ratio | float | A request must be answered, and an answer preceded by a request, at least this often. | MIN_FOLLOW_RATIO |
min_occurrences | int | Edges seen fewer times are not candidates; a pair with fewer occurrences is not evaluable. | 30 |
time_column | str | Timestamp column. | 'systime' |
uuid_column | str | Signal column. | 'uuid' |
event_uuid | str | uuid of the handshake records. | 'prod:handshake_profile' |
**cycle_options | Any | Options of the cycle profile built when cycle_profile is None. | {} |
handshake_pairs
handshake_pairs() -> pd.DataFrame
The request / answer pairs found, with their evidence.
| Type | Description |
|---|---|
DataFrame | One row per pair: pair ("<request> → <answer>"), |
DataFrame | request, answer, request_uuid, answer_uuid, |
DataFrame | pair_kind (four_phase / two_phase), |
DataFrame | occurrence_count, follow_ratio, precede_ratio, |
DataFrame | median_delay_seconds and waits_on (partner for a |
DataFrame | varying answer time, fixed for a constant delay). |
handshake_records
handshake_records() -> pd.DataFrame
One interval per answered request.
| Name | Type | Description |
|---|---|---|
Intervals | DataFrame | start (request), end (answer), |
DataFrame | duration_seconds (the wait), uuid, source_uuid (the | |
DataFrame | answering signal), pair. |
handshake_register
handshake_register() -> pd.DataFrame
What each handshake wait costs, linked to the cycle.
| Type | Description |
|---|---|
DataFrame | func:~ts_shape.events.profiling._base.potential_register |
DataFrame | of the waits per pair plus pair_kind, waits_on, |
DataFrame | cycle_share_ratio (median wait / median cycle), |
DataFrame | cycle_spearman_factor (rank correlation of the wait with the |
DataFrame | duration of its cycle) and variance_contribution_factor |
DataFrame | (cov(wait, cycle) / var(cycle) over the normal cycles). |
evaluation_window
evaluation_window() -> pd.DataFrame
Whether each pair can be trusted, and why not.
| Type | Description |
|---|---|
DataFrame | One row per pair (scope = the pair; one all row when none |
DataFrame | is found): unit_count (answered requests), evaluable, |
DataFrame | reason (below_resolution when the median wait is shorter |
DataFrame | than twice the time resolution) and time_resolution_seconds. |
summary
summary() -> dict[str, Any]
Headline numbers (JSON-able).
| Type | Description |
|---|---|
dict[str, Any] | evaluable (any pair evaluable), reason, pair_count, |
dict[str, Any] | partner_pair_count and top_wait_pair (the partner pair |
dict[str, Any] | with the largest total potential, four-phase pairs first). |