From 6e78da55b27d2f814e23a6645cb6b956998f5949 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Ignacio=20S=C3=A1nchez=20Lara?= Date: Wed, 11 Jul 2018 19:28:16 +0200 Subject: [PATCH] Precision metadata for Mapbox --- .../cartodb_services/cartodb_services/mapbox/geocoder.py | 9 ++++++++- test/integration/test_street_functions.py | 7 ++++--- 2 files changed, 12 insertions(+), 4 deletions(-) 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 = {