Skip to content
Snippets Groups Projects
Commit ec72b262 authored by imcovangent's avatar imcovangent
Browse files

Added safe handling of sleep_time as float for CMDOWS saving and loading.

Former-commit-id: b80e448cdbcf0a6ab14bce00febe8091343dce08
parent 72bdd360
No related branches found
No related tags found
No related merge requests found
......@@ -50,7 +50,7 @@ rcg.add_node('D3', category='function')
rcg.add_node('F1', category='function', function_type='regular', sleep_time=0.)
rcg.add_node('F2', category='function')
rcg.add_node('G1', category='function', function_type='regular', sleep_time=0.)
rcg.add_node('G2', category='function', function_type='regular', sleep_time=0.)
rcg.add_node('G2', category='function', function_type='regular')
# All variable nodes are defined
rcg.add_node('/dataSchema/settings/a', category='variable', label='a')
rcg.add_node('/dataSchema/settings/c', category='variable', label='c')
......
......@@ -3,8 +3,7 @@ import math
import logging
from ..utilities.xmls import Element
from ..utilities.general import get_uid
from ..utilities.general import get_uid, make_float_or_keep_none
# Settings for the logger
logger = logging.getLogger(__name__)
......@@ -231,8 +230,8 @@ class EquationMixin(object):
# Create mathematicalFunctions/mathematicalFunction
cmdows_math_func = cmdows_math_funcs.add('mathematicalFunction', uID=graph_math_func)
cmdows_math_func.add('label', self.node[graph_math_func].get('label', graph_math_func))
cmdows_math_func.add('functionType', self.node[graph_math_func].get('function_type', graph_math_func))
cmdows_math_func.add('sleepTime', self.node[graph_math_func].get('sleep_time', graph_math_func))
cmdows_math_func.add('functionType', self.node[graph_math_func].get('function_type'))
cmdows_math_func.add('sleepTime', make_float_or_keep_none(self.node[graph_math_func].get('sleep_time')))
# Create mathematicalFunctions/mathematicalFunction/inputs with children
cmdows_inputs = cmdows_math_func.add('inputs')
......@@ -279,7 +278,7 @@ class EquationMixin(object):
shape='s',
label=function.findtext('label'),
function_type=function.findtext('functionType'),
sleep_time=float(function.findtext('sleepTime')))
sleep_time=make_float_or_keep_none(function.findtext('sleepTime')))
for inp in function.findall('inputs/input'):
self.add_edge(inp.findtext('parameterUID').replace("'", '"'), function.get('uID'),
equation_label=inp.findtext('equationLabel'),
......
......@@ -858,3 +858,12 @@ def unzip_file(file_to_unzip, destination_folder=None):
zip_ref.extractall(destination_folder)
zip_ref.close()
return extracted_file
def make_float_or_keep_none(value):
if isinstance(value, (float, int, str)):
return float(value)
elif value is None:
return None
else:
raise AssertionError('Could not process value {} which is of type {}.'.format(value, type(value)))
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment