mirror of
https://github.com/Telecominfraproject/oopt-gnpy.git
synced 2025-11-02 19:18:02 +00:00
Split JSON export from service XLS reading
We have a better module for this. Change-Id: Id4b68d3ddb119f27df3dfac52277981558fc5e50
This commit is contained in:
@@ -20,7 +20,7 @@ from gnpy.core.science_utils import estimate_nf_model
|
|||||||
from gnpy.core.utils import automatic_nch, automatic_fmax, merge_amplifier_restrictions
|
from gnpy.core.utils import automatic_nch, automatic_fmax, merge_amplifier_restrictions
|
||||||
from gnpy.topology.request import PathRequest, Disjunction
|
from gnpy.topology.request import PathRequest, Disjunction
|
||||||
from gnpy.tools.convert import xls_to_json_data
|
from gnpy.tools.convert import xls_to_json_data
|
||||||
from gnpy.tools.service_sheet import convert_service_sheet
|
from gnpy.tools.service_sheet import read_service_sheet
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
|
||||||
@@ -517,3 +517,18 @@ def disjunctions_from_json(json_data):
|
|||||||
disjunctions_list.append(Disjunction(**params))
|
disjunctions_list.append(Disjunction(**params))
|
||||||
|
|
||||||
return disjunctions_list
|
return disjunctions_list
|
||||||
|
|
||||||
|
|
||||||
|
def convert_service_sheet(
|
||||||
|
input_filename,
|
||||||
|
eqpt,
|
||||||
|
network,
|
||||||
|
network_filename=None,
|
||||||
|
output_filename='',
|
||||||
|
bidir=False,
|
||||||
|
filter_region=None):
|
||||||
|
if output_filename == '':
|
||||||
|
output_filename = f'{str(input_filename)[0:len(str(input_filename))-len(str(input_filename.suffixes[0]))]}_services.json'
|
||||||
|
data = read_service_sheet(input_filename, eqpt, network, network_filename, bidir, filter_region)
|
||||||
|
save_json(data, output_filename)
|
||||||
|
return data
|
||||||
|
|||||||
@@ -180,12 +180,11 @@ class Request_element(Element):
|
|||||||
return self.pathrequest, self.pathsync
|
return self.pathrequest, self.pathsync
|
||||||
|
|
||||||
|
|
||||||
def convert_service_sheet(
|
def read_service_sheet(
|
||||||
input_filename,
|
input_filename,
|
||||||
eqpt,
|
eqpt,
|
||||||
network,
|
network,
|
||||||
network_filename=None,
|
network_filename=None,
|
||||||
output_filename='',
|
|
||||||
bidir=False,
|
bidir=False,
|
||||||
filter_region=None):
|
filter_region=None):
|
||||||
""" converts a service sheet into a json structure
|
""" converts a service sheet into a json structure
|
||||||
@@ -197,12 +196,6 @@ def convert_service_sheet(
|
|||||||
service = parse_excel(input_filename)
|
service = parse_excel(input_filename)
|
||||||
req = [Request_element(n, eqpt, bidir) for n in service]
|
req = [Request_element(n, eqpt, bidir) for n in service]
|
||||||
req = correct_xls_route_list(network_filename, network, req)
|
req = correct_xls_route_list(network_filename, network, req)
|
||||||
# dumps the output into a json file with name
|
|
||||||
# split_filename = [input_filename[0:len(input_filename)-len(suffix_filename)] , suffix_filename[1:]]
|
|
||||||
if output_filename == '':
|
|
||||||
output_filename = f'{str(input_filename)[0:len(str(input_filename))-len(str(input_filename.suffixes[0]))]}_services.json'
|
|
||||||
# for debug
|
|
||||||
# print(json_filename)
|
|
||||||
# if there is no sync vector , do not write any synchronization
|
# if there is no sync vector , do not write any synchronization
|
||||||
synchro = [n.json[1] for n in req if n.json[1] is not None]
|
synchro = [n.json[1] for n in req if n.json[1] is not None]
|
||||||
if synchro:
|
if synchro:
|
||||||
@@ -214,8 +207,6 @@ def convert_service_sheet(
|
|||||||
data = {
|
data = {
|
||||||
'path-request': [n.json[0] for n in req]
|
'path-request': [n.json[0] for n in req]
|
||||||
}
|
}
|
||||||
with open(output_filename, 'w', encoding='utf-8') as f:
|
|
||||||
f.write(dumps(data, indent=2, ensure_ascii=False))
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ from gnpy.topology.request import (jsontocsv, requests_aggregation, compute_path
|
|||||||
compute_path_with_disjunction, ResultElement, PathRequest)
|
compute_path_with_disjunction, ResultElement, PathRequest)
|
||||||
from gnpy.topology.spectrum_assignment import build_oms_list, pth_assign_spectrum
|
from gnpy.topology.spectrum_assignment import build_oms_list, pth_assign_spectrum
|
||||||
from gnpy.tools.convert import convert_file
|
from gnpy.tools.convert import convert_file
|
||||||
from gnpy.tools.json_io import load_network, save_network, load_equipment, requests_from_json, disjunctions_from_json
|
from gnpy.tools.json_io import convert_service_sheet, load_network, save_network, load_equipment, requests_from_json, disjunctions_from_json
|
||||||
from gnpy.tools.service_sheet import convert_service_sheet, correct_xls_route_list
|
from gnpy.tools.service_sheet import correct_xls_route_list
|
||||||
|
|
||||||
TEST_DIR = Path(__file__).parent
|
TEST_DIR = Path(__file__).parent
|
||||||
DATA_DIR = TEST_DIR / 'data'
|
DATA_DIR = TEST_DIR / 'data'
|
||||||
|
|||||||
Reference in New Issue
Block a user