示例#1
0
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
示例#2
0
def main():
    client = Dispatcher()

    s = time.time()
    res = client.geocode('500 Rutherford Ave, Charlestown MA',
                         provider='google')

    t = time.time() - s
    prettyprinter.pprint(res)
    print('Duration: %dms' % (t * 1000))
示例#3
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))
示例#4
0
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))
示例#5
0
def test_pairs(mock_server, test_client_config):
    mock_server.reset()
    client = Dispatcher(test_client_config)

    res, inv = client.distance_pairs(origins=np.array([[37.1, -88.1],
                                                       [37.2, -88.2],
                                                       [42.5, -97.5],
                                                       [37.1, -88.1],
                                                       [37.1, -88.1]]),
                                     destinations=np.array([[37.1, -88.1],
                                                            [45.5, -97.5],
                                                            [37.1, -86.1],
                                                            [41.9, -97.2],
                                                            [37.1, -88.1]]),
                                     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, 41.9, -97.2),
            (37.2, -88.2, 45.5, -97.5),
            (42.5, -97.5, 37.1, -86.1),
        ],
                                  names=['olat', 'olon', 'dlat', 'dlon']))

    expected_meters = [0., 1143293.274236, 1385191.366365, 1401763.032474]

    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.1, -88.1, 37.1, -88.1),
            (37.2, -88.2, 45.5, -97.5),
            (42.5, -97.5, 37.1, -86.1),
            (37.1, -88.1, 41.9, -97.2),
            (37.1, -88.1, 37.1, -88.1),
        ],
                                  names=['olat', 'olon', 'dlat', 'dlon']))
示例#6
0
def main():
    client = Dispatcher()

    s = time.time()

    res = client.distance_pairs(origins=np.array([(34.1165, -92.2353),
                                                  (34.1368, -94.5823),
                                                  (32.2665, -92.0353),
                                                  (40.3283, -88.3080)]),
                                destinations=np.array([(34.1368, -94.5823),
                                                       (36.3408, -96.0384),
                                                       (32.2834, -92.0286),
                                                       (40.3468, -88.2936)]),
                                max_meters=200 * METERS_PER_MILE,
                                provider='google')

    t = time.time() - s
    prettyprinter.pprint(res)
    print('Duration: %dms' % (t * 1000))
示例#7
0
def main():
    client = Dispatcher()

    s = time.time()

    res = client.batch_geocode(
        [
            '500 Rutherford Ave, Charlestown MA',
            'Cake Factory',
            '21 Henr St, Bristol, UK',
            'TD Bank 250 Cambridge Street Boston, MA 02114',
            m.GeoPoint(lon=-94.5823, lat=34.1368)
        ],
        provider='google'
    )

    t = time.time() - s
    # convert to DataFrame
    prettyprinter.pprint(addresses_to_df(res))
    print('Duration: %dms' % (t * 1000))
示例#8
0
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
示例#9
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']))