def test_init(self):
        """Test initialize qt4 parameter factory."""

        boolean_parameter = BooleanParameter('1231231')
        boolean_parameter.name = 'Boolean'
        boolean_parameter.help_text = 'A boolean parameter'
        boolean_parameter.description = 'A test _description'
        boolean_parameter.is_required = True
        boolean_parameter.value = True

        float_parameter = FloatParameter()
        float_parameter.name = 'Float Parameter'
        float_parameter.is_required = True
        float_parameter.precision = 3
        float_parameter.minimum_allowed_value = 1.0
        float_parameter.maximum_allowed_value = 2.0
        float_parameter.help_text = 'Short help.'
        float_parameter.description = 'Long description for parameter.'
        float_parameter.unit = 'metres'
        float_parameter.value = 1.1

        parameters = [boolean_parameter, float_parameter]

        qt4_parameter_factory = Qt4ParameterFactory()
        widgets = []
        widget_classes = []

        for parameter in parameters:
            widget = qt4_parameter_factory.get_widget(parameter)
            widgets.append(widget)
            widget_classes.append(widget.__class__)

        expected_classes = [BooleanParameterWidget, FloatParameterWidget]
        message = 'Expected %s got %s' % (expected_classes, widget_classes)
        self.assertListEqual(widget_classes, expected_classes, message)
Пример #2
0
def max_threshold():
    """Generator for the default threshold parameter.

    :return: List of FloatParameter
    :rtype: list[FloatParameter]
    """
    field = FloatParameter()
    field.name = 'Maximum Thresholds [m]'
    field.is_required = True
    field.precision = 2
    field.value = sys.float_info.max  # default value
    unit_metres = parameter_unit_metres()
    field.unit = unit_metres
    field.allowed_units = [unit_metres]
    field.help_text = tr('Maximum value of hazard considered as inundated.')
    field.description = tr('The depth of flood in meter as threshold.')
    return field
Пример #3
0
def threshold():
    """Generator for the default threshold parameter.

    :return: List of FloatParameter
    :rtype: list[FloatParameter]
    """
    field = FloatParameter()
    field.name = tr('Thresholds [m]')
    field.is_required = True
    field.precision = 2
    field.value = 1.0  # default value
    unit_metres = parameter_unit_metres()
    field.unit = unit_metres
    field.allowed_units = [unit_metres]
    field.help_text = tr(
        'Threshold value to categorize inundated area.')
    field.description = tr(
        'Hazard value above the threshold in meter will be considered '
        'inundated.')
    return field
Пример #4
0
def high_hazard_class():
    """Parameter definition.

    :returns: High Hazard Class parameter
    :rtype: FloatParameter
    """
    field = FloatParameter()
    field.name = 'High Hazard Class'
    field.element_type = float
    field.value = 3.0
    unit_generic = parameter_unit_generic()
    field.unit = unit_generic
    field.allowed_units = [unit_generic]
    field.help_text = tr('High Hazard class value.')
    field.description = tr(
        'The value of hazard categorized as High Hazard class')
    return field
Пример #5
0
def low_hazard_class():
    """Parameter definition.

    :returns: Low Hazard Class parameter
    :rtype: FloatParameter
    """
    field = FloatParameter()
    field.name = 'Low Hazard Threshold'
    field.element_type = float
    field.value = 0.34
    field.help_text = tr('Low Hazard class thresholds.')
    field.description = tr(
        'Threshold value of hazard categorized as Low Hazard class.')
    return field
Пример #6
0
    def test_all(self):
        """Basic test of all properties."""
        parameter = FloatParameter()
        parameter.is_required = True
        parameter.minimum_allowed_value = 1.0
        parameter.maximum_allowed_value = 2.0
        parameter.value = 1.123

        self.assertEqual(1.123, parameter.value)

        with self.assertRaises(TypeError):
            parameter.value = 'Test'

        with self.assertRaises(ValueOutOfBounds):
            parameter.value = 3.0

        with self.assertRaises(ValueOutOfBounds):
            parameter.value = 0.5
Пример #7
0
def high_hazard_class():
    """Parameter definition.

    :returns: High Hazard Class parameter
    :rtype: FloatParameter
    """
    field = FloatParameter()
    field.name = 'High Hazard Threshold'
    field.element_type = float
    field.value = 1.0
    field.help_text = tr('High Hazard class threshold.')
    field.description = tr(
        'Threshold value of hazard categorized as High Hazard class. It '
        'should be greater than Medium Hazard Thresholds')
    return field
Пример #8
0
    def test_set_minimum_allowed_value(self):
        """Test setter for minimum allowed value."""
        parameter = FloatParameter()

        with self.assertRaises(TypeError):
            parameter.maximum_allowed_value = 'One thousand'

        parameter.minimum_allowed_value = 1

        parameter.minimum_allowed_value = 1.0
        # Also check that it raises an error if it exceeds max
        parameter.maximum_allowed_value = 10.0
        with self.assertRaises(InvalidMinimumError):
            parameter.minimum_allowed_value = 11.0

        # Also check that when we set a value it falls within [min, max]
        parameter.value = 5
