Fixes concerning service sheet reading

- indicate which request has incorrect tsp type or mode
- correct wrong reading from excel : if string values contain only a number
  xlrd interprets as a float eg 1 -> 1.0  . A function is used to correct this
  when filling the Request class

Signed-off-by: EstherLerouzic <esther.lerouzic@orange.com>
This commit is contained in:
EstherLerouzic
2018-12-14 18:06:03 +00:00
parent 74314f00ca
commit 6af137a085

View File

@@ -47,13 +47,7 @@ class Request_element(Element):
# request_id is str # request_id is str
# excel has automatic number formatting that adds .0 on integer values # excel has automatic number formatting that adds .0 on integer values
# the next lines recover the pure int value, assuming this .0 is unwanted # the next lines recover the pure int value, assuming this .0 is unwanted
if not isinstance(Request.request_id,str): self.request_id = correct_xlrd_int_to_str_reading(Request.request_id)
value = str(int(Request.request_id))
if value.endswith('.0'):
value = value[:-2]
self.request_id = value
else:
self.request_id = Request.request_id
self.source = Request.source self.source = Request.source
self.destination = Request.destination self.destination = Request.destination
# TODO: the automatic naming generated by excel parser requires that source and dest name # TODO: the automatic naming generated by excel parser requires that source and dest name
@@ -65,14 +59,21 @@ class Request_element(Element):
equipment = load_equipment(eqpt_filename) equipment = load_equipment(eqpt_filename)
try : try :
if equipment['Transceiver'][Request.trx_type]: if equipment['Transceiver'][Request.trx_type]:
self.trx_type = Request.trx_type self.trx_type = correct_xlrd_int_to_str_reading(Request.trx_type)
if Request.mode is not None : if Request.mode is not None :
if [mode for mode in equipment['Transceiver'][Request.trx_type].mode]: Requestmode = correct_xlrd_int_to_str_reading(Request.mode)
self.mode = Request.mode if [mode for mode in equipment['Transceiver'][Request.trx_type].mode if mode['format'] == Requestmode]:
self.mode = Requestmode
else :
msg = f'Request Id: {self.request_id} - could not find tsp : \'{Request.trx_type}\' with mode: \'{Requestmode}\' in eqpt library \nComputation stopped.'
#print(msg)
logger.critical(msg)
exit(1)
else: else:
Requestmode = None
self.mode = Request.mode self.mode = Request.mode
except KeyError: except KeyError:
msg = f'could not find tsp : {Request.trx_type} with mode: {Request.mode} in eqpt library \nComputation stopped.' msg = f'Request Id: {self.request_id} - could not find tsp : \'{Request.trx_type}\' with mode: \'{Requestmode}\' in eqpt library \nComputation stopped.'
#print(msg) #print(msg)
logger.critical(msg) logger.critical(msg)
exit() exit()
@@ -91,12 +92,8 @@ class Request_element(Element):
self.nb_channel = int(Request.nb_channel) self.nb_channel = int(Request.nb_channel)
else: else:
self.nb_channel = None self.nb_channel = None
if not isinstance(Request.disjoint_from,str):
value = str(int(Request.disjoint_from)) value = correct_xlrd_int_to_str_reading(Request.disjoint_from)
if value.endswith('.0'):
value = value[:-2]
else:
value = Request.disjoint_from
self.disjoint_from = [n for n in value.split(' | ') if value] self.disjoint_from = [n for n in value.split(' | ') if value]
self.nodes_list = [] self.nodes_list = []
if Request.nodes_list : if Request.nodes_list :
@@ -213,6 +210,15 @@ def convert_service_sheet(input_filename, eqpt_filename, output_filename='', fil
f.write(dumps(data, indent=2, ensure_ascii=False)) f.write(dumps(data, indent=2, ensure_ascii=False))
return data return data
def correct_xlrd_int_to_str_reading(v) :
if not isinstance(v,str):
value = str(int(v))
if value.endswith('.0'):
value = value[:-2]
else:
value = v
return value
# to be used from dutc # to be used from dutc
def parse_row(row, fieldnames): def parse_row(row, fieldnames):
return {f: r.value for f, r in zip(fieldnames, row[0:SERVICES_COLUMN]) return {f: r.value for f, r in zip(fieldnames, row[0:SERVICES_COLUMN])