keep sweeps in acquisition order through history replays

The processor appended sweeps the GUI fed back to its own history, so its next replay
published them twice and out of order, and the B-scan came out with rotated columns.
Fed-back sweeps now stay out of that history, results are kept in timestamp order,
picking the displayed combo only redraws and only new sweeps are recorded to disk.
This commit is contained in:
Ayzen
2026-10-02 16:05:32 +03:00
parent 45861f4047
commit d283ecfdf1
11 changed files with 421 additions and 91 deletions
+38 -11
View File
@@ -12,21 +12,48 @@ from python_app.orchestration.preprocess_assets import PREPROCESS_ASSET_KEYS, pr
THistoryCollection = TypeVar("THistoryCollection", SweepCollection, ResultCollection)
def collection_key(collection: SweepCollection | ResultCollection) -> tuple[int, int]:
"""Identity of a sweep through the pipeline: its result keeps the same id and timestamp.
`monotonic_ns` is stamped by `data_preprocessor` on the system monotonic clock, so
it also orders sweeps by acquisition, across runs too (ids restart from 1).
"""
return int(collection.collection_id), int(collection.monotonic_ns)
def record_result_history(
result_history: deque[ResultCollection],
collection: ResultCollection,
) -> None:
"""Append a new result, or replace the existing entry with the same stable key."""
for index in range(len(result_history) - 1, -1, -1):
existing = result_history[index]
if (
existing.collection_id == collection.collection_id
and existing.monotonic_ns == collection.monotonic_ns
):
result_history[index] = collection
return
) -> bool:
"""Record a result, keeping the history in acquisition order; return whether it is new.
result_history.append(collection)
A result of a sweep already present replaces it (the sweep was reprocessed).
Any other result goes after the newest older one: normally at the end, as the
result of a new sweep, but the processor reprocessing its retained sweeps also
delivers sweeps whose first result the GUI missed, and appending those would
show them out of order.
"""
key = collection_key(collection)
position = len(result_history)
while position > 0:
existing = result_history[position - 1]
if collection_key(existing) == key:
result_history[position - 1] = collection
return False
if existing.monotonic_ns < collection.monotonic_ns:
break
position -= 1
if position == len(result_history):
result_history.append(collection)
return True
if len(result_history) == result_history.maxlen:
if position == 0:
return False # older than everything kept, so it would be the first to go
result_history.popleft()
position -= 1
result_history.insert(position, collection)
return False
def remove_last_aligned_histories(