diff --git a/server/lib/python/cartodb_services/cartodb_services/mapbox/geocoder.py b/server/lib/python/cartodb_services/cartodb_services/mapbox/geocoder.py index 5d644d9..9eb5e4e 100644 --- a/server/lib/python/cartodb_services/cartodb_services/mapbox/geocoder.py +++ b/server/lib/python/cartodb_services/cartodb_services/mapbox/geocoder.py @@ -5,6 +5,7 @@ Python client for the Mapbox Geocoder service. import json import requests from mapbox import Geocoder +from cartodb_services import PRECISION_PRECISE, PRECISION_INTERPOLATED from cartodb_services.metrics import Traceable from cartodb_services.tools.exceptions import ServiceException from cartodb_services.tools.qps import qps_retry @@ -74,8 +75,14 @@ class MapboxGeocoder(Traceable): return [longitude, latitude] def _extract_metadata_from_result(self, result): + if result[ENTRY_GEOMETRY].get('interpolated', False): + precision = PRECISION_INTERPOLATED + else: + precision = PRECISION_PRECISE + return { - 'relevance': self._normalize_relevance(float(result['relevance'])) + 'relevance': self._normalize_relevance(float(result['relevance'])), + 'precision': precision } def _normalize_relevance(self, relevance): diff --git a/test/integration/test_street_functions.py b/test/integration/test_street_functions.py index 970e1f7..c8abeae 100644 --- a/test/integration/test_street_functions.py +++ b/test/integration/test_street_functions.py @@ -91,9 +91,10 @@ class TestStreetFunctionsSetUp(TestCase): } MAPBOX_METADATAS = { - 'Plaza España, Barcelona': { - 'relevance': 0.75 - } + 'Plaza España, Barcelona': + {'relevance': 0.666, 'precision': 'precise'}, + 'Santiago Rusiñol 123, Valladolid': + {'relevance': 0.666, 'precision': 'precise'} # TODO: wrong } METADATAS = {