def building_type_postprocessor(): """Get building-type parameter for postprocessing. :return: Selectors to activate building breakdown postprocessor. :rtype: list """ building_type = GroupParameter() building_type.name = tr('Building type') building_type.enable_parameter = True building_type.description = tr( 'Check this option if you want to enable a building impact report ' 'broken down by building type for each aggregation area.') unit_threshold = Unit() unit_threshold.name = tr('features') unit_threshold.plural = tr('features') unit_threshold.abbreviation = tr('features') unit_threshold.description = tr('Number of features.') threshold = IntegerParameter() threshold.name = 'Threshold' threshold.minimum_allowed_value = 1 # We shouldn't set a maximum, but there is a bug (#2468). threshold.maximum_allowed_value = 9999 threshold.value = 25 threshold.unit = unit_threshold threshold.allowed_units = [unit_threshold] threshold.help_text = tr('Threshold') threshold.description = tr( 'The threshold is used to consolidate small building usage groups ' 'which are within this threshold.') building_type.value = [threshold] return [building_type]
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 building_type_postprocessor(): """Get building-type parameter for postprocessing. :return: Selectors to activate building breakdown postprocessor. :rtype: list """ building_type = GroupParameter() building_type.name = tr('Building type') building_type.enable_parameter = True building_type.description = tr( 'Check this option if you want to enable a building impact report ' 'broken down by building type for each aggregation area.' ) unit_threshold = Unit() unit_threshold.name = tr('features') unit_threshold.plural = tr('features') unit_threshold.abbreviation = tr('features') unit_threshold.description = tr( 'Number of features.' ) threshold = IntegerParameter() threshold.name = 'Threshold' threshold.minimum_allowed_value = 1 # We shouldn't set a maximum, but there is a bug (#2468). threshold.maximum_allowed_value = 9999 threshold.value = 25 threshold.unit = unit_threshold threshold.allowed_units = [unit_threshold] threshold.help_text = tr('Threshold') threshold.description = tr( 'The threshold is used to consolidate small building usage groups ' 'which are within this threshold.' ) building_type.value = [threshold] return [building_type]
def age_postprocessor(): """Get age postprocessor selectors. :return: Selectors to activate age postprocessor. :rtype: list """ age = GroupParameter() age.name = 'Age' age.enable_parameter = True age.must_scroll = False age.help_text = tr('Age ratios breakdown.') age.description = tr( 'Check this option if you wish to calculate a breakdown by age group' 'for the affected population. ' ) unit_ratio = Unit() unit_ratio.name = tr('ratio') unit_ratio.plural = tr('ratios') unit_ratio.abbreviation = tr('ratio') unit_ratio.description = tr( 'Ratio represents a fraction of 1, so it ranges from 0 to 1.' ) youth_ratio = FloatParameter() youth_ratio.name = 'Youth ratio' youth_ratio.value = get_defaults('YOUTH_RATIO') youth_ratio.unit = unit_ratio youth_ratio.allowed_units = [unit_ratio] youth_ratio.help_text = tr('Youth ratio value.') youth_ratio.description = tr( 'Youth ratio defines what proportion of the population have not yet ' 'achieved financial independence. The age threshold for youth can ' 'vary by region - please consult with your local census bureau to find' 'out what the relevant threshold is in your region. InaSAFE does not ' 'impose a particular age ratio scheme - it will break down the ' 'population according to the thresholds you define for your locality.' 'In InaSAFE, people 0-14 years old are defined as "youth". The ' 'default youth ratio is 0.263.' ) adult_ratio = FloatParameter() adult_ratio.name = 'Adult ratio' adult_ratio.value = get_defaults('ADULT_RATIO') adult_ratio.unit = unit_ratio adult_ratio.allowed_units = [unit_ratio] adult_ratio.help_text = tr('Adult ratio value.') adult_ratio.description = tr( 'Adult ratio defines what proportion of the population have ' 'passed into adulthood and are not yet aged. The age threshold for ' 'adults can vary by region - please consult with your local census ' 'bureau to find out what the relevant threshold is in your region. ' 'InaSAFE does not impose a particular age ratio scheme - it will ' 'break down the population according to the thresholds you define ' 'for your locality.' 'In InaSAFE, people 15-64 years old are defined as "adult". The ' 'default adult ratio is 0.659.' ) elderly_ratio = FloatParameter() elderly_ratio.name = 'Elderly ratio' elderly_ratio.value = get_defaults('ELDERLY_RATIO') elderly_ratio.unit = unit_ratio elderly_ratio.allowed_units = [unit_ratio] elderly_ratio.help_text = tr('Elderly ratio value.') elderly_ratio.description = tr( 'Elderly ratio defines what proportion of the population have ' 'passed from adulthood into their later life stage. The age ' 'threshold for being considered elderly can vary by region - please ' 'consult with your local census bureau to find out what the relevant ' 'threshold is in your region. InaSAFE does not impose a particular ' 'age ratio scheme - it will break down the population according to ' 'the thresholds you define for your locality.' 'In InaSAFE, people 65 years old and over are defined as "elderly". ' 'The default elderly ratio is 0.078.' ) age.value = [youth_ratio, adult_ratio, elderly_ratio] def _age_validator(parameters=None): total_ratio = 0 for p in parameters: total_ratio += p.value if not total_ratio == 1: message = tr('Total Age ratio is %s instead of 1') % total_ratio raise ValueError(message) age.custom_validator = _age_validator return [age]
def age_postprocessor(): """Get age postprocessor selectors. :return: Selectors to activate age postprocessor. :rtype: list """ age = GroupParameter() age.name = 'Age' age.enable_parameter = True age.must_scroll = False age.help_text = tr('Age ratios breakdown.') age.description = tr( 'Check this option if you wish to calculate a breakdown by age group' 'for the affected population. ') unit_ratio = Unit() unit_ratio.name = tr('ratio') unit_ratio.plural = tr('ratios') unit_ratio.abbreviation = tr('ratio') unit_ratio.description = tr( 'Ratio represents a fraction of 1, so it ranges from 0 to 1.') youth_ratio = FloatParameter() youth_ratio.name = 'Youth ratio' youth_ratio.value = get_defaults('YOUTH_RATIO') youth_ratio.unit = unit_ratio youth_ratio.allowed_units = [unit_ratio] youth_ratio.help_text = tr('Youth ratio value.') youth_ratio.description = tr( 'Youth ratio defines what proportion of the population have not yet ' 'achieved financial independence. The age threshold for youth can ' 'vary by region - please consult with your local census bureau to find' 'out what the relevant threshold is in your region. InaSAFE does not ' 'impose a particular age ratio scheme - it will break down the ' 'population according to the thresholds you define for your locality.' 'In InaSAFE, people 0-14 years old are defined as "youth". The ' 'default youth ratio is 0.263.') adult_ratio = FloatParameter() adult_ratio.name = 'Adult ratio' adult_ratio.value = get_defaults('ADULT_RATIO') adult_ratio.unit = unit_ratio adult_ratio.allowed_units = [unit_ratio] adult_ratio.help_text = tr('Adult ratio value.') adult_ratio.description = tr( 'Adult ratio defines what proportion of the population have ' 'passed into adulthood and are not yet aged. The age threshold for ' 'adults can vary by region - please consult with your local census ' 'bureau to find out what the relevant threshold is in your region. ' 'InaSAFE does not impose a particular age ratio scheme - it will ' 'break down the population according to the thresholds you define ' 'for your locality.' 'In InaSAFE, people 15-64 years old are defined as "adult". The ' 'default adult ratio is 0.659.') elderly_ratio = FloatParameter() elderly_ratio.name = 'Elderly ratio' elderly_ratio.value = get_defaults('ELDERLY_RATIO') elderly_ratio.unit = unit_ratio elderly_ratio.allowed_units = [unit_ratio] elderly_ratio.help_text = tr('Elderly ratio value.') elderly_ratio.description = tr( 'Elderly ratio defines what proportion of the population have ' 'passed from adulthood into their later life stage. The age ' 'threshold for being considered elderly can vary by region - please ' 'consult with your local census bureau to find out what the relevant ' 'threshold is in your region. InaSAFE does not impose a particular ' 'age ratio scheme - it will break down the population according to ' 'the thresholds you define for your locality.' 'In InaSAFE, people 65 years old and over are defined as "elderly". ' 'The default elderly ratio is 0.078.') age.value = [youth_ratio, adult_ratio, elderly_ratio] def _age_validator(parameters=None): total_ratio = 0 for p in parameters: total_ratio += p.value if not total_ratio == 1: message = tr('Total Age ratio is %s instead of 1') % total_ratio raise ValueError(message) age.custom_validator = _age_validator return [age]
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