added config load from file

This commit is contained in:
ayzen
2025-10-16 20:22:14 +03:00
parent 798bec107d
commit 52b0af79e4
5 changed files with 22 additions and 7 deletions

View File

@ -1,9 +1,9 @@
{ {
"open_air": true, "open_air": true,
"axis": "abs", "axis": "real",
"cut": 0.727, "cut": 0.727,
"max": 2.3, "max": 2.3,
"gain": 0.3, "gain": 0.5,
"start_freq": 100.0, "start_freq": 100.0,
"stop_freq": 8800.0, "stop_freq": 8800.0,
"clear_history": false, "clear_history": false,

View File

@ -3,5 +3,6 @@
"y_max": 40, "y_max": 40,
"autoscale": true, "autoscale": true,
"show_magnitude": true, "show_magnitude": true,
"show_phase": false "show_phase": false,
"open_air": false
} }

View File

@ -157,16 +157,20 @@ class ProcessorManager:
logger.error("Recalculation error", processor_id=processor_id, error=repr(exc)) logger.error("Recalculation error", processor_id=processor_id, error=repr(exc))
raise raise
def load_processor_history(self, processor_id: str, history_data: list[dict[str, Any]]) -> ProcessedResult | None: def load_processor_history(self, processor_id: str, history_data: list[dict[str, Any]], config: dict[str, Any] | None = None) -> ProcessedResult | None:
""" """
Load sweep history into a processor from JSON data and recalculate. Load sweep history into a processor from JSON data and recalculate.
Also restores the processor configuration (UI parameters) if provided.
Parameters Parameters
---------- ----------
processor_id : str processor_id : str
The processor to load history into. The processor to load history into.
history_data : list[dict] history_data : list[dict]
History records in the format exported by export_history_data. History records in the format exported by export_history_data.
config : dict[str, Any] | None
Processor configuration (UI parameters) to restore.
Returns Returns
------- -------
@ -178,6 +182,11 @@ class ProcessorManager:
raise ValueError(f"Processor {processor_id} not found") raise ValueError(f"Processor {processor_id} not found")
try: try:
# Restore processor configuration first if provided
if config:
processor.update_config(config)
logger.info("Processor config restored", processor_id=processor_id, config_keys=list(config.keys()))
processor.import_history_data(history_data) processor.import_history_data(history_data)
result = processor.recalculate() result = processor.recalculate()

View File

@ -177,9 +177,12 @@ class ProcessorWebSocketHandler:
async def _handle_load_history(self, websocket: WebSocket, message: dict[str, Any]) -> None: async def _handle_load_history(self, websocket: WebSocket, message: dict[str, Any]) -> None:
""" """
Load sweep history from JSON data into a processor and recalculate. Load sweep history from JSON data into a processor and recalculate.
Also restores processor configuration (UI parameters) if provided.
""" """
processor_id = message.get("processor_id") processor_id = message.get("processor_id")
history_data = message.get("history_data") history_data = message.get("history_data")
config = message.get("config") # Optional processor configuration
if not processor_id: if not processor_id:
await self._send_error(websocket, "Требуется processor_id") await self._send_error(websocket, "Требуется processor_id")
@ -190,7 +193,7 @@ class ProcessorWebSocketHandler:
return return
try: try:
result = self.processor_manager.load_processor_history(processor_id, history_data) result = self.processor_manager.load_processor_history(processor_id, history_data, config)
if result: if result:
await websocket.send_text(json.dumps(self._result_to_message(processor_id, result))) await websocket.send_text(json.dumps(self._result_to_message(processor_id, result)))
else: else:

View File

@ -464,8 +464,9 @@ export class ChartManager {
const text = await file.text(); const text = await file.text();
const jsonData = JSON.parse(text); const jsonData = JSON.parse(text);
// Extract sweep_history from the saved JSON file // Extract sweep_history and processor config from the saved JSON file
const sweepHistory = jsonData.sweep_history || []; const sweepHistory = jsonData.sweep_history || [];
const processorConfig = jsonData.state?.config || null;
if (!sweepHistory || sweepHistory.length === 0) { if (!sweepHistory || sweepHistory.length === 0) {
this.notifications?.show?.({ this.notifications?.show?.({
@ -482,7 +483,8 @@ export class ChartManager {
websocket.ws.send(JSON.stringify({ websocket.ws.send(JSON.stringify({
type: 'load_history', type: 'load_history',
processor_id: processorId, processor_id: processorId,
history_data: sweepHistory history_data: sweepHistory,
config: processorConfig
})); }));
this.notifications?.show?.({ this.notifications?.show?.({