Relevance metadata for Mapbox

This commit is contained in:
Juan Ignacio Sánchez Lara
2018-07-11 07:42:21 +02:00
parent 2af9204542
commit 825e3b7ee8
3 changed files with 68 additions and 37 deletions

View File

@@ -22,7 +22,7 @@ class TestStreetFunctionsSetUp(TestCase):
'Madrid': [-3.7037902, 40.4167754],
'Logroño, Spain': [-2.4449852, 42.4627195],
'Logroño, Argentina': [-61.6961807, -29.5031057],
'Plaza España 1, Barcelona': [2.1482563, 41.375485]
'Plaza España, Barcelona': [2.1482563, 41.375485]
}
HERE_POINTS = {
@@ -37,7 +37,7 @@ class TestStreetFunctionsSetUp(TestCase):
'Madrid': [-3.70578, 40.42028],
'Logroño, Spain': [-2.45194, 42.46592],
'Logroño, Argentina': [-61.69604, -29.50425],
'Plaza España 1, Barcelona': [2.1735699, 41.3823] # TODO: not ideal
'Plaza España, Barcelona': [2.1735699, 41.3823] # TODO: not ideal
}
TOMTOM_POINTS = HERE_POINTS.copy()
@@ -48,7 +48,7 @@ class TestStreetFunctionsSetUp(TestCase):
'Valladolid, Spain': [-4.72838, 41.6542],
'Madrid': [-3.70035, 40.42028],
'Logroño, Spain': [-2.44998, 42.46592],
'Plaza España 1, Barcelona': [2.07479, 41.36818] # TODO: not ideal
'Plaza España, Barcelona': [2.07479, 41.36818] # TODO: not ideal
})
MAPBOX_POINTS = GOOGLE_POINTS.copy()
@@ -59,7 +59,7 @@ class TestStreetFunctionsSetUp(TestCase):
'Valladolid, Spain': [-4.72856, 41.652251],
'1902 amphitheatre parkway': [-118.03, 34.06], # TODO: huge mismatch
'Madrid': [-3.69194, 40.4167754],
'Plaza España 1, Barcelona': [2.245969, 41.452483] # TODO: not ideal
'Plaza España, Barcelona': [2.245969, 41.452483] # TODO: not ideal
})
FIXTURE_POINTS = {
@@ -69,6 +69,21 @@ class TestStreetFunctionsSetUp(TestCase):
'mapbox': MAPBOX_POINTS
}
HERE_RELEVANCES = {
'Plaza España, Barcelona': 1
}
MAPBOX_RELEVANCES = {
'Plaza España, Barcelona': 0.75
}
RELEVANCES = {
'here': HERE_RELEVANCES,
'tomtom': HERE_RELEVANCES,
'mapbox': MAPBOX_RELEVANCES,
'google': HERE_RELEVANCES
}
def setUp(self):
self.env_variables = IntegrationTestHelper.get_environment_variables()
self.sql_api_url = "{0}://{1}.{2}/api/v1/sql".format(
@@ -86,6 +101,8 @@ class TestStreetFunctionsSetUp(TestCase):
provider = response['rows'][0]['provider']
self.fixture_points = self.FIXTURE_POINTS[provider]
self.relevances = self.RELEVANCES[provider]
def _run_authenticated(self, query):
authenticated_query = "{}&api_key={}".format(query,
@@ -118,12 +135,12 @@ class TestStreetFunctions(TestStreetFunctionsSetUp):
def test_component_aggregation(self):
query = "select st_x(the_geom), st_y(the_geom) from (" \
"select cdb_dataservices_client.cdb_geocode_street_point( " \
"'Plaza España 1', 'Barcelona', null, 'Spain') as the_geom) _x"
"'Plaza España', 'Barcelona', null, 'Spain') as the_geom) _x"
response = self._run_authenticated(query)
row = response['rows'][0]
x_y = [row['st_x'], row['st_y']]
# Wrong coordinates (Plaza España, Madrid): [-3.7138975, 40.4256762]
assert_close_enough(x_y, self.fixture_points['Plaza España 1, Barcelona'])
assert_close_enough(x_y, self.fixture_points['Plaza España, Barcelona'])
class TestBulkStreetFunctions(TestStreetFunctionsSetUp):
@@ -294,18 +311,18 @@ class TestBulkStreetFunctions(TestStreetFunctionsSetUp):
x_y_by_cartodb_id = self._x_y_by_cartodb_id(response)
assert_equal(x_y_by_cartodb_id[1], x_y_by_cartodb_id[2])
# "'Plaza España 1', 'Barcelona', null, 'Spain') as the_geom) _x"
# "'Plaza España', 'Barcelona', null, 'Spain') as the_geom) _x"
def test_component_aggregation(self):
query = "select cartodb_id, st_x(the_geom), st_y(the_geom) " \
"FROM cdb_dataservices_client.cdb_bulk_geocode_street_point(" \
"'select 1 as cartodb_id, ''Spain'' as country, " \
"''Barcelona'' as city, " \
"''Plaza España 1'' as street' " \
"''Plaza España'' as street' " \
", 'street', 'city', NULL, 'country')"
response = self._run_authenticated(query)
assert_close_enough(self._x_y_by_cartodb_id(response)[1],
self.fixture_points['Plaza España 1, Barcelona'])
self.fixture_points['Plaza España, Barcelona'])
def _test_known_table(self):
subquery = 'select * from known_table where cartodb_id < 1100'
@@ -325,11 +342,12 @@ class TestBulkStreetFunctions(TestStreetFunctionsSetUp):
"FROM cdb_dataservices_client.cdb_bulk_geocode_street_point(" \
"'select 1 as cartodb_id, ''Spain'' as country, " \
"''Barcelona'' as city, " \
"''Plaza España 1'' as street' " \
"''Plaza España'' as street' " \
", 'street', 'city', NULL, 'country')"
response = self._run_authenticated(query)
assert_true(isclose(response['rows'][0]['metadata']['relevance'], 1))
assert_true(isclose(response['rows'][0]['metadata']['relevance'],
self.relevances['Plaza España, Barcelona']))
def _run_authenticated(self, query):
authenticated_query = "{}&api_key={}".format(query,