Пример #1
0
    def test_classification_value_maps(self):
        """Test for classification_value_maps method."""
        value_maps = default_classification_value_maps(flood_hazard_classes)
        wet_class = flood_hazard_classes['classes'][0]
        dry_class = flood_hazard_classes['classes'][1]
        expected = {
            'dry': dry_class['string_defaults'],
            'wet': wet_class['string_defaults']
        }
        self.assertDictEqual(value_maps, expected)

        value_maps = default_classification_value_maps(
            cyclone_au_bom_hazard_classes)
        category_5_class = cyclone_au_bom_hazard_classes['classes'][0]
        category_4_class = cyclone_au_bom_hazard_classes['classes'][1]
        category_3_class = cyclone_au_bom_hazard_classes['classes'][2]
        category_2_class = cyclone_au_bom_hazard_classes['classes'][3]
        category_1_class = cyclone_au_bom_hazard_classes['classes'][4]
        tropical_depression_class = cyclone_au_bom_hazard_classes['classes'][5]
        expected = {
            'category_1':
            category_1_class.get('string_defaults', []),
            'category_2':
            category_2_class.get('string_defaults', []),
            'category_3':
            category_3_class.get('string_defaults', []),
            'category_4':
            category_4_class.get('string_defaults', []),
            'category_5':
            category_5_class.get('string_defaults', []),
            'tropical_depression':
            tropical_depression_class.get('string_defaults', [])
        }
        self.assertDictEqual(value_maps, expected)
Пример #2
0
    def test_classification_value_maps(self):
        """Test for classification_value_maps method."""
        value_maps = default_classification_value_maps(flood_hazard_classes)
        wet_class = flood_hazard_classes['classes'][0]
        dry_class = flood_hazard_classes['classes'][1]
        expected = {
            'dry': dry_class['string_defaults'],
            'wet': wet_class['string_defaults']
        }
        self.assertDictEqual(value_maps, expected)

        value_maps = default_classification_value_maps(
            cyclone_au_bom_hazard_classes)
        category_5_class = cyclone_au_bom_hazard_classes['classes'][0]
        category_4_class = cyclone_au_bom_hazard_classes['classes'][1]
        category_3_class = cyclone_au_bom_hazard_classes['classes'][2]
        category_2_class = cyclone_au_bom_hazard_classes['classes'][3]
        category_1_class = cyclone_au_bom_hazard_classes['classes'][4]
        tropical_depression_class = cyclone_au_bom_hazard_classes['classes'][5]
        expected = {
            'category_1': category_1_class.get('string_defaults', []),
            'category_2': category_2_class.get('string_defaults', []),
            'category_3': category_3_class.get('string_defaults', []),
            'category_4': category_4_class.get('string_defaults', []),
            'category_5': category_5_class.get('string_defaults', []),
            'tropical_depression': tropical_depression_class.get(
                'string_defaults', [])
        }
        self.assertDictEqual(value_maps, expected)
Пример #3
0
    def activate_classification(self, exposure, classification=None):
        """Set active to True for classification for the exposure.

        If classification = None, all classification set active = False.

        :param exposure: Exposure definition.
        :type exposure: dict

        :param classification: Classification definition.
        :type classification: dict
        """
        if self.layer_mode == layer_mode_continuous:
            selected_unit = self.parent.step_kw_unit.selected_unit()['key']
            target = self.thresholds.get(exposure['key'])
            if target is None:
                self.thresholds[exposure['key']] = {}
            target = self.thresholds.get(exposure['key'])
        else:
            selected_unit = None
            target = self.value_maps.get(exposure['key'])
            if target is None:
                self.value_maps[exposure['key']] = {}
            target = self.value_maps.get(exposure['key'])

        if classification is not None:
            if classification['key'] not in target:
                if self.layer_mode == layer_mode_continuous:
                    default_classes = default_classification_thresholds(
                        classification, selected_unit)
                    target[classification['key']] = {
                        'classes': default_classes,
                        'active': True
                    }
                else:
                    default_classes = default_classification_value_maps(
                        classification)
                    target[classification['key']] = {
                        'classes': default_classes,
                        'active': True
                    }
                return

        for classification_key, value in target.items():
            if classification is None:
                value['active'] = False
                continue

            if classification_key == classification['key']:
                value['active'] = True
            else:
                value['active'] = False
    def activate_classification(self, exposure, classification=None):
        """Set active to True for classification for the exposure.

        If classification = None, all classification set active = False.

        :param exposure: Exposure definition.
        :type exposure: dict

        :param classification: Classification definition.
        :type classification: dict
        """
        if self.layer_mode == layer_mode_continuous:
            selected_unit = self.parent.step_kw_unit.selected_unit()['key']
            target = self.thresholds.get(exposure['key'])
            if target is None:
                self.thresholds[exposure['key']] = {}
            target = self.thresholds.get(exposure['key'])
        else:
            selected_unit = None
            target = self.value_maps.get(exposure['key'])
            if target is None:
                self.value_maps[exposure['key']] = {}
            target = self.value_maps.get(exposure['key'])

        if classification is not None:
            if classification['key'] not in target:
                if self.layer_mode == layer_mode_continuous:
                    default_classes = default_classification_thresholds(
                        classification, selected_unit)
                    target[classification['key']] = {
                        'classes': default_classes,
                        'active': True
                    }
                else:
                    default_classes = default_classification_value_maps(
                        classification)
                    target[classification['key']] = {
                        'classes': default_classes,
                        'active': True
                    }
                return

        for classification_key, value in target.items():
            if classification is None:
                value['active'] = False
                continue

            if classification_key == classification['key']:
                value['active'] = True
            else:
                value['active'] = False