Пример #9
0
    def test_set_maximum_allowed_value(self):
        """Test setter for maximum allowed value."""
        parameter = FloatParameter()

        with self.assertRaises(TypeError):
            parameter.maximum_allowed_value = 'One million'

        parameter.maximum_allowed_value = 1000

        parameter.maximum_allowed_value = 11.0
        # Also check that it raises an error if it precedes min
        parameter.minimum_allowed_value = 10.0

        with self.assertRaises(InvalidMaximumError):
            parameter.maximum_allowed_value = 1.0

        # Also check that when we set a value it falls within [min, max]
        parameter.value = 10.5
Пример #10
0
    def test_init(self):

        unit_feet = Unit('130790')
        unit_feet.load_dictionary(unit_feet_depth)

        unit_metres = Unit('900713')
        unit_metres.load_dictionary(unit_metres_depth)

        float_parameter = FloatParameter()
        float_parameter.name = 'Flood Depth'
        float_parameter.is_required = True
        float_parameter.precision = 3
        float_parameter.minimum_allowed_value = 1.0
        float_parameter.maximum_allowed_value = 2.0
        float_parameter.help_text = 'The depth of flood.'
        float_parameter.description = (
            'A <b>test _description</b> that is very long so that you need '
            'to read it for one minute and you will be tired after read this '
            'description. You are the best user so far. Even better if you '
            'read this description loudly so that all of your friends will be '
            'able to hear you')
        float_parameter.unit = unit_feet
        float_parameter.allowed_units = [unit_metres, unit_feet]
        float_parameter.value = 1.12

        widget = FloatParameterWidget(float_parameter)

        expected_value = float_parameter.name
        real_value = widget._label.text()
        message = 'Expected %s get %s' % (expected_value, real_value)
        self.assertEqual(expected_value, real_value, message)

        expected_value = float_parameter.value
        real_value = widget.get_parameter().value
        message = 'Expected %s get %s' % (expected_value, real_value)
        self.assertEqual(expected_value, real_value, message)

        widget._input.setValue(1.5)

        expected_value = 1.5
        real_value = widget.get_parameter().value
        message = 'Expected %s get %s' % (expected_value, real_value)
        self.assertEqual(expected_value, real_value, message)

        widget._input.setValue(1.55555)

        expected_value = 1.556
        real_value = widget.get_parameter().value
        message = 'Expected %s get %s' % (expected_value, real_value)
        self.assertEqual(expected_value, real_value, message)

        widget._input.setValue(7)

        expected_value = 2
        real_value = widget.get_parameter().value
        message = 'Expected %s get %s' % (expected_value, real_value)
        self.assertEqual(expected_value, real_value, message)

        expected_value = 'QComboBox'
        real_value = widget._unit_widget.__class__.__name__
        message = 'Expected %s get %s' % (expected_value, real_value)
        self.assertEqual(expected_value, real_value, message)

        expected_value = 'feet'
        real_value = widget.get_parameter().unit.name
        message = 'Expected %s get %s' % (expected_value, real_value)
        self.assertEqual(expected_value, real_value, message)

        expected_value = 'metres'
        widget._unit_widget.setCurrentIndex(0)
        real_value = widget.get_parameter().unit.name
        message = 'Expected %s get %s' % (expected_value, real_value)
        self.assertEqual(expected_value, real_value, message)
Пример #11
0
    def default_field_to_parameter(self, default_field):
        """Obtain parameter from default field.

        :param default_field: A default field definition.
        :type default_field: dict

        :returns: A parameter object.
        :rtype: FloatParameter, IntegerParameter
        """
        if default_field.get('type') == QVariant.Double:
            parameter = FloatParameter()
        elif default_field.get('type') in qvariant_whole_numbers:
            parameter = IntegerParameter()
        else:
            return
        default_value = default_field.get('default_value')
        if not default_value:
            message = (
                'InaSAFE default field %s does not have default value'
                % default_field.get('name'))
            LOGGER.exception(message)
            return

        parameter.guid = default_field.get('key')
        parameter.name = default_value.get('name')
        parameter.is_required = True
        parameter.precision = default_field.get('precision')
        parameter.minimum_allowed_value = default_value.get(
            'min_value', 0)
        parameter.maximum_allowed_value = default_value.get(
            'max_value', 100000000)
        parameter.help_text = default_value.get('help_text')
        parameter.description = default_value.get('description')

        # Check if user ask to restore to the most default value.
        if self.is_restore_default:
            parameter._value = default_value.get('default_value')
        else:
            # Current value
            qsetting_default_value = get_inasafe_default_value_qsetting(
                self.settings, GLOBAL, default_field['key'])

            # To avoid python error
            if qsetting_default_value > parameter.maximum_allowed_value:
                qsetting_default_value = parameter.maximum_allowed_value
            if qsetting_default_value < parameter.minimum_allowed_value:
                qsetting_default_value = parameter.minimum_allowed_value

            parameter.value = qsetting_default_value
        return parameter
