Skip to content

Commit

Permalink
reduce complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosmc committed Dec 18, 2024
1 parent e72557d commit 8f71856
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 84 deletions.
101 changes: 57 additions & 44 deletions src/dgcv/report/tables/compliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -123,4 +134,6 @@ def create_map(results: dict) -> list:
]
)

_add_times(results, compliance_map)

return compliance_map
84 changes: 44 additions & 40 deletions src/dgcv/report/tables/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down Expand Up @@ -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

0 comments on commit 8f71856

Please sign in to comment.