some webUI fixes

This commit is contained in:
Ayzen
2026-06-10 14:39:25 +03:00
parent c12ae05148
commit 21f76d7cd2
14 changed files with 767 additions and 32 deletions
+37
View File
@@ -33,6 +33,43 @@ def radar_key_from_config(
)
def radar_config_filename_prefix(
model_name: str,
sweep_start_hz: float,
sweep_stop_hz: float,
sweep_points: int,
power_dbm: float,
) -> str:
"""Build a readable, filesystem-safe prefix describing the radar acquisition setup.
Encodes the radar model, sweep frequency span, point count, and power so a saved
dataset's name carries the configuration it was captured with. ADC-mode radars have
no fixed sweep, so the point count is reported as ``adc``.
"""
points_token = "adc" if model_name.strip().lower() == "kamil_adc" else f"{int(sweep_points)}pts"
tokens = (
model_name,
_format_frequency_span(sweep_start_hz, sweep_stop_hz),
points_token,
f"{power_dbm:g}dBm",
)
return sanitize_path_component("_".join(tokens))
def _format_frequency_span(start_hz: float, stop_hz: float) -> str:
"""Format a frequency span compactly, both bounds sharing the larger bound's unit."""
unit, scale = _frequency_unit(max(start_hz, stop_hz))
return f"{start_hz / scale:g}-{stop_hz / scale:g}{unit}"
def _frequency_unit(hz: float) -> tuple[str, float]:
"""Pick the largest unit (GHz/MHz/kHz/Hz) that keeps the magnitude at or above one."""
for unit, scale in (("GHz", 1e9), ("MHz", 1e6), ("kHz", 1e3)):
if hz >= scale:
return unit, scale
return "Hz", 1.0
def collection_dir_name(index: int, collection_id: int, monotonic_ns: int) -> str:
"""Build canonical collection directory name for snapshot stages."""
return f"{index:04d}_id{int(collection_id)}_ns{int(monotonic_ns)}"
+14 -4
View File
@@ -27,6 +27,15 @@ from python_app.storage.store_api import StoreApi
logger = logging.getLogger(__name__)
def _compose_snapshot_stem(name: str, name_prefix: str) -> str:
"""Compose a sanitized snapshot stem from an optional prefix and the operator's name.
The name falls back to a UTC timestamp when blank, so a save is always uniquely named.
"""
base = name.strip() or datetime.now(timezone.utc).strftime("snapshot_%Y%m%d_%H%M%S")
return sanitize_path_component(f"{name_prefix}_{base}" if name_prefix else base)
class NpzStore(StoreApi):
"""Persist preprocess sets and runtime snapshots using NumPy files."""
@@ -193,13 +202,14 @@ class NpzStore(StoreApi):
preprocessed_history: list[SweepCollection],
result_history: list[ResultCollection],
last_n: int,
*,
name_prefix: str = "",
) -> tuple[Path, dict[str, Any]]:
"""Save historical runtime collections in NumPy tree format."""
if last_n <= 0:
raise ValueError("last_n must be > 0")
snapshot_stem = snapshot_name.strip() or datetime.now(timezone.utc).strftime("snapshot_%Y%m%d_%H%M%S")
snapshot_stem = sanitize_path_component(snapshot_stem)
snapshot_stem = _compose_snapshot_stem(snapshot_name, name_prefix)
output_root_dir.mkdir(parents=True, exist_ok=True)
snapshot_dir = output_root_dir / snapshot_stem
@@ -324,13 +334,13 @@ class NpzStore(StoreApi):
*,
channel: str = "s21",
primary_stage: str = "preprocessed",
name_prefix: str = "",
) -> tuple[list[Path], dict[str, Any]]:
"""Save one runtime VNA-history JSON per available combo."""
if last_n <= 0:
raise ValueError("last_n must be > 0")
output_stem = output_name.strip() or datetime.now(timezone.utc).strftime("snapshot_%Y%m%d_%H%M%S")
output_stem = sanitize_path_component(output_stem)
output_stem = _compose_snapshot_stem(output_name, name_prefix)
output_root_dir.mkdir(parents=True, exist_ok=True)
output_dir = self._vna_json_output_dir(output_root_dir, output_stem)
output_dir.mkdir(parents=True, exist_ok=True)