From f2197d4b2ae3e35b4ac12ec1fea31fd1082f4fa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Ignacio=20S=C3=A1nchez=20Lara?= Date: Mon, 16 Jul 2018 11:34:33 +0200 Subject: [PATCH] match_types for Google metadata --- .../cartodb_services/google/geocoder.py | 17 ++++++++++++++++- test/integration/test_street_functions.py | 6 ++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/server/lib/python/cartodb_services/cartodb_services/google/geocoder.py b/server/lib/python/cartodb_services/cartodb_services/google/geocoder.py index f4cd0a5..74d8f53 100644 --- a/server/lib/python/cartodb_services/cartodb_services/google/geocoder.py +++ b/server/lib/python/cartodb_services/cartodb_services/google/geocoder.py @@ -23,6 +23,18 @@ PRECISION_BY_LOCATION_TYPE = { 'RANGE_INTERPOLATED': PRECISION_INTERPOLATED, 'APPROXIMATE': PRECISION_INTERPOLATED } +MATCH_TYPE_BY_MATCH_LEVEL = { + 'point_of_interest': 'point_of_interest', + 'country': 'country', + 'administrative_area_level_1': 'state', + 'administrative_area_level_2': 'county', + 'locality': 'locality', + 'sublocality': 'district', + 'street_address': 'street', + 'intersection': 'intersection', + 'street_number': 'street_number', + 'postal_code': 'postal_code' +} class GoogleMapsGeocoder(): @@ -70,9 +82,12 @@ class GoogleMapsGeocoder(): base_relevance = RELEVANCE_BY_LOCATION_TYPE[location_type] partial_match = result.get('partial_match', False) partial_factor = PARTIAL_FACTOR if partial_match else 1 + match_types = [MATCH_TYPE_BY_MATCH_LEVEL.get(match_level, None) + for match_level in result['types']] return { 'relevance': base_relevance * partial_factor, - 'precision': PRECISION_BY_LOCATION_TYPE[location_type] + 'precision': PRECISION_BY_LOCATION_TYPE[location_type], + 'match_types': filter(None, match_types) } diff --git a/test/integration/test_street_functions.py b/test/integration/test_street_functions.py index c8abeae..7575b7c 100644 --- a/test/integration/test_street_functions.py +++ b/test/integration/test_street_functions.py @@ -71,9 +71,9 @@ class TestStreetFunctionsSetUp(TestCase): GOOGLE_METADATAS = { 'Plaza España, Barcelona': - {'relevance': 0.9, 'precision': 'precise'}, + {'relevance': 0.9, 'precision': 'precise', 'match_types': ['point_of_interest']}, 'Santiago Rusiñol 123, Valladolid': - {'relevance': 0.56, 'precision': 'interpolated'} + {'relevance': 0.56, 'precision': 'interpolated', 'match_types': ['locality']} } HERE_METADATAS = { @@ -408,3 +408,5 @@ class TestBulkStreetFunctions(TestStreetFunctionsSetUp): '{} not close to {}'.format(relevance, expected_relevance)) assert_equal(metadata['precision'], expected['precision']) + + assert_equal(metadata['match_types'], expected['match_types'])