Skip to content

Commit 101eb8f

Browse files
committed
Define functions for results conversion and load eqpt/topology from dict
Change-Id: I4111f20f59aeef1e25fc8b44028922bbb94dea91
1 parent 7ce6650 commit 101eb8f

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

Diff for: gnpy/tools/json_io.py

+32-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import json
1414
from collections import namedtuple
1515
from copy import deepcopy
16-
from typing import Union, Dict, List
16+
from typing import Union, Dict, List, Tuple
1717
from networkx import DiGraph
1818
from numpy import arange
1919

@@ -25,7 +25,7 @@
2525
from gnpy.core.info import Carrier
2626
from gnpy.core.utils import automatic_nch, automatic_fmax, merge_amplifier_restrictions, dbm2watt
2727
from gnpy.core.parameters import DEFAULT_RAMAN_COEFFICIENT, EdfaParams, MultiBandParams, DEFAULT_EDFA_CONFIG
28-
from gnpy.topology.request import PathRequest, Disjunction, compute_spectrum_slot_vs_bandwidth
28+
from gnpy.topology.request import PathRequest, Disjunction, compute_spectrum_slot_vs_bandwidth, ResultElement
2929
from gnpy.topology.spectrum_assignment import mvalue_to_slots
3030
from gnpy.tools.convert import xls_to_json_data
3131
from gnpy.tools.service_sheet import read_service_sheet
@@ -975,3 +975,33 @@ def merge_equalization(params: dict, extra_params: dict) -> Union[dict, None]:
975975
# If ROADM config doesn't contain any equalization type, keep the default one
976976
return extra_params
977977
return None
978+
979+
980+
def results_to_json(pathresults: List[ResultElement]):
981+
"""Converts a list of `ResultElement` objects into a JSON-compatible dictionary.
982+
983+
:param pathresults: List of `ResultElement` objects to be converted.
984+
:return: A dictionary with a single key `"response"`, containing a list of
985+
the `json` attributes of the provided `ResultElement` objects.
986+
"""
987+
return {'response': [n.json for n in pathresults]}
988+
989+
990+
def load_eqpt_topo_from_json(eqpt: dict, topology: dict) -> Tuple[dict, DiGraph]:
991+
"""Loads equipment configuration and network topology from JSON data.
992+
993+
:param eqpt: Dictionary containing the equipment configuration in JSON format.
994+
It includes details about the devices to be processed and structured.
995+
:param topology: Dictionary representing the network topology in JSON format,
996+
defining the structure of the network and its connections.
997+
998+
:return: A tuple containing:
999+
1000+
- A dictionary with the processed equipment configuration.
1001+
- A directed graph (DiGraph) representing the network topology, where nodes
1002+
correspond to equipment and edges define their connections.
1003+
"""
1004+
equipment = _equipment_from_json(eqpt, DEFAULT_EXTRA_CONFIG)
1005+
network = network_from_json(topology, equipment)
1006+
return equipment, network
1007+

0 commit comments

Comments
 (0)