Пример #12
0
    def set_up_resource_parameters(self):
        """Set up the resource parameter for the add/edit view.
        """
        name_parameter = StringParameter('UUID-1')
        name_parameter.name = 'Resource name'
        name_parameter.help_text = (
            'Name of the resource that will be provided '
            'as part of minimum needs. '
            'e.g. Rice, Water etc.')
        name_parameter.description = (
            'A <b>resource</b> is something that you provide to displaced '
            'persons in the event of a disaster. The resource will be made '
            'available at IDP camps and may need to be stockpiled by '
            'contingency planners in their preparations for a disaster.')
        name_parameter.is_required = True
        name_parameter.value = ''

        description_parameter = StringParameter('UUID-2')
        description_parameter.name = 'Resource description'
        description_parameter.help_text = (
            'Description of the resource that will be provided as part of '
            'minimum needs.')
        description_parameter.description = (
            'This gives a detailed description of what the resource is and ')
        description_parameter.is_required = True
        description_parameter.value = ''

        unit_parameter = StringParameter('UUID-3')
        unit_parameter.name = 'Unit'
        unit_parameter.help_text = (
            'Single unit for the resources spelled out. e.g. litre, '
            'kilogram etc.')
        unit_parameter.description = (
            'A <b>unit</b> is the basic measurement unit used for computing '
            'the allowance per individual. For example when planning water '
            'rations the unit would be single litre.')
        unit_parameter.is_required = True
        unit_parameter.value = ''

        units_parameter = StringParameter('UUID-4')
        units_parameter.name = 'Units'
        units_parameter.help_text = (
            'Multiple units for the resources spelled out. e.g. litres, '
            'kilogram etc.')
        units_parameter.description = (
            '<b>Units</b> are the basic measurement used for computing the '
            'allowance per individual. For example when planning water '
            'rations the units would be litres.')
        units_parameter.is_required = True
        units_parameter.value = ''

        unit_abbreviation_parameter = StringParameter('UUID-5')
        unit_abbreviation_parameter.name = 'Unit abbreviation'
        unit_abbreviation_parameter.help_text = (
            'Abbreviations of unit for the resources. e.g. l, kg etc.')
        unit_abbreviation_parameter.description = (
            "A <b>unti abbreviation</b> is the basic measurement unit's "
            "shortened. For example when planning water rations "
            "the units would be l.")
        unit_abbreviation_parameter.is_required = True
        unit_abbreviation_parameter.value = ''

        minimum_parameter = FloatParameter('UUID-6')
        minimum_parameter.name = 'Minimum allowed'
        minimum_parameter.is_required = True
        minimum_parameter.precision = 2
        minimum_parameter.minimum_allowed_value = -99999.0
        minimum_parameter.maximum_allowed_value = 99999.0
        minimum_parameter.help_text = (
            'The minimum allowable quantity per person. ')
        minimum_parameter.description = (
            'The <b>minimum</b> is the minimum allowed quantity of the '
            'resource per person. For example you may dictate that the water '
            'ration per person per day should never be allowed to be less '
            'than 0.5l. This is enforced when tweaking a minimum needs set '
            'before an impact evaluation')
        minimum_parameter.value = 0.00

        maximum_parameter = FloatParameter('UUID-7')
        maximum_parameter.name = 'Maximum allowed'
        maximum_parameter.is_required = True
        maximum_parameter.precision = 2
        maximum_parameter.minimum_allowed_value = -99999.0
        maximum_parameter.maximum_allowed_value = 99999.0
        maximum_parameter.help_text = (
            'The maximum allowable quantity per person. ')
        maximum_parameter.description = (
            'The <b>maximum</b> is the maximum allowed quantity of the '
            'resource per person. For example you may dictate that the water '
            'ration per person per day should never be allowed to be more '
            'than 50l. This is enforced when tweaking a minimum needs set '
            'before an impact evaluation.')
        maximum_parameter.value = 100.0

        default_parameter = FloatParameter('UUID-8')
        default_parameter.name = 'Default'
        default_parameter.is_required = True
        default_parameter.precision = 2
        default_parameter.minimum_allowed_value = -99999.0
        default_parameter.maximum_allowed_value = 99999.0
        default_parameter.help_text = (
            'The default allowable quantity per person. ')
        default_parameter.description = (
            "The <b>default</b> is the default allowed quantity of the "
            "resource per person. For example you may indicate that the water "
            "ration per person weekly should be 67l.")
        default_parameter.value = 10.0

        frequency_parameter = StringParameter('UUID-9')
        frequency_parameter.name = 'Frequency'
        frequency_parameter.help_text = (
            "The frequency that this resource needs to be provided to a "
            "displaced person. e.g. weekly, daily, once etc.")
        frequency_parameter.description = (
            "The <b>frequency</b> informs the aid worker how regularly this "
            "resource needs to be provided to the displaced person.")
        frequency_parameter.is_required = True
        frequency_parameter.value = 'weekly'

        sentence_parameter = StringParameter('UUID-10')
        sentence_parameter.name = 'Readable sentence'
        sentence_parameter.help_text = (
            'A readable presentation of the resource.')
        sentence_parameter.description = (
            "A <b>readable sentence</b> is a presentation of the resource "
            "that displays all pertinent information. If you are unsure then "
            "use the default. Properties should be included using double "
            "curly brackets '{{' '}}'. Including the resource name would be "
            "achieved by including e.g. {{ Resource name }}")
        sentence_parameter.is_required = True
        sentence_parameter.value = (
            "A displaced person should be provided with "
            "{{ Default }} {{ Unit }}/{{ Units }}/{{ Unit abbreviation }} of "
            "{{ Resource name }}. Though no less than {{ Minimum allowed }} "
            "and no more than {{ Maximum allowed }}. This should be provided "
            "{{ Frequency }}.")

        parameters = [
            name_parameter,
            description_parameter,
            unit_parameter,
            units_parameter,
            unit_abbreviation_parameter,
            default_parameter,
            minimum_parameter,
            maximum_parameter,
            frequency_parameter,
            sentence_parameter
        ]
        parameter_container = ParameterContainer(parameters)

        layout = QGridLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        layout.setSpacing(0)
        layout.addWidget(parameter_container)
        self.resource_widget.setLayout(layout)
