def test_main(mock_server, test_client_config): mock_server.reset() client = Dispatcher(test_client_config) res = client.distance_matrix(origins=ORIGS, destinations=DESTS, provider='google') assert len(res) == 1975 assert res.isnull().sum().sum() == 0
def main(): client = Dispatcher() s = time.time() res, inv = client.distance_matrix(origins=ORIGS, destinations=DESTS, provider='google', return_inverse=True) t = time.time() - s prettyprinter.pprint(res.take(inv.flat)) print('Duration: %dms' % (t * 1000))
def main(): client = Dispatcher() s = time.time() res = client.distance_matrix( origins=np.random.rand(10, 2) * [20, 20] + [25, -90], destinations=np.random.rand(10, 2) * [20, 20] + [25, -90], provider='google') t = time.time() - s prettyprinter.pprint(res) print('Duration: %dms' % (t * 1000))
def test_square(mock_server): mock_server.reset() client = Dispatcher({ 'providers': { 'google': { 'type_': 'google', 'key': 'test123', 'base_url': 'http://localhost:8080/' } } }) res = client.distance_matrix( origins=LOCS, destinations=LOCS, provider='google', max_meters=np.Infinity ) assert len(res) == 2500 assert res.isnull().sum().sum() == 0
def test_main(mock_server, test_client_config): mock_server.reset() client = Dispatcher(test_client_config) res, inv = client.distance_matrix(origins=np.array([[37.2, -88.2], [37.1, -88.1], [42.5, -97.5]]), destinations=np.array([[37.1, -88.1], [45.5, -97.5], [37.1, -86.1], [41.9, -97.2]]), provider='google', return_inverse=True) assert res.isnull().sum().sum() == 0 # np.unique will end up sorting index pd.testing.assert_index_equal( res.index, pd.MultiIndex.from_tuples([ (37.1, -88.1, 37.1, -88.1), (37.1, -88.1, 37.1, -86.1), (37.1, -88.1, 41.9, -97.2), (37.1, -88.1, 45.5, -97.5), (37.2, -88.2, 37.1, -88.1), (37.2, -88.2, 37.1, -86.1), (37.2, -88.2, 41.9, -97.2), (37.2, -88.2, 45.5, -97.5), (42.5, -97.5, 37.1, -88.1), (42.5, -97.5, 37.1, -86.1), (42.5, -97.5, 41.9, -97.2), (42.5, -97.5, 45.5, -97.5), ], names=['olat', 'olon', 'dlat', 'dlon'])) # double check these values if they should need to change. # should be able to eyeball if they look reasonable. expected_meters = [ 0., 444779., 1143293.274236, 1400881.808377, 44477., 489257., 1128289.345949, 1385191.366365, 1204670.037841, 1401763.032474, 200150., 667169. ] np.testing.assert_array_almost_equal(res.meters.values, expected_meters) # restore index with inverse key # should be origin-major traversal pd.testing.assert_index_equal( res.take(inv.flat).index, pd.MultiIndex.from_tuples([ (37.2, -88.2, 37.1, -88.1), (37.2, -88.2, 45.5, -97.5), (37.2, -88.2, 37.1, -86.1), (37.2, -88.2, 41.9, -97.2), (37.1, -88.1, 37.1, -88.1), (37.1, -88.1, 45.5, -97.5), (37.1, -88.1, 37.1, -86.1), (37.1, -88.1, 41.9, -97.2), (42.5, -97.5, 37.1, -88.1), (42.5, -97.5, 45.5, -97.5), (42.5, -97.5, 37.1, -86.1), (42.5, -97.5, 41.9, -97.2), ], names=['olat', 'olon', 'dlat', 'dlon']))