parser_combine_results_rule
Module for Parser CombineResultsRule class
!!! classes CombineResultsRuleParser
ParserCombineResultsRule (IParserRuleBase)
Class for creating a CombineResultsRuleData
Source code in parsers/parser_combine_results_rule.py
class ParserCombineResultsRule(IParserRuleBase):
"""Class for creating a CombineResultsRuleData"""
@property
def rule_type_name(self) -> str:
"""Type name for the rule"""
return "combine_results_rule"
def parse_dict(self, dictionary: Dict[str, Any], logger: ILogger) -> IRuleData:
"""Parses the provided dictionary to an IRuleData
Args:
dictionary (Dict[str, Any]): Dictionary holding the values
for making the rule
Returns:
RuleBase: Rule based on the provided data
"""
name = get_dict_element("name", dictionary, True)
input_variable_names = get_dict_element("input_variables", dictionary, True)
operation_type: str = get_dict_element("operation", dictionary, True)
self._validate_operation_type(operation_type)
operation_type = operation_type.upper()
output_variable_name = get_dict_element("output_variable", dictionary)
description = get_dict_element("description", dictionary, False)
if not description:
description = ""
ignore_nan = get_dict_element("ignore_nan", dictionary, False)
rule_data = CombineResultsRuleData(name, input_variable_names,
operation_type, ignore_nan)
rule_data.output_variable = output_variable_name
rule_data.description = description
return rule_data
def _validate_operation_type(self, operation_type: Any):
"""
Validates if the operation type is well formed (a string)
and if it has been implemented."""
if not isinstance(operation_type, str):
message = f"""Operation must be a string, \
received: {operation_type}"""
raise ValueError(message)
if operation_type.upper() not in dir(MultiArrayOperationType):
possible_operations = [
"\n" + operation_name
for operation_name in dir(MultiArrayOperationType)
if not operation_name.startswith("_")
]
message = f"""Operation must be one of: {possible_operations}"""
raise ValueError(message)
rule_type_name: str
property
readonly
Type name for the rule
parse_dict(self, dictionary, logger)
Parses the provided dictionary to an IRuleData
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dictionary |
Dict[str, Any] |
Dictionary holding the values for making the rule |
required |
Returns:
Type | Description |
---|---|
RuleBase |
Rule based on the provided data |
Source code in parsers/parser_combine_results_rule.py
def parse_dict(self, dictionary: Dict[str, Any], logger: ILogger) -> IRuleData:
"""Parses the provided dictionary to an IRuleData
Args:
dictionary (Dict[str, Any]): Dictionary holding the values
for making the rule
Returns:
RuleBase: Rule based on the provided data
"""
name = get_dict_element("name", dictionary, True)
input_variable_names = get_dict_element("input_variables", dictionary, True)
operation_type: str = get_dict_element("operation", dictionary, True)
self._validate_operation_type(operation_type)
operation_type = operation_type.upper()
output_variable_name = get_dict_element("output_variable", dictionary)
description = get_dict_element("description", dictionary, False)
if not description:
description = ""
ignore_nan = get_dict_element("ignore_nan", dictionary, False)
rule_data = CombineResultsRuleData(name, input_variable_names,
operation_type, ignore_nan)
rule_data.output_variable = output_variable_name
rule_data.description = description
return rule_data