Пример #13
0
def evacuation_percentage():
    """Generator for the default evaluation percentage parameter.
    :return: List of Float parameter
    :rtype: list[FloatParameter]
    """
    field = FloatParameter()
    field.name = 'Evacuation Percentage'
    field.is_required = True
    field.maximum_allowed_value = 100
    field.minimum_allowed_value = 0
    field.value = 1
    field.precision = 2
    unit_percentage = parameter_unit_percentage()
    field.unit = unit_percentage
    field.allowed_units = [unit_percentage]
    field.help_text = tr('Percentage value of affected population.')
    field.description = tr(
        'The value in percentage of the population that '
        'represent the number of people needed to be evacuated.')
    return field
Пример #14
0
    def default_field_to_parameter(self, default_field):
        """Obtain parameter from default field.

        :param default_field: A default field definition.
        :type default_field: dict

        :returns: A parameter object.
        :rtype: FloatParameter, IntegerParameter
        """
        if default_field.get('type') == QVariant.Double:
            parameter = FloatParameter()
        elif default_field.get('type') in qvariant_whole_numbers:
            parameter = IntegerParameter()
        else:
            return
        default_value = default_field.get('default_value')
        if not default_value:
            message = ('InaSAFE default field %s does not have default value' %
                       default_field.get('name'))
            LOGGER.exception(message)
            return

        parameter.guid = default_field.get('key')
        parameter.name = default_value.get('name')
        parameter.is_required = True
        parameter.precision = default_field.get('precision')
        parameter.minimum_allowed_value = default_value.get('min_value', 0)
        parameter.maximum_allowed_value = default_value.get(
            'max_value', 100000000)
        parameter.help_text = default_value.get('help_text')
        parameter.description = default_value.get('description')

        # Check if user ask to restore to the most default value.
        if self.is_restore_default:
            parameter._value = default_value.get('default_value')
        else:
            # Current value
            qsetting_default_value = get_inasafe_default_value_qsetting(
                self.settings, GLOBAL, default_field['key'])

            # To avoid python error
            if qsetting_default_value > parameter.maximum_allowed_value:
                qsetting_default_value = parameter.maximum_allowed_value
            if qsetting_default_value < parameter.minimum_allowed_value:
                qsetting_default_value = parameter.minimum_allowed_value

            parameter.value = qsetting_default_value
        return parameter
Пример #15
0
def high_threshold():
    """Generate high  hazard zone threshold parameter

    :returns: A FloatParameter.
    :rtype: FloatParameter
    """
    field = FloatParameter()
    field.is_required = True
    field.name = tr('High Hazard Zone Threshold')
    field.precision = 2
    field.value = 10
    field.minimum_allowed_value = 0
    field.maximum_allowed_value = 100
    unit_centimetres = parameter_unit_centimetres()
    field.unit = unit_centimetres
    field.allowed_units = [unit_centimetres]
    field.help_text = tr('High Hazard Zone threshold.')
    field.description = tr(
        'The threshold of hazard categorized as High Hazard Zone in '
        'centimetres. A zone is categorized as High Hazard Zone if the '
        'thickness of ash is more than Moderate Hazard Zone Threshold and '
        'less than High Hazard Zone Threshold. If it is more than High Hazard '
        'Threshold then it was considered as Very High Hazard Zone')
    return field
