Exemplo n.º 1
0
def convert_to_parameter_unit(unit_definition):
    unit = Unit()
    unit.name = unit_definition.get('name')
    unit.plural = unit_definition.get('plural_name')
    unit.abbreviation = unit_definition.get('abbreviation')
    unit.description = unit_definition.get('description')
    return unit
Exemplo n.º 2
0
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]
Exemplo n.º 3
0
    def test_all(self):
        """Basic test of all properties."""
        unit = Unit()
        unit.name = "meter"
        unit.plural = "metres"
        unit.abbreviation = "m"
        unit.description = (("<b>metres</b> are a metric unit of measure. There are 100 " "centimetres in 1 metre."),)
        unit.help_text = "Help for meter unit"

        parameter = ResourceParameter()
        parameter.is_required = True
        parameter.minimum_allowed_value = 1.0
        parameter.maximum_allowed_value = 2.0
        parameter.value = 1.123
        parameter.frequency = "weekly"
        parameter.unit = unit

        self.assertEqual(1.123, parameter.value)
        self.assertDictEqual(unit.serialize(), parameter.unit.serialize())
        self.assertEqual("weekly", parameter.frequency)
Exemplo n.º 4
0
    def test_all(self):
        """Basic test of all properties."""
        unit = Unit()
        unit.name = 'meter'
        unit.plural = 'metres'
        unit.abbreviation = 'm'
        unit.description = (
            '<b>metres</b> are a metric unit of measure. There are 100 '
            'centimetres in 1 metre.'),
        unit.help_text = 'Help for meter unit'

        parameter = ResourceParameter()
        parameter.is_required = True
        parameter.minimum_allowed_value = 1.0
        parameter.maximum_allowed_value = 2.0
        parameter.value = 1.123
        parameter.frequency = 'weekly'
        parameter.unit = unit

        self.assertEqual(1.123, parameter.value)
        self.assertDictEqual(unit.serialize(), parameter.unit.serialize())
        self.assertEqual('weekly', parameter.frequency)
Exemplo n.º 5
0
    def test_all(self):
        """Basic test of all properties."""
        unit = Unit()
        unit.name = 'meter'
        unit.plural = 'metres'
        unit.abbreviation = 'm'
        unit.description = (
            '<b>metres</b> are a metric unit of measure. There are 100 '
            'centimetres in 1 metre.'),
        unit.help_text = 'Help for meter unit'

        parameter = ResourceParameter()
        parameter.is_required = True
        parameter.minimum_allowed_value = 1.0
        parameter.maximum_allowed_value = 2.0
        parameter.value = 1.123
        parameter.frequency = 'weekly'
        parameter.unit = unit

        self.assertEqual(1.123, parameter.value)
        self.assertDictEqual(unit.serialize(), parameter.unit.serialize())
        self.assertEqual('weekly', parameter.frequency)
Exemplo n.º 6
0
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]
Exemplo n.º 7
0
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]
Exemplo n.º 8
0
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]