match_types for batched HERE metadata

This commit is contained in:
Juan Ignacio Sánchez Lara 2018-07-16 12:43:40 +02:00
parent 080de34163
commit e82346e7f6
3 changed files with 30 additions and 21 deletions

View File

@ -140,10 +140,15 @@ class HereMapsBulkGeocoder(HereMapsGeocoder, StreetPointBulkGeocoder):
reader = csv.DictReader(root_zip.open(name), delimiter='|')
for row in reader:
if row['SeqNumber'] == '1': # First per requested data
precision = self.PRECISION_BY_MATCH_TYPE[
row.get('matchType', 'pointAddress')]
match_type = self.MATCH_TYPE_BY_MATCH_LEVEL.get(row['matchLevel'], None)
results.append((row['recId'],
[row['displayLongitude'], row['displayLatitude']],
{
'relevance': float(row['relevance'])
'relevance': float(row['relevance']),
'precision': precision,
'match_types': [match_type] if match_type else []
}))
return results

View File

@ -9,24 +9,6 @@ from exceptions import *
from cartodb_services import PRECISION_PRECISE, PRECISION_INTERPOLATED
from cartodb_services.metrics import Traceable
PRECISION_BY_MATCH_TYPE = {
'pointAddress': PRECISION_PRECISE,
'interpolated': PRECISION_INTERPOLATED
}
MATCH_TYPE_BY_MATCH_LEVEL = {
'landmark': 'point_of_interest',
'country': 'country',
'state': 'state',
'county': 'county',
'city': 'locality',
'district': 'district',
'street': 'street',
'intersection': 'intersection',
'houseNumber': 'street_number',
'postalCode': 'postal_code'
}
class HereMapsGeocoder(Traceable):
'A Here Maps Geocoder wrapper for python'
@ -70,6 +52,23 @@ class HereMapsGeocoder(Traceable):
'strictlanguagemode'
] + ADDRESS_PARAMS
PRECISION_BY_MATCH_TYPE = {
'pointAddress': PRECISION_PRECISE,
'interpolated': PRECISION_INTERPOLATED
}
MATCH_TYPE_BY_MATCH_LEVEL = {
'landmark': 'point_of_interest',
'country': 'country',
'state': 'state',
'county': 'county',
'city': 'locality',
'district': 'district',
'street': 'street',
'intersection': 'intersection',
'houseNumber': 'street_number',
'postalCode': 'postal_code'
}
def __init__(self, app_id, app_code, logger, service_params=None, maxresults=DEFAULT_MAXRESULTS):
service_params = service_params or {}
self.app_id = app_id
@ -145,9 +144,9 @@ class HereMapsGeocoder(Traceable):
def _extract_metadata_from_result(self, result):
# See https://stackoverflow.com/questions/51285622/missing-matchtype-at-here-geocoding-responses
precision = PRECISION_BY_MATCH_TYPE[
precision = self.PRECISION_BY_MATCH_TYPE[
result.get('MatchType', 'pointAddress')]
match_type = MATCH_TYPE_BY_MATCH_LEVEL.get(result['MatchLevel'], None)
match_type = self.MATCH_TYPE_BY_MATCH_LEVEL.get(result['MatchLevel'], None)
return {
'relevance': result['Relevance'],
'precision': precision,

View File

@ -315,6 +315,11 @@ class TestBulkStreetFunctions(TestStreetFunctionsSetUp):
assert_equal(n, len(response['rows']))
for row in response['rows']:
assert_not_equal(row['st_x'], None)
assert_not_equal(row['metadata'], {})
metadata = row['metadata']
assert_not_equal(metadata['relevance'], None)
assert_not_equal(metadata['precision'], None)
assert_not_equal(metadata['match_types'], None)
def test_missing_components_on_private_function(self):
query = "SELECT _cdb_bulk_geocode_street_point(" \