Refactor radar system
This commit is contained in:
@@ -6,6 +6,7 @@ import dataclasses
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
from python_app.models.json_fields import finite_number, json_object as _as_dict
|
||||
from python_app.models.gui_profile_schema import (
|
||||
GuiBscanStateModel,
|
||||
GuiDataActionsStateModel,
|
||||
@@ -24,15 +25,6 @@ from python_app.models.run_config_model import RunConfigModel
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _as_dict(value: Any, context: str) -> dict[str, Any]:
|
||||
"""Validate payload node is object-like, treating missing values as empty object."""
|
||||
if value is None:
|
||||
return {}
|
||||
if not isinstance(value, dict):
|
||||
raise ValueError(f"{context} must be a JSON object")
|
||||
return value
|
||||
|
||||
|
||||
def _optional_string(object_payload: dict[str, Any], key: str, fallback: str, context: str) -> str:
|
||||
"""Return optional string field with type validation."""
|
||||
raw_value = object_payload.get(key, fallback)
|
||||
@@ -59,10 +51,7 @@ def _optional_int(object_payload: dict[str, Any], key: str, fallback: int, conte
|
||||
|
||||
def _optional_float(object_payload: dict[str, Any], key: str, fallback: float, context: str) -> float:
|
||||
"""Return optional numeric field with type validation."""
|
||||
raw_value = object_payload.get(key, fallback)
|
||||
if isinstance(raw_value, bool) or not isinstance(raw_value, (int, float)):
|
||||
raise ValueError(f"{context}.{key} must be a JSON number")
|
||||
return float(raw_value)
|
||||
return finite_number(object_payload.get(key, fallback), f"{context}.{key}")
|
||||
|
||||
|
||||
def _legacy_gpr_mode_from_algorithm(value: str) -> str | None:
|
||||
@@ -533,12 +522,6 @@ def gui_profile_from_dict(payload: dict[str, Any]) -> GuiProfileModel:
|
||||
|
||||
data_actions_object = _as_dict(gui_object.get("data_actions"), "gui.data_actions")
|
||||
gui.data_actions = GuiDataActionsStateModel(
|
||||
save_count=_optional_int(
|
||||
data_actions_object,
|
||||
"save_count",
|
||||
gui.data_actions.save_count,
|
||||
"gui.data_actions",
|
||||
),
|
||||
save_path=_optional_string(
|
||||
data_actions_object,
|
||||
"save_path",
|
||||
@@ -598,102 +581,5 @@ def gui_profile_from_dict(payload: dict[str, Any]) -> GuiProfileModel:
|
||||
def gui_profile_to_dict(model: GuiProfileModel) -> dict[str, Any]:
|
||||
"""Encode :class:`GuiProfileModel` into JSON-serializable dictionary."""
|
||||
payload = model.run_config.to_dict()
|
||||
gui = model.gui if model.gui is not None else GuiStateModel()
|
||||
payload["gui"] = {
|
||||
"version": gui.version,
|
||||
"switches": {
|
||||
"combo_mode": gui.switches.combo_mode,
|
||||
"combos_text": gui.switches.combos_text,
|
||||
"single_input": gui.switches.single_input,
|
||||
"single_output": gui.switches.single_output,
|
||||
},
|
||||
"processing": {
|
||||
"selected_mode": gui.processing.selected_mode,
|
||||
"pass_through": {
|
||||
"show_magnitude": gui.processing.pass_through.show_magnitude,
|
||||
"show_phase": gui.processing.pass_through.show_phase,
|
||||
"unwrap_phase": gui.processing.pass_through.unwrap_phase,
|
||||
"combo_filter": gui.processing.pass_through.combo_filter,
|
||||
"fixed_y_enabled": gui.processing.pass_through.fixed_y_enabled,
|
||||
"y_min_db": gui.processing.pass_through.y_min_db,
|
||||
"y_max_db": gui.processing.pass_through.y_max_db,
|
||||
},
|
||||
"bscan": {
|
||||
"axis": gui.processing.bscan.axis,
|
||||
"cut_m": gui.processing.bscan.cut_m,
|
||||
"max_depth_m": gui.processing.bscan.max_depth_m,
|
||||
"gain": gui.processing.bscan.gain,
|
||||
"start_freq_mhz": gui.processing.bscan.start_freq_mhz,
|
||||
"stop_freq_mhz": gui.processing.bscan.stop_freq_mhz,
|
||||
"subtract_mean_ascan": gui.processing.bscan.subtract_mean_ascan,
|
||||
"history_window_scans": gui.processing.bscan.history_window_scans,
|
||||
},
|
||||
"gpr": {
|
||||
"input_positions": gui.processing.gpr.input_positions,
|
||||
"output_positions": gui.processing.gpr.output_positions,
|
||||
"min_depth_m": gui.processing.gpr.min_depth_m,
|
||||
"max_depth_m": gui.processing.gpr.max_depth_m,
|
||||
"range_comp_power": gui.processing.gpr.range_comp_power,
|
||||
"object_min_frac": gui.processing.gpr.object_min_frac,
|
||||
"score_mode": gui.processing.gpr.score_mode,
|
||||
"motion_mode": gui.processing.gpr.motion_mode,
|
||||
"look_angle_deg": gui.processing.gpr.look_angle_deg,
|
||||
"direction_sign": gui.processing.gpr.direction_sign,
|
||||
"speed_m_s": gui.processing.gpr.speed_m_s,
|
||||
"ignore_socket_speed_enabled": gui.processing.gpr.ignore_socket_speed_enabled,
|
||||
"max_detected_objects_to_draw": gui.processing.gpr.max_detected_objects_to_draw,
|
||||
"draw_top_m_objects": gui.processing.gpr.draw_top_m_objects,
|
||||
"object_approach_min_frames": gui.processing.gpr.object_approach_min_frames,
|
||||
"start_freq_mhz": gui.processing.gpr.start_freq_mhz,
|
||||
"stop_freq_mhz": gui.processing.gpr.stop_freq_mhz,
|
||||
"background_subtract_enabled": gui.processing.gpr.background_subtract_enabled,
|
||||
"background_mean_count": gui.processing.gpr.background_mean_count,
|
||||
"remove_sidelobe_objects_enabled": gui.processing.gpr.remove_sidelobe_objects_enabled,
|
||||
"imaging_plane_y_m": gui.processing.gpr.imaging_plane_y_m,
|
||||
"render_mode": gui.processing.gpr.render_mode,
|
||||
"visible_x_min_m": gui.processing.gpr.visible_x_min_m,
|
||||
"visible_x_max_m": gui.processing.gpr.visible_x_max_m,
|
||||
"visible_z_min_m": gui.processing.gpr.visible_z_min_m,
|
||||
"visible_z_max_m": gui.processing.gpr.visible_z_max_m,
|
||||
},
|
||||
"legacy_gpr": {
|
||||
"mode": gui.processing.legacy_gpr.mode,
|
||||
"input_positions": gui.processing.legacy_gpr.input_positions,
|
||||
"output_positions": gui.processing.legacy_gpr.output_positions,
|
||||
"min_depth_m": gui.processing.legacy_gpr.min_depth_m,
|
||||
"max_depth_m": gui.processing.legacy_gpr.max_depth_m,
|
||||
"comp_power": gui.processing.legacy_gpr.comp_power,
|
||||
"start_freq_mhz": gui.processing.legacy_gpr.start_freq_mhz,
|
||||
"stop_freq_mhz": gui.processing.legacy_gpr.stop_freq_mhz,
|
||||
"speed_m_s": gui.processing.legacy_gpr.speed_m_s,
|
||||
"ignore_socket_speed_enabled": gui.processing.legacy_gpr.ignore_socket_speed_enabled,
|
||||
"look_angle_deg": gui.processing.legacy_gpr.look_angle_deg,
|
||||
"apply_freq_phase_correction": gui.processing.legacy_gpr.apply_freq_phase_correction,
|
||||
"reference_mode": gui.processing.legacy_gpr.reference_mode,
|
||||
"snr_thresh": gui.processing.legacy_gpr.snr_thresh,
|
||||
"snr_comp_max": gui.processing.legacy_gpr.snr_comp_max,
|
||||
"background_subtract_enabled": gui.processing.legacy_gpr.background_subtract_enabled,
|
||||
"background_mean_count": gui.processing.legacy_gpr.background_mean_count,
|
||||
"render_mode": gui.processing.legacy_gpr.render_mode,
|
||||
"min_visible_pair_count": gui.processing.legacy_gpr.min_visible_pair_count,
|
||||
"visible_x_min_m": gui.processing.legacy_gpr.visible_x_min_m,
|
||||
"visible_x_max_m": gui.processing.legacy_gpr.visible_x_max_m,
|
||||
"visible_z_min_m": gui.processing.legacy_gpr.visible_z_min_m,
|
||||
"visible_z_max_m": gui.processing.legacy_gpr.visible_z_max_m,
|
||||
},
|
||||
"sar3d": dataclasses.asdict(gui.processing.sar3d),
|
||||
},
|
||||
"data_actions": {
|
||||
"save_count": gui.data_actions.save_count,
|
||||
"save_path": gui.data_actions.save_path,
|
||||
"save_name": gui.data_actions.save_name,
|
||||
"record_count": gui.data_actions.record_count,
|
||||
},
|
||||
"preprocess_dialog": {
|
||||
"set_name": gui.preprocess_dialog.set_name,
|
||||
"radar_config_dir": gui.preprocess_dialog.radar_config_dir,
|
||||
"use_all_radar_configs": gui.preprocess_dialog.use_all_radar_configs,
|
||||
"median_sweep_count": gui.preprocess_dialog.median_sweep_count,
|
||||
},
|
||||
}
|
||||
payload["gui"] = dataclasses.asdict(model.gui if model.gui is not None else GuiStateModel())
|
||||
return payload
|
||||
|
||||
Reference in New Issue
Block a user