Skip to content

parser_rolling_statistics_rule

Module for ParserRollingStatisticsRule class

!!! classes ParserRollingStatisticsRule

ParserRollingStatisticsRule (IParserRuleBase)

Class for creating a RollingStatisticsRuleData

Source code in parsers/parser_rolling_statistics_rule.py
class ParserRollingStatisticsRule(IParserRuleBase):
    """Class for creating a RollingStatisticsRuleData"""

    @property
    def rule_type_name(self) -> str:
        """Type name for the rule"""
        return "rolling_statistics_rule"

    def parse_dict(self, dictionary: Dict[str, Any], logger: ILogger) -> IRuleData:
        """Parses the provided dictionary to a IRuleData
        Args:
            dictionary (Dict[str, Any]): Dictionary holding the values
                                         for making the rule
        Returns:
            RuleBase: Rule based on the provided data
        """
        # get elements
        name: str = get_dict_element("name", dictionary)
        input_variable_name: str = get_dict_element("input_variable", dictionary)
        operation: str = get_dict_element("operation", dictionary)
        time_scale: str = get_dict_element("time_scale", dictionary)
        period: float = get_dict_element("period", dictionary)
        description = get_dict_element("description", dictionary, False)
        output_variable_name = get_dict_element("output_variable", dictionary)

        if not period:
            message = f"Period is not of a predefined type. Should be  \
                      a float or integer value. Received: {period}"
            raise ValueError(message)

        operation_value, percentile_value = parse_operation_values(operation)

        rule_data = RollingStatisticsRuleData(
            name, operation_value, input_variable_name, period
        )

        rule_data.time_scale = time_scale
        rule_data.percentile_value = percentile_value
        rule_data.output_variable = output_variable_name
        rule_data.description = description

        return rule_data

rule_type_name: str property readonly

Type name for the rule

parse_dict(self, dictionary, logger)

Parses the provided dictionary to a 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_rolling_statistics_rule.py
def parse_dict(self, dictionary: Dict[str, Any], logger: ILogger) -> IRuleData:
    """Parses the provided dictionary to a IRuleData
    Args:
        dictionary (Dict[str, Any]): Dictionary holding the values
                                     for making the rule
    Returns:
        RuleBase: Rule based on the provided data
    """
    # get elements
    name: str = get_dict_element("name", dictionary)
    input_variable_name: str = get_dict_element("input_variable", dictionary)
    operation: str = get_dict_element("operation", dictionary)
    time_scale: str = get_dict_element("time_scale", dictionary)
    period: float = get_dict_element("period", dictionary)
    description = get_dict_element("description", dictionary, False)
    output_variable_name = get_dict_element("output_variable", dictionary)

    if not period:
        message = f"Period is not of a predefined type. Should be  \
                  a float or integer value. Received: {period}"
        raise ValueError(message)

    operation_value, percentile_value = parse_operation_values(operation)

    rule_data = RollingStatisticsRuleData(
        name, operation_value, input_variable_name, period
    )

    rule_data.time_scale = time_scale
    rule_data.percentile_value = percentile_value
    rule_data.output_variable = output_variable_name
    rule_data.description = description

    return rule_data