Пример #16
0
def unaffected_threshold():
    """Generate threshold for unaffected region

    :returns: A FloatParameter.
    :rtype: FloatParameter
    """
    field = FloatParameter()
    field.is_required = True
    field.name = tr('Unaffected Threshold')
    field.precision = 2
    field.value = 1
    field.minimum_allowed_value = 0
    field.maximum_allowed_value = 100
    field.value = 0.01
    unit_centimetres = parameter_unit_centimetres()
    field.unit = unit_centimetres
    field.allowed_units = [unit_centimetres]
    field.help_text = tr('Unaffected threshold.')
    field.description = tr(
        'The threshold of hazard categorized as Unaffected in '
        'centimetres. A zone is categorized as Unaffected if the '
        'thickness of ash is less than Unaffected Threshold.')
    return field
Пример #17
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]
Пример #18
0
    def set_up_resource_parameters(self):
        """Set up the resource parameter for the add/edit view.
        """
        name_parameter = StringParameter('UUID-1')
        name_parameter.name = tr('Resource name')
        name_parameter.help_text = tr(
            'Name of the resource that will be provided '
            'as part of minimum needs. '
            'e.g. Rice, Water etc.')
        name_parameter.description = tr(
            'A <b>resource</b> is something that you provide to displaced '
            'persons in the event of a disaster. The resource will be made '
            'available at IDP camps and may need to be stockpiled by '
            'contingency planners in their preparations for a disaster.')
        name_parameter.is_required = True
        name_parameter.value = ''

        description_parameter = StringParameter('UUID-2')
        description_parameter.name = tr('Resource description')
        description_parameter.help_text = tr(
            'Description of the resource that will be provided as part of '
            'minimum needs.')
        description_parameter.description = tr(
            'This gives a detailed description of what the resource is and ')
        description_parameter.is_required = True
        description_parameter.value = ''

        unit_parameter = StringParameter('UUID-3')
        unit_parameter.name = tr('Unit')
        unit_parameter.help_text = tr(
            'Single unit for the resources spelled out. e.g. litre, '
            'kilogram etc.')
        unit_parameter.description = tr(
            'A <b>unit</b> is the basic measurement unit used for computing '
            'the allowance per individual. For example when planning water '
            'rations the unit would be single litre.')
        unit_parameter.is_required = True
        unit_parameter.value = ''

        units_parameter = StringParameter('UUID-4')
        units_parameter.name = tr('Units')
        units_parameter.help_text = tr(
            'Multiple units for the resources spelled out. e.g. litres, '
            'kilogram etc.')
        units_parameter.description = tr(
            '<b>Units</b> are the basic measurement used for computing the '
            'allowance per individual. For example when planning water '
            'rations the units would be litres.')
        units_parameter.is_required = True
        units_parameter.value = ''

        unit_abbreviation_parameter = StringParameter('UUID-5')
        unit_abbreviation_parameter.name = tr('Unit abbreviation')
        unit_abbreviation_parameter.help_text = tr(
            'Abbreviations of unit for the resources. e.g. l, kg etc.')
        unit_abbreviation_parameter.description = tr(
            "A <b>unti abbreviation</b> is the basic measurement unit's "
            "shortened. For example when planning water rations "
            "the units would be l.")
        unit_abbreviation_parameter.is_required = True
        unit_abbreviation_parameter.value = ''

        minimum_parameter = FloatParameter('UUID-6')
        minimum_parameter.name = tr('Minimum allowed')
        minimum_parameter.is_required = True
        minimum_parameter.precision = 2
        minimum_parameter.minimum_allowed_value = -99999.0
        minimum_parameter.maximum_allowed_value = 99999.0
        minimum_parameter.help_text = tr(
            'The minimum allowable quantity per person. ')
        minimum_parameter.description = tr(
            'The <b>minimum</b> is the minimum allowed quantity of the '
            'resource per person. For example you may dictate that the water '
            'ration per person per day should never be allowed to be less '
            'than 0.5l. This is enforced when tweaking a minimum needs set '
            'before an impact evaluation')
        minimum_parameter.value = 0.00

        maximum_parameter = FloatParameter('UUID-7')
        maximum_parameter.name = tr('Maximum allowed')
        maximum_parameter.is_required = True
        maximum_parameter.precision = 2
        maximum_parameter.minimum_allowed_value = -99999.0
        maximum_parameter.maximum_allowed_value = 99999.0
        maximum_parameter.help_text = tr(
            'The maximum allowable quantity per person. ')
        maximum_parameter.description = tr(
            'The <b>maximum</b> is the maximum allowed quantity of the '
            'resource per person. For example you may dictate that the water '
            'ration per person per day should never be allowed to be more '
            'than 50l. This is enforced when tweaking a minimum needs set '
            'before an impact evaluation.')
        maximum_parameter.value = 100.0

        default_parameter = FloatParameter('UUID-8')
        default_parameter.name = tr('Default')
        default_parameter.is_required = True
        default_parameter.precision = 2
        default_parameter.minimum_allowed_value = -99999.0
        default_parameter.maximum_allowed_value = 99999.0
        default_parameter.help_text = tr(
            'The default allowable quantity per person. ')
        default_parameter.description = tr(
            "The <b>default</b> is the default allowed quantity of the "
            "resource per person. For example you may indicate that the water "
            "ration per person weekly should be 67l.")
        default_parameter.value = 10.0

        frequency_parameter = StringParameter('UUID-9')
        frequency_parameter.name = tr('Frequency')
        frequency_parameter.help_text = tr(
            "The frequency that this resource needs to be provided to a "
            "displaced person. e.g. weekly, daily, once etc.")
        frequency_parameter.description = tr(
            "The <b>frequency</b> informs the aid worker how regularly this "
            "resource needs to be provided to the displaced person.")
        frequency_parameter.is_required = True
        frequency_parameter.value = tr('weekly')

        sentence_parameter = TextParameter('UUID-10')
        sentence_parameter.name = tr('Readable sentence')
        sentence_parameter.help_text = tr(
            'A readable presentation of the resource.')
        sentence_parameter.description = tr(
            "A <b>readable sentence</b> is a presentation of the resource "
            "that displays all pertinent information. If you are unsure then "
            "use the default. Properties should be included using double "
            "curly brackets '{{' '}}'. Including the resource name would be "
            "achieved by including e.g. {{ Resource name }}")
        sentence_parameter.is_required = True
        sentence_parameter.value = tr(
            "A displaced person should be provided with "
            "{{ Default }} {{ Unit }}/{{ Units }}/{{ Unit abbreviation }} of "
            "{{ Resource name }}. Though no less than {{ Minimum allowed }} "
            "and no more than {{ Maximum allowed }}. This should be provided "
            "{{ Frequency }}.")

        parameters = [
            name_parameter,
            description_parameter,
            unit_parameter,
            units_parameter,
            unit_abbreviation_parameter,
            default_parameter,
            minimum_parameter,
            maximum_parameter,
            frequency_parameter,
            sentence_parameter
        ]
        parameter_container = ParameterContainer(parameters)
        parameter_container.setup_ui()

        layout = QGridLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        layout.setSpacing(0)
        layout.addWidget(parameter_container)
        self.parameters_scrollarea.setLayout(layout)
