Merge pull request #252 from Orange-OpenSource/bug_fixes_create_eqpt_sheet

Refactoring and bug fixes in an auxiliary transformation tool.
This commit is contained in:
Jan Kundrát
2019-05-31 16:26:10 +02:00
committed by GitHub
4 changed files with 398 additions and 423 deletions

View File

@@ -11,64 +11,72 @@ If not present in the "Nodes" sheet, the "Type" column will be implicitly
determined based on the topology.
"""
from sys import exit
try:
from xlrd import open_workbook
except ModuleNotFoundError:
exit('Required: `pip install xlrd`')
from argparse import ArgumentParser
from collections import namedtuple, defaultdict
PARSER = ArgumentParser()
PARSER.add_argument('workbook', nargs='?', default='meshTopologyExampleV2.xls',
help='create the mandatory columns in Eqpt sheet')
ALL_ROWS = lambda sh, start=0: (sh.row(x) for x in range(start, sh.nrows))
Shortlink = namedtuple('Link', 'src dest')
class Node:
""" Node element contains uid, list of connected nodes and eqpt type
"""
def __init__(self, uid, to_node):
self.uid = uid
self.to_node = to_node
self.eqpt = None
Shortnode = namedtuple('Node', 'nodename eqt')
def __repr__(self):
return f'uid {self.uid} \nto_node {[node for node in self.to_node]}\neqpt {self.eqpt}\n'
parser = ArgumentParser()
parser.add_argument('workbook', nargs='?', default='meshTopologyExampleV2.xls',
help = 'create the mandatory columns in Eqpt sheet ')
all_rows = lambda sh, start=0: (sh.row(x) for x in range(start, sh.nrows))
def __str__(self):
return f'uid {self.uid} \nto_node {[node for node in self.to_node]}\neqpt {self.eqpt}\n'
def read_excel(input_filename):
with open_workbook(input_filename) as wb:
""" read excel Nodes and Links sheets and create a dict of nodes with
their to_nodes and type of eqpt
"""
with open_workbook(input_filename) as wobo:
# reading Links sheet
links_sheet = wb.sheet_by_name('Links')
links = []
nodeoccuranceinlinks = []
links_by_src = defaultdict(list)
links_by_dest = defaultdict(list)
for row in all_rows(links_sheet, start=5):
links.append(Shortlink(row[0].value,row[1].value))
links_by_src[row[0].value].append(Shortnode(row[1].value,''))
links_by_dest[row[1].value].append(Shortnode(row[0].value,''))
#print(f'source {links[len(links)-1].src} dest {links[len(links)-1].dest}')
nodeoccuranceinlinks.append(row[0].value)
nodeoccuranceinlinks.append(row[1].value)
links_sheet = wobo.sheet_by_name('Links')
nodes = {}
for row in ALL_ROWS(links_sheet, start=5):
try:
nodes[row[0].value].to_node.append(row[1].value)
except KeyError:
nodes[row[0].value] = Node(row[0].value, [row[1].value])
try:
nodes[row[1].value].to_node.append(row[0].value)
except KeyError:
nodes[row[1].value] = Node(row[1].value, [row[0].value])
# reading Nodes sheet
nodes_sheet = wb.sheet_by_name('Nodes')
nodes = []
node_degree = []
for row in all_rows(nodes_sheet, start=5) :
nodes_sheet = wobo.sheet_by_name('Nodes')
for row in ALL_ROWS(nodes_sheet, start=5):
node = row[0].value
eqpt = row[6].value
try:
if eqpt == 'ILA' and len(nodes[node].to_node) != 2:
print(f'Inconsistancy ILA node with degree > 2: {node} ')
exit()
if eqpt == '' and len(nodes[node].to_node) == 2:
nodes[node].eqpt = 'ILA'
elif eqpt == '' and len(nodes[node].to_node) != 2:
nodes[node].eqpt = 'ROADM'
else:
nodes[node].eqpt = eqpt
except KeyError:
print(f'inconsistancy between nodes and links sheet: {node} is not listed in links')
exit()
return nodes
temp_eqt = row[6].value
# verify node degree to confirm eqt type
node_degree.append(nodeoccuranceinlinks.count(row[0].value))
if temp_eqt.lower() == 'ila' and nodeoccuranceinlinks.count(row[0].value) !=2 :
print(f'Inconsistancy: node {nodes[len(nodes)-1]} has degree \
{node_degree[len(nodes)-1]} and can not be an ILA ... replaced by ROADM')
temp_eqt = 'ROADM'
if temp_eqt == '' and nodeoccuranceinlinks.count(row[0].value) == 2 :
temp_eqt = 'ILA'
if temp_eqt == '' and nodeoccuranceinlinks.count(row[0].value) != 2 :
temp_eqt = 'ROADM'
# print(f'node {nodes[len(nodes)-1]} eqt {temp_eqt}')
nodes.append(Shortnode(row[0].value,temp_eqt))
# print(len(nodes)-1)
print(f'reading: node {nodes[len(nodes)-1].nodename} eqpt {temp_eqt}')
return links,nodes, links_by_src , links_by_dest
def create_eqt_template(links,nodes, links_by_src , links_by_dest, input_filename):
def create_eqt_template(nodes, input_filename):
""" writes list of node A node Z corresponding to Nodes and Links sheets in order
to help user populating Eqpt
"""
output_filename = f'{input_filename[:-4]}_eqpt_sheet.txt'
with open(output_filename, 'w', encoding='utf-8') as my_file:
# print header similar to excel
@@ -77,27 +85,17 @@ def create_eqt_template(links,nodes, links_by_src , links_by_dest, input_filenam
\nNode A \tNode Z \tamp type \tatt_in \tamp gain \ttilt \tatt_out\
amp type \tatt_in \tamp gain \ttilt \tatt_out\n')
tab = []
temp = []
i = 0
for lk in links:
if [e for n,e in nodes if n==lk.src][0] != 'FUSED' :
temp = [lk.src , lk.dest]
tab.append(temp)
my_file.write(f'{temp[0]}\t{temp[1]}\n')
for n in nodes :
if n.eqt.lower() == 'roadm' :
for src in links_by_dest[n.nodename] :
temp = [n.nodename , src.nodename]
tab.append(temp)
# print(temp)
my_file.write(f'{temp[0]}\t{temp[1]}\n')
i = i + 1
for node in nodes.values():
if node.eqpt == 'ILA':
my_file.write(f'{node.uid}\t{node.to_node[0]}\n')
if node.eqpt == 'ROADM':
for to_node in node.to_node:
my_file.write(f'{node.uid}\t{to_node}\n')
print(f'File {output_filename} successfully created with Node A - Node Z ' +
' entries for Eqpt sheet in excel file.')
' entries for Eqpt sheet in excel file.')
if __name__ == '__main__':
args = parser.parse_args()
input_filename = args.workbook
links,nodes,links_by_src, links_by_dest = read_excel(input_filename)
create_eqt_template(links,nodes, links_by_src , links_by_dest , input_filename)
ARGS = PARSER.parse_args()
create_eqt_template(read_excel(ARGS.workbook), ARGS.workbook)

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@@ -42,7 +42,7 @@
"location": {
"city": "Rennes_STA",
"region": "RLD",
"latitude": 0.0,
"latitude": 4.0,
"longitude": 0.0
}
},
@@ -54,7 +54,7 @@
"location": {
"city": "Brest_KLA",
"region": "RLD",
"latitude": 4.0,
"latitude": 0.0,
"longitude": 0.0
}
},
@@ -66,8 +66,8 @@
"location": {
"city": "a",
"region": "",
"latitude": 0,
"longitude": 0
"latitude": 6.0,
"longitude": 0.0
}
},
"type": "Transceiver"
@@ -78,8 +78,8 @@
"location": {
"city": "b",
"region": "",
"latitude": 0,
"longitude": 0
"latitude": 5.0,
"longitude": 0.0
}
},
"type": "Transceiver"
@@ -90,8 +90,8 @@
"location": {
"city": "c",
"region": "",
"latitude": 0,
"longitude": 0
"latitude": 6.0,
"longitude": 1.0
}
},
"type": "Transceiver"
@@ -102,8 +102,8 @@
"location": {
"city": "d",
"region": "",
"latitude": 0,
"longitude": 0
"latitude": 6.0,
"longitude": 4.0
}
},
"type": "Transceiver"
@@ -114,8 +114,8 @@
"location": {
"city": "e",
"region": "",
"latitude": 0,
"longitude": 0
"latitude": 5.0,
"longitude": 4.0
}
},
"type": "Transceiver"
@@ -126,8 +126,8 @@
"location": {
"city": "f",
"region": "",
"latitude": 0,
"longitude": 0
"latitude": 5.0,
"longitude": 1.0
}
},
"type": "Transceiver"
@@ -138,8 +138,8 @@
"location": {
"city": "g",
"region": "",
"latitude": 0,
"longitude": 0
"latitude": 5.0,
"longitude": 3.0
}
},
"type": "Transceiver"
@@ -150,8 +150,8 @@
"location": {
"city": "h",
"region": "",
"latitude": 0,
"longitude": 0
"latitude": 5.0,
"longitude": 2.0
}
},
"type": "Transceiver"
@@ -198,7 +198,7 @@
"location": {
"city": "Rennes_STA",
"region": "RLD",
"latitude": 0.0,
"latitude": 4.0,
"longitude": 0.0
}
},
@@ -210,7 +210,7 @@
"location": {
"city": "Brest_KLA",
"region": "RLD",
"latitude": 4.0,
"latitude": 0.0,
"longitude": 0.0
}
},
@@ -222,8 +222,8 @@
"location": {
"city": "a",
"region": "",
"latitude": 0,
"longitude": 0
"latitude": 6.0,
"longitude": 0.0
}
},
"type": "Roadm"
@@ -234,8 +234,8 @@
"location": {
"city": "b",
"region": "",
"latitude": 0,
"longitude": 0
"latitude": 5.0,
"longitude": 0.0
}
},
"type": "Roadm"
@@ -246,8 +246,8 @@
"location": {
"city": "c",
"region": "",
"latitude": 0,
"longitude": 0
"latitude": 6.0,
"longitude": 1.0
}
},
"type": "Roadm"
@@ -258,8 +258,8 @@
"location": {
"city": "d",
"region": "",
"latitude": 0,
"longitude": 0
"latitude": 6.0,
"longitude": 4.0
}
},
"type": "Roadm"
@@ -270,8 +270,8 @@
"location": {
"city": "e",
"region": "",
"latitude": 0,
"longitude": 0
"latitude": 5.0,
"longitude": 4.0
}
},
"type": "Roadm"
@@ -282,8 +282,8 @@
"location": {
"city": "f",
"region": "",
"latitude": 0,
"longitude": 0
"latitude": 5.0,
"longitude": 1.0
}
},
"type": "Roadm"
@@ -294,8 +294,8 @@
"location": {
"city": "g",
"region": "",
"latitude": 0,
"longitude": 0
"latitude": 5.0,
"longitude": 3.0
}
},
"type": "Roadm"
@@ -306,8 +306,8 @@
"location": {
"city": "h",
"region": "",
"latitude": 0,
"longitude": 0
"latitude": 5.0,
"longitude": 2.0
}
},
"type": "Roadm"
@@ -342,7 +342,7 @@
"location": {
"city": "Morlaix",
"region": "RLD",
"latitude": 3.0,
"latitude": 1.0,
"longitude": 0.0
}
},
@@ -378,7 +378,7 @@
"location": {
"city": "Morlaix",
"region": "RLD",
"latitude": 3.0,
"latitude": 1.0,
"longitude": 0.0
}
},
@@ -460,7 +460,7 @@
"uid": "fiber (Lannion_CAS → Stbrieuc)-F056",
"metadata": {
"location": {
"latitude": 1.5,
"latitude": 2.5,
"longitude": 0.0
}
},
@@ -478,7 +478,7 @@
"uid": "fiber (Stbrieuc → Rennes_STA)-F057",
"metadata": {
"location": {
"latitude": 0.5,
"latitude": 3.5,
"longitude": 0.0
}
},
@@ -496,7 +496,7 @@
"uid": "fiber (Lannion_CAS → Morlaix)-F059",
"metadata": {
"location": {
"latitude": 2.5,
"latitude": 1.5,
"longitude": 0.0
}
},
@@ -514,7 +514,7 @@
"uid": "fiber (Morlaix → Brest_KLA)-F060",
"metadata": {
"location": {
"latitude": 3.5,
"latitude": 0.5,
"longitude": 0.0
}
},
@@ -532,8 +532,8 @@
"uid": "fiber (Brest_KLA → Quimper)-",
"metadata": {
"location": {
"latitude": 2.5,
"longitude": 0.5
"latitude": 0.0,
"longitude": 1.5
}
},
"type": "Fiber",
@@ -550,8 +550,8 @@
"uid": "fiber (Quimper → Lorient_KMA)-",
"metadata": {
"location": {
"latitude": 1.5,
"longitude": 2.0
"latitude": 1.0,
"longitude": 3.0
}
},
"type": "Fiber",
@@ -568,8 +568,8 @@
"uid": "fiber (Ploermel → Vannes_KBE)-",
"metadata": {
"location": {
"latitude": 1.5,
"longitude": 3.0
"latitude": 3.0,
"longitude": 4.0
}
},
"type": "Fiber",
@@ -586,8 +586,8 @@
"uid": "fiber (Ploermel → Rennes_STA)-",
"metadata": {
"location": {
"latitude": 0.5,
"longitude": 1.0
"latitude": 4.0,
"longitude": 2.0
}
},
"type": "Fiber",
@@ -604,7 +604,7 @@
"uid": "fiber (a → b)-",
"metadata": {
"location": {
"latitude": 0.0,
"latitude": 5.5,
"longitude": 0.0
}
},
@@ -622,8 +622,8 @@
"uid": "fiber (a → c)-",
"metadata": {
"location": {
"latitude": 0.0,
"longitude": 0.0
"latitude": 6.0,
"longitude": 0.5
}
},
"type": "Fiber",
@@ -640,8 +640,8 @@
"uid": "fiber (c → d)-",
"metadata": {
"location": {
"latitude": 0.0,
"longitude": 0.0
"latitude": 6.0,
"longitude": 2.5
}
},
"type": "Fiber",
@@ -658,8 +658,8 @@
"uid": "fiber (c → f)-",
"metadata": {
"location": {
"latitude": 0.0,
"longitude": 0.0
"latitude": 5.5,
"longitude": 1.0
}
},
"type": "Fiber",
@@ -676,8 +676,8 @@
"uid": "fiber (b → f)-",
"metadata": {
"location": {
"latitude": 0.0,
"longitude": 0.0
"latitude": 5.0,
"longitude": 0.5
}
},
"type": "Fiber",
@@ -694,8 +694,8 @@
"uid": "fiber (e → d)-",
"metadata": {
"location": {
"latitude": 0.0,
"longitude": 0.0
"latitude": 5.5,
"longitude": 4.0
}
},
"type": "Fiber",
@@ -712,8 +712,8 @@
"uid": "fiber (e → g)-",
"metadata": {
"location": {
"latitude": 0.0,
"longitude": 0.0
"latitude": 5.0,
"longitude": 3.5
}
},
"type": "Fiber",
@@ -730,8 +730,8 @@
"uid": "fiber (f → h)-",
"metadata": {
"location": {
"latitude": 0.0,
"longitude": 0.0
"latitude": 5.0,
"longitude": 1.5
}
},
"type": "Fiber",
@@ -748,8 +748,8 @@
"uid": "fiber (h → g)-",
"metadata": {
"location": {
"latitude": 0.0,
"longitude": 0.0
"latitude": 5.0,
"longitude": 2.5
}
},
"type": "Fiber",
@@ -838,7 +838,7 @@
"uid": "fiber (Stbrieuc → Lannion_CAS)-F056",
"metadata": {
"location": {
"latitude": 1.5,
"latitude": 2.5,
"longitude": 0.0
}
},
@@ -856,7 +856,7 @@
"uid": "fiber (Rennes_STA → Stbrieuc)-F057",
"metadata": {
"location": {
"latitude": 0.5,
"latitude": 3.5,
"longitude": 0.0
}
},
@@ -874,7 +874,7 @@
"uid": "fiber (Morlaix → Lannion_CAS)-F059",
"metadata": {
"location": {
"latitude": 2.5,
"latitude": 1.5,
"longitude": 0.0
}
},
@@ -892,7 +892,7 @@
"uid": "fiber (Brest_KLA → Morlaix)-F060",
"metadata": {
"location": {
"latitude": 3.5,
"latitude": 0.5,
"longitude": 0.0
}
},
@@ -910,8 +910,8 @@
"uid": "fiber (Quimper → Brest_KLA)-",
"metadata": {
"location": {
"latitude": 2.5,
"longitude": 0.5
"latitude": 0.0,
"longitude": 1.5
}
},
"type": "Fiber",
@@ -928,8 +928,8 @@
"uid": "fiber (Lorient_KMA → Quimper)-",
"metadata": {
"location": {
"latitude": 1.5,
"longitude": 2.0
"latitude": 1.0,
"longitude": 3.0
}
},
"type": "Fiber",
@@ -946,8 +946,8 @@
"uid": "fiber (Vannes_KBE → Ploermel)-",
"metadata": {
"location": {
"latitude": 1.5,
"longitude": 3.0
"latitude": 3.0,
"longitude": 4.0
}
},
"type": "Fiber",
@@ -964,8 +964,8 @@
"uid": "fiber (Rennes_STA → Ploermel)-",
"metadata": {
"location": {
"latitude": 0.5,
"longitude": 1.0
"latitude": 4.0,
"longitude": 2.0
}
},
"type": "Fiber",
@@ -982,7 +982,7 @@
"uid": "fiber (b → a)-",
"metadata": {
"location": {
"latitude": 0.0,
"latitude": 5.5,
"longitude": 0.0
}
},
@@ -1000,8 +1000,8 @@
"uid": "fiber (c → a)-",
"metadata": {
"location": {
"latitude": 0.0,
"longitude": 0.0
"latitude": 6.0,
"longitude": 0.5
}
},
"type": "Fiber",
@@ -1018,8 +1018,8 @@
"uid": "fiber (d → c)-",
"metadata": {
"location": {
"latitude": 0.0,
"longitude": 0.0
"latitude": 6.0,
"longitude": 2.5
}
},
"type": "Fiber",
@@ -1036,8 +1036,8 @@
"uid": "fiber (f → c)-",
"metadata": {
"location": {
"latitude": 0.0,
"longitude": 0.0
"latitude": 5.5,
"longitude": 1.0
}
},
"type": "Fiber",
@@ -1054,8 +1054,8 @@
"uid": "fiber (f → b)-",
"metadata": {
"location": {
"latitude": 0.0,
"longitude": 0.0
"latitude": 5.0,
"longitude": 0.5
}
},
"type": "Fiber",
@@ -1072,8 +1072,8 @@
"uid": "fiber (d → e)-",
"metadata": {
"location": {
"latitude": 0.0,
"longitude": 0.0
"latitude": 5.5,
"longitude": 4.0
}
},
"type": "Fiber",
@@ -1090,8 +1090,8 @@
"uid": "fiber (g → e)-",
"metadata": {
"location": {
"latitude": 0.0,
"longitude": 0.0
"latitude": 5.0,
"longitude": 3.5
}
},
"type": "Fiber",
@@ -1108,8 +1108,8 @@
"uid": "fiber (h → f)-",
"metadata": {
"location": {
"latitude": 0.0,
"longitude": 0.0
"latitude": 5.0,
"longitude": 1.5
}
},
"type": "Fiber",
@@ -1126,8 +1126,8 @@
"uid": "fiber (g → h)-",
"metadata": {
"location": {
"latitude": 0.0,
"longitude": 0.0
"latitude": 5.0,
"longitude": 2.5
}
},
"type": "Fiber",
@@ -1178,25 +1178,6 @@
"out_voa": null
}
},
{
"uid": "east edfa in Stbrieuc to Rennes_STA",
"metadata": {
"location": {
"city": "Stbrieuc",
"region": "RLD",
"latitude": 1.0,
"longitude": 0.0
}
},
"type": "Edfa",
"type_variety": "std_medium_gain",
"operational": {
"gain_target": 18.5,
"delta_p": null,
"tilt_target": 0,
"out_voa": null
}
},
{
"uid": "east edfa in Lannion_CAS to Morlaix",
"metadata": {
@@ -1216,13 +1197,32 @@
"out_voa": 0.5
}
},
{
"uid": "east edfa in Stbrieuc to Rennes_STA",
"metadata": {
"location": {
"city": "Stbrieuc",
"region": "RLD",
"latitude": 3.0,
"longitude": 0.0
}
},
"type": "Edfa",
"type_variety": "std_medium_gain",
"operational": {
"gain_target": 18.5,
"delta_p": null,
"tilt_target": 0,
"out_voa": null
}
},
{
"uid": "east edfa in Brest_KLA to Quimper",
"metadata": {
"location": {
"city": "Brest_KLA",
"region": "RLD",
"latitude": 4.0,
"latitude": 0.0,
"longitude": 0.0
}
},
@@ -1241,8 +1241,8 @@
"location": {
"city": "Ploermel",
"region": "RLD",
"latitude": 1.0,
"longitude": 2.0
"latitude": 4.0,
"longitude": 4.0
}
},
"type": "Edfa",
@@ -1291,25 +1291,6 @@
"tilt_target": 0,
"out_voa": null
}
},
{
"uid": "west edfa in Quimper to Lorient_KMA",
"metadata": {
"location": {
"city": "Quimper",
"region": "RLD",
"latitude": 1.0,
"longitude": 1.0
}
},
"type": "Edfa",
"type_variety": "std_low_gain",
"operational": {
"gain_target": 19.0,
"delta_p": null,
"tilt_target": 0,
"out_voa": null
}
}
],
"connections": [
@@ -1499,10 +1480,6 @@
},
{
"from_node": "fiber (Lorient_KMA → Quimper)-",
"to_node": "west edfa in Quimper to Lorient_KMA"
},
{
"from_node": "west edfa in Quimper to Lorient_KMA",
"to_node": "fiber (Quimper → Brest_KLA)-"
},
{