Split JSON export from service XLS reading

We have a better module for this.

Change-Id: Id4b68d3ddb119f27df3dfac52277981558fc5e50
This commit is contained in:
Jan Kundrát
2020-06-08 18:35:08 +02:00
parent 5bc42332cd
commit 0d5f1c7d80
3 changed files with 19 additions and 13 deletions

View File

@@ -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.topology.request import PathRequest, Disjunction
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
@@ -517,3 +517,18 @@ def disjunctions_from_json(json_data):
disjunctions_list.append(Disjunction(**params))
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

View File

@@ -180,12 +180,11 @@ class Request_element(Element):
return self.pathrequest, self.pathsync
def convert_service_sheet(
def read_service_sheet(
input_filename,
eqpt,
network,
network_filename=None,
output_filename='',
bidir=False,
filter_region=None):
""" converts a service sheet into a json structure
@@ -197,12 +196,6 @@ def convert_service_sheet(
service = parse_excel(input_filename)
req = [Request_element(n, eqpt, bidir) for n in service]
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
synchro = [n.json[1] for n in req if n.json[1] is not None]
if synchro:
@@ -214,8 +207,6 @@ def convert_service_sheet(
data = {
'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

View File

@@ -30,8 +30,8 @@ from gnpy.topology.request import (jsontocsv, requests_aggregation, compute_path
compute_path_with_disjunction, ResultElement, PathRequest)
from gnpy.topology.spectrum_assignment import build_oms_list, pth_assign_spectrum
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.service_sheet import convert_service_sheet, correct_xls_route_list
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 correct_xls_route_list
TEST_DIR = Path(__file__).parent
DATA_DIR = TEST_DIR / 'data'