Пример #19
0
def low_threshold():
    """Generate low hazard zone threshold parameter

    :returns: A FloatParameter.
    :rtype: FloatParameter
    """
    field = FloatParameter()
    field.is_required = True
    field.name = tr('Low Hazard Zone Threshold')
    field.precision = 2
    field.value = 2
    field.minimum_allowed_value = 0
    field.maximum_allowed_value = 100
    unit_centimetres = parameter_unit_centimetres()
    field.unit = unit_centimetres
    field.allowed_units = [unit_centimetres]
    field.help_text = tr('Low Hazard Zone threshold.')
    field.description = tr(
        'The threshold of hazard categorized as Low Hazard Zone in '
        'centimetres. A zone is categorized as Low Hazard Zone if the '
        'thickness of ash is more than Very Low Hazard Zone Threshold and '
        'less than Low Hazard Zone Threshold.')
    return field
Пример #20
0
def high_threshold():
    """Generate high  hazard zone threshold parameter

    :return: list of FloatParameter
    :rtype: list[FloatParameter]
    """
    field = FloatParameter()
    field.is_required = True
    field.name = 'High Hazard Zone Threshold'
    field.precision = 2
    field.value = 8
    field.minimum_allowed_value = 0
    field.maximum_allowed_value = 100
    unit_metres = parameter_unit_metres()
    field.unit = unit_metres
    field.allowed_units = [unit_metres]
    field.help_text = tr('High Hazard Zone threshold.')
    field.description = tr(
        'The threshold of hazard categorized as High Hazard Zone in '
        'meter. A zone is categorized as High Hazard Zone if the depth of '
        'tsunami inundation is more than Medium Hazard Zone Threshold and '
        'less than High Hazard Zone Threshold.'
        'A zone that has more than High Hazard Zone Threshold is categorized '
        'as Very High Hazard Zone.')
    return field
