Commit 93b7f93a authored by Jan Dinkelbach's avatar Jan Dinkelbach

skipping error calculation and assertion for variables without counterpart

parent 207618f7
...@@ -43,4 +43,4 @@ for i in range(len(ts_dpsimList)): ...@@ -43,4 +43,4 @@ for i in range(len(ts_dpsimList)):
print('************************ convert dpsim to modelica end ****************') print('************************ convert dpsim to modelica end ****************')
res_err=validationtools.compare_timeseries(res_ref,ts_dpsimList) res_err=validationtools.compare_timeseries(res_ref,ts_dpsimList)
validationtools.assert_modelia_results(net_name,res_err,threshold) validationtools.assert_modelica_results(net_name,res_err,threshold)
\ No newline at end of file \ No newline at end of file
...@@ -121,7 +121,7 @@ def compare_timeseries(ts1, ts2): ...@@ -121,7 +121,7 @@ def compare_timeseries(ts1, ts2):
# Match the components in result files, and compare them # Match the components in result files, and compare them
for i in range(len_ts1): for i in range(len_ts1):
flag_not_found = False flag_found = False
for j in range(len_limit): for j in range(len_limit):
if ts1[i].name == ts2[j].name: # Find the same variable if ts1[i].name == ts2[j].name: # Find the same variable
timeseries_names.append(ts1[i].name) timeseries_names.append(ts1[i].name)
...@@ -132,15 +132,16 @@ def compare_timeseries(ts1, ts2): ...@@ -132,15 +132,16 @@ def compare_timeseries(ts1, ts2):
print(ts1[i].name) print(ts1[i].name)
print(timeseries_error[len(timeseries_error) - 1]) print(timeseries_error[len(timeseries_error) - 1])
flag_not_found = True flag_found = True
if flag_not_found is False: if flag_found is False:
# No such variable in Modelica model, set the error to -1 # No such variable in Modelica model, set the error to -1
timeseries_names.append(ts1[i].name) print("Warning: no matching variable found for " + ts1[i].name + "! Skipping error calculation and assertion for this variable...")
timeseries_error.append(-1) # timeseries_names.append(ts1[i].name)
# timeseries_error.append(-1)
return dict(zip(timeseries_names, timeseries_error)) return dict(zip(timeseries_names, timeseries_error))
def assert_modelia_results(net_name, error, threshold): def assert_modelica_results(net_name, error, threshold):
""" """
assert the result data of a net. assert the result data of a net.
:param net_name: name of the network :param net_name: name of the network
...@@ -149,7 +150,6 @@ def assert_modelia_results(net_name, error, threshold): ...@@ -149,7 +150,6 @@ def assert_modelia_results(net_name, error, threshold):
:return: outputs to command line which are the results of the assert :return: outputs to command line which are the results of the assert
""" """
fail_list = [] # List for all the failed test fail_list = [] # List for all the failed test
# the limitations are set to 0.5
for name in error.keys(): for name in error.keys():
if abs(error[name]) > threshold: if abs(error[name]) > threshold:
fail_list.append(name) fail_list.append(name)
...@@ -173,11 +173,24 @@ def validate_modelica_res(net_name, modelica_res_path, reference_res_path, thres ...@@ -173,11 +173,24 @@ def validate_modelica_res(net_name, modelica_res_path, reference_res_path, thres
:param threshold: the threshold of the assertion, a default value of 0.5 is introduced. :param threshold: the threshold of the assertion, a default value of 0.5 is introduced.
:return: outputs to command line which are the results of the validation. :return: outputs to command line which are the results of the validation.
""" """
print('\n************************ Modelica Results ****************')
res_mod = read_timeseries_Modelica (modelica_res_path) res_mod = read_timeseries_Modelica (modelica_res_path)
for res in res_mod:
print(res.name)
print(res.values[0]) # only show first value of time series
print('\n************************ Reference Results ****************')
if os.path.splitext(reference_res_path)[1] == '.rep': if os.path.splitext(reference_res_path)[1] == '.rep':
res_ref = convert_simulink_to_modelica_timeseries(read_timeseries_simulink_loadflow(reference_res_path)) res_ref = convert_simulink_to_modelica_timeseries(read_timeseries_simulink_loadflow(reference_res_path))
elif os.path.splitext(reference_res_path)[1] == '.rlf': elif os.path.splitext(reference_res_path)[1] == '.rlf':
res_ref = convert_neplan_to_modelica_timeseries(read_timeseries_NEPLAN_loadflow(reference_res_path)) res_ref = convert_neplan_to_modelica_timeseries(read_timeseries_NEPLAN_loadflow(reference_res_path))
for res in res_ref:
print(res.name)
print(res.values)
print('\n************************ Comparison ****************')
res_err = compare_timeseries(res_ref, res_mod) res_err = compare_timeseries(res_ref, res_mod)
assert_modelia_results(net_name, res_err, threshold)
print('\n************************ Assertion ****************')
assert_modelica_results(net_name, res_err, threshold)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment