def test_analysis_summary(self): """Test we can aggregate the aggregate hazard to the analysis.""" aggregate_hazard = load_test_vector_layer( 'gisv4', 'intermediate', 'aggregate_classified_hazard_summary.geojson') aggregate_hazard.keywords['hazard_keywords'] = { 'classification': 'generic_hazard_classes' } analysis = load_test_vector_layer('gisv4', 'intermediate', 'analysis.geojson', clone=True) number_of_fields = analysis.fields().count() layer = analysis_summary(aggregate_hazard, analysis) check_inasafe_fields(layer) fields = aggregate_hazard.keywords['inasafe_fields'] hazard_class = fields[hazard_class_field['key']] hazard_class_index = aggregate_hazard.fieldNameIndex(hazard_class) unique_hazard = aggregate_hazard.uniqueValues(hazard_class_index) # expected number of fields: # - one field for each hazard class # - 2 fields for analysis id and analysis name # - 4 fields for total affected, not_affected, not exposed and total self.assertEqual(layer.fields().count(), len(unique_hazard) + number_of_fields + 4)
def test_analysis_summary(self): """Test we can aggregate the aggregate hazard to the analysis.""" aggregate_hazard = load_test_vector_layer( 'gisv4', 'intermediate', 'aggregate_classified_hazard_summary.geojson') aggregate_hazard.keywords['hazard_keywords'] = { 'classification': 'generic_hazard_classes' } analysis = load_test_vector_layer( 'gisv4', 'intermediate', 'analysis.geojson', clone=True) number_of_fields = analysis.fields().count() layer = analysis_summary(aggregate_hazard, analysis) check_inasafe_fields(layer) fields = aggregate_hazard.keywords['inasafe_fields'] hazard_class = fields[hazard_class_field['key']] hazard_class_index = aggregate_hazard.fieldNameIndex(hazard_class) unique_hazard = aggregate_hazard.uniqueValues(hazard_class_index) # expected number of fields: # - one field for each hazard class # - 2 fields for analysis id and analysis name # - 4 fields for total affected, not_affected, not exposed and total self.assertEqual( layer.fields().count(), len(unique_hazard) + number_of_fields + 4 )