model.util.export_json ====================== .. py:module:: model.util.export_json .. autoapi-nested-parse:: Utility script to export a scenario to a JSON file. This script exports eflips-model database data to a JSON format compatible with django-simba imports. It handles serialization of SQLAlchemy objects including geometry types, enums, datetimes, and relationships. Attributes ---------- .. autoapisummary:: model.util.export_json.MODEL_NAME_MAPPING model.util.export_json.FIELD_DEFAULTS model.util.export_json.EXTRA_FIELDS model.util.export_json.COMPUTED_FIELDS Functions --------- .. autoapisummary:: model.util.export_json.get_foreign_key_columns model.util.export_json.convert_geometry_to_3d model.util.export_json.serialize_value model.util.export_json.get_many_to_many_relationships model.util.export_json.serialize_object model.util.export_json.export_scenario_to_json model.util.export_json.list_scenarios model.util.export_json.main Module Contents --------------- .. py:data:: MODEL_NAME_MAPPING :type: dict[str, str] .. py:data:: FIELD_DEFAULTS :type: dict[str, dict[str, Any]] .. py:data:: EXTRA_FIELDS :type: dict[str, dict[str, Any]] .. py:data:: COMPUTED_FIELDS :type: dict[str, dict[str, Callable[[dict[str, Any]], Any]]] .. py:function:: get_foreign_key_columns(mapper) Get column names that are foreign keys (with _id suffix). Args: mapper: SQLAlchemy mapper for the class Returns: Set of column names that are foreign keys .. py:function:: convert_geometry_to_3d(wkt) Convert a 2D WKT geometry string to 3D with Z=0. Examples: POINT(13.19 52.69) -> POINT Z (13.19 52.69 0) LINESTRING(13.19 52.69, 13.20 52.70) -> LINESTRING Z (13.19 52.69 0, 13.20 52.70 0) POLYGON((13.19 52.69, ...)) -> POLYGON Z ((13.19 52.69 0, ...)) .. py:function:: serialize_value(value) Serialize a single value based on its type. Args: value: The value to serialize Returns: A JSON-serializable representation of the value .. py:function:: get_many_to_many_relationships(obj) Get many-to-many relationship data as lists of IDs. Args: obj: An SQLAlchemy object Returns: A dict mapping relationship names to lists of related object IDs .. py:function:: serialize_object(obj) Serialize an SQLAlchemy object to a dict. Foreign key columns have their _id suffix stripped to match django-simba's expected format (e.g., scenario_id -> scenario). Some non-FK columns like manager_id are also treated as references. Args: obj: An SQLAlchemy object Returns: A JSON-serializable dict representation of the object .. py:function:: export_scenario_to_json(scenario_id, session) Export a scenario and all related objects to a JSON-compatible dict. Args: scenario_id: The ID of the scenario to export session: An active database session Returns: A dict with class names as keys and lists of serialized objects as values .. py:function:: list_scenarios(session, scenario_ids = None) List available scenarios. Args: session: An active database session scenario_ids: Optional list of specific scenario IDs to list .. py:function:: main() CLI entry point.