Precision metadata for Mapbox

This commit is contained in:
Juan Ignacio Sánchez Lara 2018-07-11 19:28:16 +02:00
parent 4123a4c442
commit 6e78da55b2
2 changed files with 12 additions and 4 deletions

View File

@ -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):

View File

@ -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 = {