Пример #21
0
def medium_threshold():
    """Generate moderate hazard zone threshold parameter

    :return: list of FloatParameter
    :rtype: list[FloatParameter]
    """
    field = FloatParameter()
    field.is_required = True
    field.name = 'Moderate Hazard Zone Threshold'
    field.precision = 2
    field.value = 3
    field.minimum_allowed_value = 0
    field.maximum_allowed_value = 100
    unit_metres = parameter_unit_metres()
    field.unit = unit_metres
    field.allowed_units = [unit_metres]
    field.help_text = tr('Moderate Hazard Zone threshold.')
    field.description = tr(
        'The threshold of hazard categorized as Moderate Hazard Zone in '
        'meter. A zone is categorized as Medium Hazard Zone if the depth of '
        'tsunami inundation is more than Low Hazard Zone Threshold and less '
        'than Medium Hazard Zone Threshold.')
    return field
Пример #22
0
def low_threshold():
    """Generate low hazard zone threshold parameter

    :return: list of FloatParameter
    :rtype: list[FloatParameter]
    """
    field = FloatParameter()
    field.is_required = True
    field.name = 'Low Hazard Zone Threshold'
    field.precision = 2
    field.value = 1
    field.minimum_allowed_value = 0
    field.maximum_allowed_value = 100
    unit_metres = parameter_unit_metres()
    field.unit = unit_metres
    field.allowed_units = [unit_metres]
    field.help_text = tr('Low Hazard Zone threshold.')
    field.description = tr(
        'The threshold of hazard categorized as Low Hazard Zone in meter. A '
        'zone is categorized as Low Hazard Zone if the depth of tsunami '
        'inundation is less than Low Hazard Zone Threshold.')
    return field
Пример #23
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]
Пример #24
0
def age_postprocessor():
    """Get age postprocessor selectors.

    :return: Selectors to activate age postprocessor.
    :rtype: list
    """
    age = BooleanParameter()
    age.name = 'Age'
    age.value = True

    youth_ratio = FloatParameter()
    youth_ratio.name = 'Youth ratio'
    youth_ratio.value = get_defaults('YOUTH_RATIO')
    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.')

    adult_ratio = FloatParameter()
    adult_ratio.name = 'Adult ratio'
    adult_ratio.value = get_defaults('ADULT_RATIO')
    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.')

    elderly_ratio = FloatParameter()
    elderly_ratio.name = 'Elderly ratio'
    elderly_ratio.value = get_defaults('ELDERLY_RATIO')
    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.')

    return [age, youth_ratio, adult_ratio, elderly_ratio]
Пример #25
0
def age_postprocessor():
    """Get age postprocessor selectors.

    :return: Selectors to activate age postprocessor.
    :rtype: list
    """
    age = BooleanParameter()
    age.name = 'Age'
    age.value = True

    youth_ratio = FloatParameter()
    youth_ratio.name = 'Youth ratio'
    youth_ratio.value = get_defaults('YOUTH_RATIO')
    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.'
    )

    adult_ratio = FloatParameter()
    adult_ratio.name = 'Adult ratio'
    adult_ratio.value = get_defaults('ADULT_RATIO')
    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.'
    )

    elderly_ratio = FloatParameter()
    elderly_ratio.name = 'Elderly ratio'
    elderly_ratio.value = get_defaults('ELDERLY_RATIO')
    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.'
    )

    return [age, youth_ratio, adult_ratio, elderly_ratio]
Пример #26
0
def high_threshold():
    """Generate high  hazard zone threshold parameter

    :returns: A FloatParameter.
    :rtype: FloatParameter
    """
    field = FloatParameter()
    field.is_required = True
    field.name = tr('High Hazard Zone Threshold')
    field.precision = 2
    field.value = 10
    field.minimum_allowed_value = 0
    field.maximum_allowed_value = 100
    unit_centimetres = parameter_unit_centimetres()
    field.unit = unit_centimetres
    field.allowed_units = [unit_centimetres]
    field.help_text = tr('High Hazard Zone threshold.')
    field.description = tr(
        'The threshold of hazard categorized as High Hazard Zone in '
        'centimetres. A zone is categorized as High Hazard Zone if the '
        'thickness of ash is more than Moderate Hazard Zone Threshold and '
        'less than High Hazard Zone Threshold. If it is more than High Hazard '
        'Threshold then it was considered as Very High Hazard Zone')
    return field
    def test_init(self):
        """Test initialize qt4 parameter factory."""

        boolean_parameter = BooleanParameter('1231231')
        boolean_parameter.name = 'Boolean'
        boolean_parameter.help_text = 'A boolean parameter'
        boolean_parameter.description = 'A test _description'
        boolean_parameter.is_required = True
        boolean_parameter.value = True

        float_parameter = FloatParameter()
        float_parameter.name = 'Float Parameter'
        float_parameter.is_required = True
        float_parameter.precision = 3
        float_parameter.minimum_allowed_value = 1.0
        float_parameter.maximum_allowed_value = 2.0
        float_parameter.help_text = 'Short help.'
        float_parameter.description = 'Long description for parameter.'
        float_parameter.unit = 'metres'
        float_parameter.value = 1.1

        parameters = [boolean_parameter, float_parameter]

        qt4_parameter_factory = Qt4ParameterFactory()
        widgets = []
        widget_classes = []

        for parameter in parameters:
            widget = qt4_parameter_factory.get_widget(parameter)
            widgets.append(widget)
            widget_classes.append(widget.__class__)

        expected_classes = [BooleanParameterWidget, FloatParameterWidget]
        message = 'Expected %s got %s' % (expected_classes, widget_classes)
        self.assertListEqual(widget_classes, expected_classes, message)
