criteria_table_validaton_helper
Module for validation logic of the (ClassificationRule) criteria table
validate_table_coverage(crit_table, logger)
Check if the criteria for the parameters given in the criteria_table cover the entire range of data values. If not give the user feedback (warnings) concerning gaps and overlaps.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
crit_table |
Dict[str, Any] |
User input describing criteria per parameter |
required |
Source code in parsers/criteria_table_validaton_helper.py
def validate_table_coverage(crit_table: Dict[str, Any], logger: ILogger):
"""Check if the criteria for the parameters given in the criteria_table
cover the entire range of data values. If not give the user feedback (warnings)
concerning gaps and overlaps.
Args:
crit_table (Dict[str, Any]): User input describing criteria per parameter
"""
criteria_table = crit_table.copy()
del criteria_table["output"]
new_crit_table = criteria_table.copy()
unique = True
# If only 1 parameter is given in the criteria_table check the first parameter
# on all values and not only the unique values.
if len(new_crit_table.items()) == 1:
unique = False
# Make a loop over all variables from right to left to check combinations
msgs = []
for key in reversed(criteria_table.keys()):
msgs = msgs + list(
_divide_table_in_unique_chunks(new_crit_table, logger, {}, unique)
)
del new_crit_table[key]
max_msg = 6
if len(msgs) < max_msg:
logger.log_warning("\n".join(msgs))
else:
# Only show the first 6 lines. Print all msgs to a txt file.
logger.log_warning("\n".join(msgs[:max_msg]))
logger.log_warning(
f"{len(msgs)} warnings found concerning coverage of the "
f"parameters. Only first {max_msg} warnings are shown. See "
"multiple_classification_rule_warnings.log file for all warnings."
)
with open(
"multiple_classification_rule_warnings.log", "w", encoding="utf-8"
) as file:
file.write("\n".join(msgs))