def categorical_thresholds(): field = GroupParameter() field.must_scroll = False field.name = 'Categorical thresholds' field.is_required = True field.help_text = tr('Hazard classes thresholds.') field.description = tr( 'Describe the upper thresholds of each hazard class. Each threshold ' 'should be greater value than previous one.') field.value = [ low_hazard_class(), medium_hazard_class(), high_hazard_class() ] field.custom_validator = increasing_validator return field
def threshold_group_parameter(): """Generate group parameter of threshold to define constraints. :return: a group parameter :rtype: GroupParameter """ field = GroupParameter() field.name = 'Hazard Threshold' field.is_required = True field.help_text = tr('Define thresholds for Ash hazard zones.') field.description = tr('Define thresholds for Ash hazard zones.') unaffected = unaffected_threshold() very_low = very_low_threshold() low = low_threshold() moderate = moderate_threshold() high = high_threshold() field.value_map = { 'unaffected_threshold': unaffected, 'very_low_threshold': very_low, 'low_threshold': low, 'moderate_threshold': moderate, 'high_threshold': high } field.value = [unaffected, very_low, low, moderate, high] def threshold_validator(param): """Inspect the value of the parameter :param param: FloatParameter in validation :type param: FloatParameter :returns: True if valid :rtype: bool """ valid = True message = None if ((param == unaffected and param.value >= very_low.value) or (param == very_low and param.value < unaffected.value)): message = tr( 'Unaffected threshold must less than Very Low threshold') valid = False if ((param == very_low and param.value >= low.value) or (param == low and param.value < very_low.value)): message = tr('Very Low threshold must less than Low threshold') valid = False if ((param == low and param.value >= moderate.value) or (param == moderate and param.value < low.value)): message = tr('Low threshold must less than Moderate threshold') valid = False if ((param == moderate and param.value >= high.value) or (param == high and param.value < moderate.value)): message = tr('Moderate threshold must less than High threshold') valid = False if not valid: raise ValueError(message) return valid field.custom_validator = threshold_validator return field
def threshold_group_parameter(): """Generate group parameter of threshold to define constraints. :return: a group parameter :rtype: GroupParameter """ field = GroupParameter() field.name = 'Hazard Threshold' field.is_required = True field.help_text = tr('Define thresholds for Ash hazard zones.') field.description = tr('Define thresholds for Ash hazard zones.') unaffected = unaffected_threshold() very_low = very_low_threshold() low = low_threshold() moderate = moderate_threshold() high = high_threshold() field.value_map = { 'unaffected_threshold': unaffected, 'very_low_threshold': very_low, 'low_threshold': low, 'moderate_threshold': moderate, 'high_threshold': high } field.value = [ unaffected, very_low, low, moderate, high ] def threshold_validator(param): """Inspect the value of the parameter :param param: FloatParameter in validation :type param: FloatParameter :returns: True if valid :rtype: bool """ valid = True message = None if ((param == unaffected and param.value >= very_low.value) or (param == very_low and param.value < unaffected.value)): message = tr( 'Unaffected threshold must less than Very Low threshold') valid = False if ((param == very_low and param.value >= low.value) or (param == low and param.value < very_low.value)): message = tr( 'Very Low threshold must less than Low threshold') valid = False if ((param == low and param.value >= moderate.value) or (param == moderate and param.value < low.value)): message = tr( 'Low threshold must less than Moderate threshold') valid = False if ((param == moderate and param.value >= high.value) or (param == high and param.value < moderate.value)): message = tr( 'Moderate threshold must less than High threshold') valid = False if not valid: raise ValueError(message) return valid field.custom_validator = threshold_validator return field