added config load from file
This commit is contained in:
@ -1,9 +1,9 @@
|
||||
{
|
||||
"open_air": true,
|
||||
"axis": "abs",
|
||||
"axis": "real",
|
||||
"cut": 0.727,
|
||||
"max": 2.3,
|
||||
"gain": 0.3,
|
||||
"gain": 0.5,
|
||||
"start_freq": 100.0,
|
||||
"stop_freq": 8800.0,
|
||||
"clear_history": false,
|
||||
|
||||
@ -3,5 +3,6 @@
|
||||
"y_max": 40,
|
||||
"autoscale": true,
|
||||
"show_magnitude": true,
|
||||
"show_phase": false
|
||||
"show_phase": false,
|
||||
"open_air": false
|
||||
}
|
||||
@ -157,16 +157,20 @@ class ProcessorManager:
|
||||
logger.error("Recalculation error", processor_id=processor_id, error=repr(exc))
|
||||
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.
|
||||
|
||||
Also restores the processor configuration (UI parameters) if provided.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
processor_id : str
|
||||
The processor to load history into.
|
||||
history_data : list[dict]
|
||||
History records in the format exported by export_history_data.
|
||||
config : dict[str, Any] | None
|
||||
Processor configuration (UI parameters) to restore.
|
||||
|
||||
Returns
|
||||
-------
|
||||
@ -178,6 +182,11 @@ class ProcessorManager:
|
||||
raise ValueError(f"Processor {processor_id} not found")
|
||||
|
||||
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)
|
||||
result = processor.recalculate()
|
||||
|
||||
|
||||
@ -177,9 +177,12 @@ class ProcessorWebSocketHandler:
|
||||
async def _handle_load_history(self, websocket: WebSocket, message: dict[str, Any]) -> None:
|
||||
"""
|
||||
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")
|
||||
history_data = message.get("history_data")
|
||||
config = message.get("config") # Optional processor configuration
|
||||
|
||||
if not processor_id:
|
||||
await self._send_error(websocket, "Требуется processor_id")
|
||||
@ -190,7 +193,7 @@ class ProcessorWebSocketHandler:
|
||||
return
|
||||
|
||||
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:
|
||||
await websocket.send_text(json.dumps(self._result_to_message(processor_id, result)))
|
||||
else:
|
||||
|
||||
@ -464,8 +464,9 @@ export class ChartManager {
|
||||
const text = await file.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 processorConfig = jsonData.state?.config || null;
|
||||
|
||||
if (!sweepHistory || sweepHistory.length === 0) {
|
||||
this.notifications?.show?.({
|
||||
@ -482,7 +483,8 @@ export class ChartManager {
|
||||
websocket.ws.send(JSON.stringify({
|
||||
type: 'load_history',
|
||||
processor_id: processorId,
|
||||
history_data: sweepHistory
|
||||
history_data: sweepHistory,
|
||||
config: processorConfig
|
||||
}));
|
||||
|
||||
this.notifications?.show?.({
|
||||
|
||||
Reference in New Issue
Block a user