Skip to content

Commit

Permalink
integrated tests for diagnostic_reports into test_diagnostic
Browse files Browse the repository at this point in the history
  • Loading branch information
julffers committed Mar 20, 2017
1 parent 30e1e96 commit 22dfc7e
Show file tree
Hide file tree
Showing 4 changed files with 762 additions and 227 deletions.
19 changes: 15 additions & 4 deletions pandapower/diagnostic.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,24 @@ def diagnostic(net, report_style='detailed', warnings_only=False, return_result_
"different_voltage_levels_connected(net)",
"nominal_voltages_dont_match(net, nom_voltage_tolerance)",
"multiple_voltage_controlling_elements_per_bus(net)"]
invalid_value_dependent_checks = ["wrong_reference_system(net)"]

diag_results = {}
for diag_function in diag_functions:
if (diag_function in bus_index_dependent_checks) and ("missing_bus_indeces" in diag_results.keys()):
diag_result = "check skipped"
elif 'invalid_values' in diag_results.keys():
if (diag_function in invalid_value_dependent_checks) and (set(['gen', 'load', 'sgen'])
& set(diag_results['invalid_values'].keys())):
diag_result = "check skipped"
else:
diag_result = eval(diag_function)
if diag_result:
diag_results[diag_function.split("(")[0]] = diag_result
else:
diag_result = eval(diag_function)
if diag_result:
diag_results[diag_function.split("(")[0]] = diag_result
if diag_result:
diag_results[diag_function.split("(")[0]] = diag_result

diag_params = {
"overload_scaling_factor": overload_scaling_factor,
Expand Down Expand Up @@ -630,8 +640,9 @@ def nominal_voltages_dont_match(net, nom_voltage_tolerance):
trafo3w_results['connectors_swapped_3w'] = connectors_swapped_3w
if trafo3w_results:
results['trafo3w'] = trafo3w_results

return results

if len(results) > 0:
return results


def disconnected_elements(net):
Expand Down
110 changes: 56 additions & 54 deletions pandapower/diagnostic_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,60 +436,62 @@ def report_wrong_reference_system(self):

# message body
diag_result = self.diag_results["wrong_reference_system"]

for element_type in diag_result:
if element_type is "loads":
if self.compact_report:
logger.warning("loads %s: wrong reference system."
% (diag_result[element_type]))
else:
for load in diag_result[element_type]:
logger.warning("Found load %s: '%s' with p_kw = %s. In load reference "
"system p_kw should be positive."
% (load, self.net.load.name.at[load],
self.net.load.p_kw.at[load]))

elif element_type is "gens":
if self.compact_report:
logger.warning("gens %s: wrong reference system."
% (diag_result[element_type]))
else:
for gen in diag_result[element_type]:
logger.warning("Found gen %s: '%s' with p_kw = %s. In load reference "
"system p_kw should be negative."
% (gen, self.net.gen.name.at[gen], self.net.gen.p_kw.at[gen]))

elif element_type is "sgens":
if self.compact_report:
logger.warning("sgens %s: wrong reference system."
% (diag_result[element_type]))
else:
for sgen in diag_result[element_type]:
logger.warning("Found sgen %s: '%s' with p_kw = %s. In load reference "
"system p_kw should be negative."
% (sgen, self.net.sgen.name.at[sgen], self.net.sgen.p_kw.at[sgen]))

# message summary
if not self.compact_report:
logger.warning("")
if 'loads' in diag_result:
logger.warning("SUMMARY: Found %s load(s) with negative p_kw. In load "
"reference system, p_kw should be positive. If the intention "
"was to model a constant generation, please use an sgen instead."
% (len(diag_result['loads'])))
if 'gens' in diag_result:
logger.warning("SUMMARY: Found %s gen(s) with positive p_kw. In load "
"reference system, p_kw should be negative. If the intention "
"was to model a load, please use a load instead."
% (len(diag_result['gens'])))
if 'sgens' in diag_result:
logger.warning("SUMMARY: Found %s sgen(s) with positive p_kw. In load "
"reference system, p_kw should be negative. If the intention "
"was to model a load, please use a load instead."
% (len(diag_result['sgens'])))

else:
logger.info("PASSED: power flow converges. No overload found.")
if diag_result == "check skipped":
logger.warning("check skipped due to possible bus index errors (see bus index check)")
else:
for element_type in diag_result:
if element_type is "loads":
if self.compact_report:
logger.warning("loads %s: wrong reference system."
% (diag_result[element_type]))
else:
for load in diag_result[element_type]:
logger.warning("Found load %s: '%s' with p_kw = %s. In load reference "
"system p_kw should be positive."
% (load, self.net.load.name.at[load],
self.net.load.p_kw.at[load]))

elif element_type is "gens":
if self.compact_report:
logger.warning("gens %s: wrong reference system."
% (diag_result[element_type]))
else:
for gen in diag_result[element_type]:
logger.warning("Found gen %s: '%s' with p_kw = %s. In load reference "
"system p_kw should be negative."
% (gen, self.net.gen.name.at[gen], self.net.gen.p_kw.at[gen]))

elif element_type is "sgens":
if self.compact_report:
logger.warning("sgens %s: wrong reference system."
% (diag_result[element_type]))
else:
for sgen in diag_result[element_type]:
logger.warning("Found sgen %s: '%s' with p_kw = %s. In load reference "
"system p_kw should be negative."
% (sgen, self.net.sgen.name.at[sgen], self.net.sgen.p_kw.at[sgen]))

# message summary
if not self.compact_report:
logger.warning("")
if 'loads' in diag_result:
logger.warning("SUMMARY: Found %s load(s) with negative p_kw. In load "
"reference system, p_kw should be positive. If the intention "
"was to model a constant generation, please use an sgen instead."
% (len(diag_result['loads'])))
if 'gens' in diag_result:
logger.warning("SUMMARY: Found %s gen(s) with positive p_kw. In load "
"reference system, p_kw should be negative. If the intention "
"was to model a load, please use a load instead."
% (len(diag_result['gens'])))
if 'sgens' in diag_result:
logger.warning("SUMMARY: Found %s sgen(s) with positive p_kw. In load "
"reference system, p_kw should be negative. If the intention "
"was to model a load, please use a load instead."
% (len(diag_result['sgens'])))

else:
logger.info("PASSED: power flow converges. No overload found.")


def report_deviation_from_std_type(self):
Expand Down
Loading

0 comments on commit 22dfc7e

Please sign in to comment.