Precision metadata for TomTom

This commit is contained in:
Juan Ignacio Sánchez Lara 2018-07-11 19:09:02 +02:00
parent dbb4f9204a
commit 4123a4c442
2 changed files with 15 additions and 6 deletions

View File

@ -5,6 +5,7 @@ import json
import requests
from uritemplate import URITemplate
from math import tanh
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
@ -22,6 +23,7 @@ ENTRY_LAT = 'lat'
EMPTY_RESPONSE = [[], {}]
SCORE_NORMALIZATION_FACTOR = 0.15
PRECISION_SCORE_THRESHOLD = 0.5
class TomTomGeocoder(Traceable):
'''
@ -133,9 +135,15 @@ class TomTomGeocoder(Traceable):
return EMPTY_RESPONSE
def _extract_metadata_from_result(self, result):
score = self._normalize_score(result['score'])
return {
'relevance': self._normalize_score(result['score'])
'relevance': score,
'precision': self._precision_from_score(score)
}
def _normalize_score(self, score):
return tanh(score * SCORE_NORMALIZATION_FACTOR)
def _precision_from_score(self, score):
return PRECISION_PRECISE \
if score > PRECISION_SCORE_THRESHOLD else PRECISION_INTERPOLATED

View File

@ -73,7 +73,7 @@ class TestStreetFunctionsSetUp(TestCase):
'Plaza España, Barcelona':
{'relevance': 0.9, 'precision': 'precise'},
'Santiago Rusiñol 123, Valladolid':
{'relevance': 0.8, 'precision': 'interpolated'}
{'relevance': 0.56, 'precision': 'interpolated'}
}
HERE_METADATAS = {
@ -84,9 +84,10 @@ class TestStreetFunctionsSetUp(TestCase):
}
TOMTOM_METADATAS = {
'Plaza España, Barcelona': {
'relevance': 0.85
}
'Plaza España, Barcelona':
{'relevance': 0.85, 'precision': 'precise'},
'Santiago Rusiñol 123, Valladolid':
{'relevance': 0.448283494533, 'precision': 'interpolated'}
}
MAPBOX_METADATAS = {
@ -369,7 +370,7 @@ class TestBulkStreetFunctions(TestStreetFunctionsSetUp):
"UNION " \
"select 2 as cartodb_id, ''Spain'' as country, " \
"''Valladolid'' as city, " \
"''Calle Santiago Rusiñol 123'' as street' " \
"''Santiago Rusiñol 123'' as street' " \
", 'street', 'city', NULL, 'country')"
response = self._run_authenticated(query)