def _validate_recommendation_settings()

in src/lambdas/r8s_api_handler/processors/algorithm_processor.py [0:0]


    def _validate_recommendation_settings(self, recommendation_settings):
        if not recommendation_settings:
            return
        field_type_mapping = {
            RECORD_STEP_MINUTES_ATTR: int,
            THRESHOLDS_ATTR: list,
            MIN_ALLOWED_DAYS_ATTR: int,
            MAX_DAYS_ATTR: int,
            MIN_ALLOWED_DAYS_SCHEDULE_ATTR: int,
            IGNORE_SAVINGS_ATTR: bool,
            MAX_RECOMMENDED_SHAPES_ATTR: int,
            SHAPE_COMPATIBILITY_RULE_ATTR: str,
            SHAPE_SORTING_ATTR: str,
            USE_PAST_RECOMMENDATIONS_ATTR: bool,
            USE_INSTANCE_TAGS_ATTR: bool,
            ANALYSIS_PRICE_ATTR: str,
            IGNORE_ACTIONS_ATTR: list,
            TARGET_TIMEZONE_NAME_ATTR: str,
            DISCARD_INITIAL_ZEROS_ATTR: bool,
            FORBID_CHANGE_FAMILY_ATTR: bool,
            FORBID_CHANGE_SERIES_ATTR: bool
        }
        errors = self._validate_dict_value_types(
            d=recommendation_settings,
            field_type_mapping=field_type_mapping)

        thresholds = recommendation_settings.get(THRESHOLDS_ATTR)
        if thresholds is not None:
            if len(thresholds) != 3:
                errors.append(f'Exactly 3 threshold values '
                              f'must be provided')
            if not all([isinstance(i, int) for i in thresholds]):
                errors.append(f'All of the specified threshold values must '
                              f'be a valid integers.')

        compatibility_rule = recommendation_settings.get(
            SHAPE_COMPATIBILITY_RULE_ATTR)
        errors.append(self._validate_enum_field(
            attr_name=SHAPE_COMPATIBILITY_RULE_ATTR,
            value=compatibility_rule,
            enum_=ShapeCompatibilityRule
        ))

        shape_sorting = recommendation_settings.get(SHAPE_SORTING_ATTR)
        errors.append(self._validate_enum_field(
            attr_name=SHAPE_SORTING_ATTR,
            value=shape_sorting,
            enum_=ShapeSorting
        ))

        if TARGET_TIMEZONE_NAME_ATTR in recommendation_settings:
            target_timezone_name = recommendation_settings.get(
                TARGET_TIMEZONE_NAME_ATTR)
            if not target_timezone_name:
                errors.append(f'target_timezone_name can not be empty.')

        errors = [i for i in errors if i]
        if errors:
            _LOG.error(f'{",".join(errors)}')
            return build_response(
                code=RESPONSE_BAD_REQUEST_CODE,
                content=f'{",".join(errors)}'
            )