fixed serialize problem
This commit is contained in:
@ -562,6 +562,26 @@ class BaseProcessor:
|
|||||||
# --------------------------------------------------------------------- #
|
# --------------------------------------------------------------------- #
|
||||||
# History Export/Import
|
# History Export/Import
|
||||||
# --------------------------------------------------------------------- #
|
# --------------------------------------------------------------------- #
|
||||||
|
def _make_json_serializable(self, obj: Any) -> Any:
|
||||||
|
"""
|
||||||
|
Recursively convert non-serializable objects to JSON-compatible types.
|
||||||
|
|
||||||
|
Handles Enums, custom objects, etc.
|
||||||
|
"""
|
||||||
|
from enum import Enum
|
||||||
|
|
||||||
|
if isinstance(obj, Enum):
|
||||||
|
return obj.value
|
||||||
|
elif isinstance(obj, dict):
|
||||||
|
return {key: self._make_json_serializable(value) for key, value in obj.items()}
|
||||||
|
elif isinstance(obj, (list, tuple)):
|
||||||
|
return [self._make_json_serializable(item) for item in obj]
|
||||||
|
elif hasattr(obj, '__dict__'):
|
||||||
|
# Custom object - try to serialize its dict
|
||||||
|
return self._make_json_serializable(obj.__dict__)
|
||||||
|
else:
|
||||||
|
return obj
|
||||||
|
|
||||||
def export_history_data(self) -> list[dict[str, Any]]:
|
def export_history_data(self) -> list[dict[str, Any]]:
|
||||||
"""
|
"""
|
||||||
Export sweep history in JSON-serializable format.
|
Export sweep history in JSON-serializable format.
|
||||||
@ -578,13 +598,16 @@ class BaseProcessor:
|
|||||||
calibrated_data = entry["calibrated_data"]
|
calibrated_data = entry["calibrated_data"]
|
||||||
reference_data = entry.get("reference_data")
|
reference_data = entry.get("reference_data")
|
||||||
|
|
||||||
|
# Convert vna_config to fully serializable format
|
||||||
|
vna_config = self._make_json_serializable(entry.get("vna_config", {}))
|
||||||
|
|
||||||
exported.append({
|
exported.append({
|
||||||
"sweep_number": sweep_data.sweep_number if sweep_data else None,
|
"sweep_number": sweep_data.sweep_number if sweep_data else None,
|
||||||
"timestamp": entry.get("timestamp"),
|
"timestamp": entry.get("timestamp"),
|
||||||
"sweep_points": sweep_data.points if sweep_data else [],
|
"sweep_points": sweep_data.points if sweep_data else [],
|
||||||
"calibrated_points": calibrated_data.points if calibrated_data else [],
|
"calibrated_points": calibrated_data.points if calibrated_data else [],
|
||||||
"reference_points": reference_data.points if reference_data else [],
|
"reference_points": reference_data.points if reference_data else [],
|
||||||
"vna_config": entry.get("vna_config", {}),
|
"vna_config": vna_config,
|
||||||
})
|
})
|
||||||
|
|
||||||
return exported
|
return exported
|
||||||
|
|||||||
Reference in New Issue
Block a user