|
| 1 | +Settle Detection Over a Churn Series |
| 2 | +==================================== |
| 3 | + |
| 4 | +``smart_waits.wait_until_screen_stable`` and ``actionability``'s stability check bake the |
| 5 | +settle logic *inside* a ``time.sleep`` polling loop over live pixel frames — you cannot feed |
| 6 | +them a recorded series of a11y-element counts or screen-diff metrics, and you cannot unit-test |
| 7 | +the *decision* independently of capture. ``settle_detector`` extracts that decision: it takes a |
| 8 | +stream of *churn* values (how much changed each sample — a pixel delta, an element-count delta, |
| 9 | +a digest-changed 0/1, anything) and reports when the churn has stayed at or below ``max_churn`` |
| 10 | +for ``quiet_samples`` in a row. A spike resets the quiet run, so "settled then changed again" |
| 11 | +is handled. |
| 12 | + |
| 13 | +Pure-stdlib; deterministic and unit-testable on an injected series with no capture and no |
| 14 | +clock. Imports no ``PySide6``. |
| 15 | + |
| 16 | +Headless API |
| 17 | +------------ |
| 18 | + |
| 19 | +.. code-block:: python |
| 20 | +
|
| 21 | + from je_auto_control import settle_point, is_settled, SettleTracker |
| 22 | +
|
| 23 | + churns = [5, 4, 0.5, 0.3, 0.2] # per-frame change metric |
| 24 | + settle_point(churns, quiet_samples=3, max_churn=1.0) # -> 4 |
| 25 | + is_settled(churns, quiet_samples=3, max_churn=1.0) # -> True |
| 26 | +
|
| 27 | + # incremental, for a live loop (you supply the churn each tick) |
| 28 | + tracker = SettleTracker(quiet_samples=3, max_churn=1.0) |
| 29 | + state = tracker.update(current_churn) |
| 30 | + if state.settled: |
| 31 | + observe_now() |
| 32 | +
|
| 33 | +``settle_point`` returns the index at which the series first settles (or ``None``); |
| 34 | +``is_settled`` is the boolean. ``SettleTracker`` is the incremental form: ``update(churn)`` |
| 35 | +returns a ``SettleState`` (``settled`` / ``quiet_run`` / ``churn``); ``reset`` clears the run |
| 36 | +(e.g. right after acting again). |
| 37 | + |
| 38 | +Executor command |
| 39 | +---------------- |
| 40 | + |
| 41 | +``AC_settle_point`` (``churns`` / ``quiet_samples`` / ``max_churn`` → ``{settled, index}``) is |
| 42 | +exposed as the MCP tool ``ac_settle_point`` (read-only) and as the Script Builder command |
| 43 | +**Settle Point (churn series)** under **Flow**. |
0 commit comments