|
13 | 13 | import json
|
14 | 14 | from collections import namedtuple
|
15 | 15 | from copy import deepcopy
|
16 |
| -from typing import Union, Dict, List |
| 16 | +from typing import Union, Dict, List, Tuple |
17 | 17 | from networkx import DiGraph
|
18 | 18 | from numpy import arange
|
19 | 19 |
|
|
25 | 25 | from gnpy.core.info import Carrier
|
26 | 26 | from gnpy.core.utils import automatic_nch, automatic_fmax, merge_amplifier_restrictions, dbm2watt
|
27 | 27 | 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 |
29 | 29 | from gnpy.topology.spectrum_assignment import mvalue_to_slots
|
30 | 30 | from gnpy.tools.convert import xls_to_json_data
|
31 | 31 | from gnpy.tools.service_sheet import read_service_sheet
|
@@ -975,3 +975,33 @@ def merge_equalization(params: dict, extra_params: dict) -> Union[dict, None]:
|
975 | 975 | # If ROADM config doesn't contain any equalization type, keep the default one
|
976 | 976 | return extra_params
|
977 | 977 | 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