improved logging
This commit is contained in:
@@ -4,6 +4,7 @@ from __future__ import annotations
|
||||
|
||||
from contextlib import suppress
|
||||
from dataclasses import dataclass
|
||||
import logging
|
||||
import time
|
||||
|
||||
import numpy as np
|
||||
@@ -15,13 +16,15 @@ from python_app.models.dataset_model import ComboKey, SweepCollection, TraceData
|
||||
from python_app.models.run_config_model import ComboModel, RunConfigModel
|
||||
from python_app.storage.npz_store import NpzStore, radar_key_from_config
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
MATRIX_RADAR_MANUAL_CAPTURE_KINDS = frozenset({"s21_calibration", "s11_open", "s11_short", "s11_load"})
|
||||
DEFAULT_CALIBRATION_MEDIAN_SWEEP_COUNT = 5
|
||||
|
||||
|
||||
@dataclass(slots=True)
|
||||
class SequentialCaptureState:
|
||||
"""Immutable view of sequential capture progress."""
|
||||
"""Snapshot of sequential capture progress for the GUI/controller."""
|
||||
|
||||
kind: str
|
||||
set_name: str
|
||||
@@ -73,6 +76,15 @@ class SequentialCaptureSession:
|
||||
self._next_index = 0
|
||||
self._opened = False
|
||||
|
||||
logger.info(
|
||||
"Sequential capture session created: kind=%s set=%s combos=%d matrix_radar=%s median_sweeps=%d",
|
||||
self._kind,
|
||||
self._set_name,
|
||||
len(self._combos),
|
||||
self._is_matrix_radar,
|
||||
self._median_sweep_count,
|
||||
)
|
||||
|
||||
if self._is_matrix_radar:
|
||||
self._radar: MatrixRadarService = create_matrix_radar_service(config)
|
||||
self._input_switch = None
|
||||
@@ -124,12 +136,15 @@ class SequentialCaptureSession:
|
||||
self._input_switch.open()
|
||||
if self._output_switch is not None:
|
||||
self._output_switch.open()
|
||||
logger.info("Sequential capture session opened (kind=%s set=%s)", self._kind, self._set_name)
|
||||
except Exception:
|
||||
logger.exception("Failed to open sequential capture session (kind=%s set=%s)", self._kind, self._set_name)
|
||||
self.close()
|
||||
raise
|
||||
|
||||
def close(self) -> None:
|
||||
"""Close all opened hardware resources."""
|
||||
was_open = self._opened
|
||||
with suppress(Exception):
|
||||
if self._output_switch is not None:
|
||||
self._output_switch.close()
|
||||
@@ -139,6 +154,8 @@ class SequentialCaptureSession:
|
||||
with suppress(Exception):
|
||||
self._radar.close()
|
||||
self._opened = False
|
||||
if was_open:
|
||||
logger.info("Sequential capture session closed (kind=%s set=%s)", self._kind, self._set_name)
|
||||
|
||||
def state(self) -> SequentialCaptureState:
|
||||
"""Return current progress snapshot."""
|
||||
@@ -174,11 +191,13 @@ class SequentialCaptureSession:
|
||||
trace = combine_traces_via_median(per_sweep_traces)
|
||||
self._traces.append(trace)
|
||||
self._next_index += 1
|
||||
logger.debug("Captured matrix combo input=%d output=%d", combo.input, combo.output)
|
||||
return trace
|
||||
|
||||
combined_collection = combine_collections_via_median(collections)
|
||||
self._traces.extend(combined_collection.traces)
|
||||
self._next_index = len(self._combos)
|
||||
logger.info("Captured full matrix combo set (%d traces)", len(combined_collection.traces))
|
||||
return combined_collection.traces[-1]
|
||||
|
||||
if self._input_switch is None or self._output_switch is None:
|
||||
@@ -202,6 +221,13 @@ class SequentialCaptureSession:
|
||||
trace = combine_traces_via_median(sweep_traces)
|
||||
self._traces.append(trace)
|
||||
self._next_index += 1
|
||||
logger.debug(
|
||||
"Captured combo input=%d output=%d (%d/%d)",
|
||||
combo.input,
|
||||
combo.output,
|
||||
self._next_index,
|
||||
len(self._combos),
|
||||
)
|
||||
return trace
|
||||
|
||||
def undo_last_capture(self) -> TraceData:
|
||||
@@ -217,6 +243,7 @@ class SequentialCaptureSession:
|
||||
removed_trace = self._traces[-1]
|
||||
self._traces.clear()
|
||||
self._next_index = 0
|
||||
logger.info("Undid matrix combo set capture (kind=%s set=%s)", self._kind, self._set_name)
|
||||
return removed_trace
|
||||
|
||||
expected_combo = self._combos[self._next_index - 1]
|
||||
@@ -228,6 +255,13 @@ class SequentialCaptureSession:
|
||||
raise RuntimeError("Capture session state is inconsistent; last trace does not match rewind combo")
|
||||
self._next_index -= 1
|
||||
self._traces.pop()
|
||||
logger.debug(
|
||||
"Undid combo capture input=%d output=%d (%d/%d remaining)",
|
||||
expected_combo.input,
|
||||
expected_combo.output,
|
||||
self._next_index,
|
||||
len(self._combos),
|
||||
)
|
||||
return removed_trace
|
||||
|
||||
def last_captured_trace(self) -> TraceData | None:
|
||||
@@ -265,6 +299,13 @@ class SequentialCaptureSession:
|
||||
extra_serials=self._config.radar_key_extra_parts() or None,
|
||||
)
|
||||
store.save_set(self._kind, radar_key, self._set_name, collection)
|
||||
logger.info(
|
||||
"Finalized capture set kind=%s set=%s radar_key=%s traces=%d",
|
||||
self._kind,
|
||||
self._set_name,
|
||||
radar_key,
|
||||
len(collection.traces),
|
||||
)
|
||||
return radar_key, collection
|
||||
|
||||
def _current_combo(self) -> ComboModel | None:
|
||||
|
||||
Reference in New Issue
Block a user