From 8f71856e1fb852e7c509a595e6480b97e5ecd7f6 Mon Sep 17 00:00:00 2001 From: marcosmc Date: Wed, 18 Dec 2024 14:38:29 +0100 Subject: [PATCH] reduce complexity --- src/dgcv/report/tables/compliance.py | 101 +++++++++++++++------------ src/dgcv/report/tables/results.py | 84 +++++++++++----------- 2 files changed, 101 insertions(+), 84 deletions(-) diff --git a/src/dgcv/report/tables/compliance.py b/src/dgcv/report/tables/compliance.py index dd6f044..cdbff2e 100644 --- a/src/dgcv/report/tables/compliance.py +++ b/src/dgcv/report/tables/compliance.py @@ -10,6 +10,61 @@ from dgcv.report import printable +def _add_simple_times(results: dict, compliance_map: list): + if "time_5U" in results: + time_5U = printable.format_value(results, "time_5U", apply_formatter=True) + check = printable.format_value(results, "time_5U_check") + compliance_map.append(["$T_{5U} < 10 s$", time_5U, check]) + if "time_10U" in results: + time_10U = printable.format_value(results, "time_10U", apply_formatter=True) + check = printable.format_value(results, "time_10U_check") + compliance_map.append(["$T_{10U} < 5 s$", time_10U, check]) + if "time_5P" in results and not ("time_5P_85U" in results or "time_5P_clear" in results): + time_5P = printable.format_value(results, "time_5P", apply_formatter=True) + check = printable.format_value(results, "time_5P_check") + compliance_map.append(["$T_{5P} < 10 s$", time_5P, check]) + if "time_5P_clear" in results: + time_5P_clear = printable.format_value(results, "time_5P_clear", apply_formatter=True) + check = printable.format_value(results, "time_5P_clear_check") + compliance_map.append(["$T_{5P} - T_{clear} < 10 s$", time_5P_clear, check]) + if "time_10P" in results and not ("time_10P_85U" in results or "time_10P_clear" in results): + time_10P = printable.format_value(results, "time_10P", apply_formatter=True) + check = printable.format_value(results, "time_10P_check") + compliance_map.append(["$T_{10P} < 5 s$", time_10P, check]) + if "time_10P_clear" in results: + time_10P_clear = printable.format_value(results, "time_10P_clear", apply_formatter=True) + check = printable.format_value(results, "time_10P_clear_check") + compliance_map.append(["$T_{10P} - T_{clear} < 5 s$", time_10P_clear, check]) + if "time_10Pfloor_clear" in results: + time_10Pfloor_clear = printable.format_value( + results, "time_10Pfloor_clear", apply_formatter=True + ) + check = printable.format_value(results, "time_10Pfloor_clear_check") + compliance_map.append(["$T_{10P_{floor}} - T_{clear} < 2 s$", time_10Pfloor_clear, check]) + + +def _add_composed_times(results: dict, compliance_map: list): + if "time_5P_85U" in results: + time_5P_85U = printable.format_value(results, "time_5P_85U", apply_formatter=True) + check = printable.format_value(results, "time_5P_85U_check") + compliance_map.append(["$T_{5P} - T_{85U} < 10 s$", time_5P_85U, check]) + if "time_10P_85U" in results: + time_10P_85U = printable.format_value(results, "time_10P_85U", apply_formatter=True) + check = printable.format_value(results, "time_10P_85U_check") + compliance_map.append(["$T_{10P} - T_{85U} < 5 s$", time_10P_85U, check]) + if "time_10Pfloor_85U" in results: + time_10Pfloor_85U = printable.format_value( + results, "time_10Pfloor_85U", apply_formatter=True + ) + check = printable.format_value(results, "time_10Pfloor_85U_check") + compliance_map.append(["$T_{10P_{floor}} - T_{85U} < 2 s$", time_10Pfloor_85U, check]) + + +def _add_times(results: dict, compliance_map: list): + _add_simple_times(results, compliance_map) + _add_composed_times(results, compliance_map) + + def create_map(results: dict) -> list: """Creates a list to populate the compliance table in the LaTeX reports @@ -62,50 +117,6 @@ def create_map(results: dict) -> list: check, ] ) - if "time_5U" in results: - time_5U = printable.format_value(results, "time_5U", apply_formatter=True) - check = printable.format_value(results, "time_5U_check") - compliance_map.append(["$T_{5U} < 10 s$", time_5U, check]) - if "time_10U" in results: - time_10U = printable.format_value(results, "time_10U", apply_formatter=True) - check = printable.format_value(results, "time_10U_check") - compliance_map.append(["$T_{10U} < 5 s$", time_10U, check]) - if "time_5P" in results and not ("time_5P_85U" in results or "time_5P_clear" in results): - time_5P = printable.format_value(results, "time_5P", apply_formatter=True) - check = printable.format_value(results, "time_5P_check") - compliance_map.append(["$T_{5P} < 10 s$", time_5P, check]) - if "time_5P_85U" in results: - time_5P_85U = printable.format_value(results, "time_5P_85U", apply_formatter=True) - check = printable.format_value(results, "time_5P_85U_check") - compliance_map.append(["$T_{5P} - T_{85U} < 10 s$", time_5P_85U, check]) - if "time_5P_clear" in results: - time_5P_clear = printable.format_value(results, "time_5P_clear", apply_formatter=True) - check = printable.format_value(results, "time_5P_clear_check") - compliance_map.append(["$T_{5P} - T_{clear} < 10 s$", time_5P_clear, check]) - if "time_10P" in results and not ("time_10P_85U" in results or "time_10P_clear" in results): - time_10P = printable.format_value(results, "time_10P", apply_formatter=True) - check = printable.format_value(results, "time_10P_check") - compliance_map.append(["$T_{10P} < 5 s$", time_10P, check]) - if "time_10P_85U" in results: - time_10P_85U = printable.format_value(results, "time_10P_85U", apply_formatter=True) - check = printable.format_value(results, "time_10P_85U_check") - compliance_map.append(["$T_{10P} - T_{85U} < 5 s$", time_10P_85U, check]) - if "time_10P_clear" in results: - time_10P_clear = printable.format_value(results, "time_10P_clear", apply_formatter=True) - check = printable.format_value(results, "time_10P_clear_check") - compliance_map.append(["$T_{10P} - T_{clear} < 5 s$", time_10P_clear, check]) - if "time_10Pfloor_85U" in results: - time_10Pfloor_85U = printable.format_value( - results, "time_10Pfloor_85U", apply_formatter=True - ) - check = printable.format_value(results, "time_10Pfloor_85U_check") - compliance_map.append(["$T_{10P_{floor}} - T_{85U} < 2 s$", time_10Pfloor_85U, check]) - if "time_10Pfloor_clear" in results: - time_10Pfloor_clear = printable.format_value( - results, "time_10Pfloor_clear", apply_formatter=True - ) - check = printable.format_value(results, "time_10Pfloor_clear_check") - compliance_map.append(["$T_{10P_{floor}} - T_{clear} < 2 s$", time_10Pfloor_clear, check]) if "static_diff" in results: static_diff = printable.format_value(results, "static_diff", apply_formatter=True) check = printable.format_value(results, "static_diff_check") @@ -123,4 +134,6 @@ def create_map(results: dict) -> list: ] ) + _add_times(results, compliance_map) + return compliance_map diff --git a/src/dgcv/report/tables/results.py b/src/dgcv/report/tables/results.py index 08bd3e9..4c3923a 100644 --- a/src/dgcv/report/tables/results.py +++ b/src/dgcv/report/tables/results.py @@ -10,46 +10,7 @@ from dgcv.report import printable -def create_map(results: dict) -> list: - """Creates a list to populate the results table in the LaTex reports - - Parameters - ---------- - results: dict - Results of the validations applied in the pcs - - Returns - ------- - list - Results table - """ - results_map = [] - - if "time_10U" in results: - time_10U = printable.format_value(results, "time_10U", apply_formatter=True) - results_map.append(["$T_{10U}$", time_10U + " s"]) - if "time_5U" in results: - time_5U = printable.format_value(results, "time_5U", apply_formatter=True) - results_map.append(["$T_{5U}$", time_5U + " s"]) - if "time_10P" in results: - time_10P = printable.format_value(results, "time_10P", apply_formatter=True) - results_map.append(["$T_{10P}$", time_10P + " s"]) - if "time_10Pfloor" in results: - time_10Pfloor = printable.format_value(results, "time_10Pfloor", apply_formatter=True) - results_map.append(["$T_{10P_{floor}}$", time_10Pfloor + " s"]) - if "time_5P" in results: - time_5P = printable.format_value(results, "time_5P", apply_formatter=True) - results_map.append(["$T_{5P}$", time_5P + " s"]) - if "time_85U" in results: - time_85U = printable.format_value(results, "time_85U", apply_formatter=True) - results_map.append(["$T_{85U}$", time_85U + " s"]) - if "time_cct" in results: - time_cct = printable.format_value(results, "time_cct", apply_formatter=True) - results_map.append(["$T_{cct}$", time_cct + " s"]) - if "static_diff" in results: - static_diff = printable.format_value(results, "static_diff", apply_formatter=True) - results_map.append(["$\epsilon$", static_diff]) - +def _iterate_variables(results: dict, results_map: list): variables = [ ["voltage", "V"], ["active_power", "P"], @@ -143,4 +104,47 @@ def create_map(results: dict) -> list: [col, before_mxe, before_me, before_mae, after_mxe, after_me, after_mae] ) + +def create_map(results: dict) -> list: + """Creates a list to populate the results table in the LaTex reports + + Parameters + ---------- + results: dict + Results of the validations applied in the pcs + + Returns + ------- + list + Results table + """ + results_map = [] + + if "time_10U" in results: + time_10U = printable.format_value(results, "time_10U", apply_formatter=True) + results_map.append(["$T_{10U}$", time_10U + " s"]) + if "time_5U" in results: + time_5U = printable.format_value(results, "time_5U", apply_formatter=True) + results_map.append(["$T_{5U}$", time_5U + " s"]) + if "time_10P" in results: + time_10P = printable.format_value(results, "time_10P", apply_formatter=True) + results_map.append(["$T_{10P}$", time_10P + " s"]) + if "time_10Pfloor" in results: + time_10Pfloor = printable.format_value(results, "time_10Pfloor", apply_formatter=True) + results_map.append(["$T_{10P_{floor}}$", time_10Pfloor + " s"]) + if "time_5P" in results: + time_5P = printable.format_value(results, "time_5P", apply_formatter=True) + results_map.append(["$T_{5P}$", time_5P + " s"]) + if "time_85U" in results: + time_85U = printable.format_value(results, "time_85U", apply_formatter=True) + results_map.append(["$T_{85U}$", time_85U + " s"]) + if "time_cct" in results: + time_cct = printable.format_value(results, "time_cct", apply_formatter=True) + results_map.append(["$T_{cct}$", time_cct + " s"]) + if "static_diff" in results: + static_diff = printable.format_value(results, "static_diff", apply_formatter=True) + results_map.append(["$\epsilon$", static_diff]) + + _iterate_variables(results, results_map) + return results_map