Пример #28
0
def unaffected_threshold():
    """Generate threshold for unaffected region

    :returns: A FloatParameter.
    :rtype: FloatParameter
    """
    field = FloatParameter()
    field.is_required = True
    field.name = tr('Unaffected Threshold')
    field.precision = 2
    field.value = 1
    field.minimum_allowed_value = 0
    field.maximum_allowed_value = 100
    field.value = 0.01
    unit_centimetres = parameter_unit_centimetres()
    field.unit = unit_centimetres
    field.allowed_units = [unit_centimetres]
    field.help_text = tr('Unaffected threshold.')
    field.description = tr(
        'The threshold of hazard categorized as Unaffected in '
        'centimetres. A zone is categorized as Unaffected if the '
        'thickness of ash is less than Unaffected Threshold.')
    return field
Пример #29
0
def low_threshold():
    """Generate low hazard zone threshold parameter

    :returns: A FloatParameter.
    :rtype: FloatParameter
    """
    field = FloatParameter()
    field.is_required = True
    field.name = tr('Low Hazard Zone Threshold')
    field.precision = 2
    field.value = 2
    field.minimum_allowed_value = 0
    field.maximum_allowed_value = 100
    unit_centimetres = parameter_unit_centimetres()
    field.unit = unit_centimetres
    field.allowed_units = [unit_centimetres]
    field.help_text = tr('Low Hazard Zone threshold.')
    field.description = tr(
        'The threshold of hazard categorized as Low Hazard Zone in '
        'centimetres. A zone is categorized as Low Hazard Zone if the '
        'thickness of ash is more than Very Low Hazard Zone Threshold and '
        'less than Low Hazard Zone Threshold.')
    return field
Пример #30
0
    def restore_default_values_page(self):
        """Setup UI for default values setting."""
        # Clear parameters so it doesn't add parameters when
        # restore from changes.
        if self.default_value_parameters:
            self.default_value_parameters = []

        unordered_parameters = []

        default_fields = all_default_fields()
        for default_field in default_fields:
            if default_field.get('type') == QVariant.Double:
                parameter = FloatParameter()
            elif default_field.get('type') in qvariant_whole_numbers:
                parameter = IntegerParameter()
            else:
                continue
            default_value = default_field.get('default_value')
            if not default_value:
                message = (
                    'InaSAFE default field %s does not have default value'
                    % default_field.get('name'))
                LOGGER.exception(message)
                continue

            parameter.guid = default_field.get('key')
            parameter.name = default_value.get('name')
            parameter.is_required = True
            parameter.precision = default_field.get('precision')
            parameter.minimum_allowed_value = default_value.get(
                'min_value', 0)
            parameter.maximum_allowed_value = default_value.get(
                'max_value', 100000000)
            parameter.help_text = default_value.get('help_text')
            parameter.description = default_value.get('description')

            # Check if user ask to restore to the most default value.
            if self.is_restore_default:
                parameter._value = default_value.get('default_value')
            else:
                # Current value
                qsetting_default_value = get_inasafe_default_value_qsetting(
                    self.settings, GLOBAL, default_field['key'])

                # To avoid python error
                if qsetting_default_value > parameter.maximum_allowed_value:
                    qsetting_default_value = parameter.maximum_allowed_value
                if qsetting_default_value < parameter.minimum_allowed_value:
                    qsetting_default_value = parameter.minimum_allowed_value

                parameter.value = qsetting_default_value

            unordered_parameters.append(parameter)

        preferred_order = [
            youth_ratio_field,
            adult_ratio_field,
            elderly_ratio_field
        ]

        for order in preferred_order:
            parameter_index = [
                p.guid for p in unordered_parameters].index(order['key'])
            if parameter_index > -1:
                self.default_value_parameters.append(
                    unordered_parameters[parameter_index])
                unordered_parameters.pop(parameter_index)

        self.default_value_parameters.extend(unordered_parameters)

        description_text = tr(
            'In this options you can change the global default values for '
            'these variables.')
        self.default_value_parameter_container = ParameterContainer(
            self.default_value_parameters, description_text=description_text)
        self.default_value_parameter_container.setup_ui()
        self.default_values_layout.addWidget(
            self.default_value_parameter_container)