Exemplo n.º 1
0
async def request():
    client = osrm.AioHTTPClient(host='http://localhost:5000')
    response = await client.table(
        coordinates=[[-74.0056, 40.6197], [-74.0034, 40.6333]],
        overview=osrm.overview.full)
    print(response)
    await client.close()
Exemplo n.º 2
0
 async def async_requests(self, pts):
     Client = osrm.AioHTTPClient(host='http://localhost:5000')
     response = await asyncio.gather(*[
         asyncio.ensure_future(Client.nearest(coordinates=[p])) for p in pts
     ])
     await Client.close()
     return response
Exemplo n.º 3
0
async def osrm_route(src, dst, reverse=False, amortized=False):
    X, T = 0, 0
    if amortized:
        expected_src = mus[flag.value].nearest(np.array(dst))
        expected_routes = osrm_route(expected_src, dst, reverse=True)
        for r in expected_routes:
            X += r['routes'][0]['distance']
            T += r['routes'][0]['duration']
        X /= len(expected_routes)
        T /= len(expected_routes)
    client = osrm.AioHTTPClient(
        host='http://localhost:{}'.format(osrm_port.value + flag.value))
    response = []
    for s in src:
        r = await client.route(
            coordinates=[[s[1], s[0]], [dst[1], dst[0]]]
            if not reverse else [[dst[1], dst[0]], [s[1], s[0]]],
            overview=osrm.overview.full,
            steps=True,
            geometries=osrm.geometries.polyline,
        )
        r['routes'][0]['distance'] += X
        r['routes'][0]['duration'] += T
        response.append(r)
    await client.close()
    return response
Exemplo n.º 4
0
    async def test_real_timeout(self):
        client = osrm.AioHTTPClient(
            host=OSRM_HOST, timeout=0.01, max_retries=1)
        with self.assertRaises(osrm.OSRMServerException) as cm:
            await client.match(
                coordinates=[[-73.999, 40.724], [-73.994, 40.728]],
                radiuses=[150, 150]
            )
            await client.close()

        assert cm.exception.args[1] == 'server timeout'
Exemplo n.º 5
0
async def optimized_route(src, dst):
    client = osrm.AioHTTPClient(host='http://localhost:5555')
    response = []
    now = time.time()
    for s in src:
        route = await client.route(
            coordinates=[s, dst],
            overview=osrm.overview.full,
            steps=True,
            geometries=osrm.geometries.polyline,
        )

        response.append(optimize(route, now))
    await client.close()
    return response
Exemplo n.º 6
0
 async def async_route(self, od_list, annotations=False):
     Client = osrm.AioHTTPClient(host='http://localhost:5000')
     # responses = []
     # for pt in od_list:
     #     print('checkpoint',pt)
     #     response = await asyncio.gather(*[asyncio.ensure_future(Client.route(coordinates=pt,steps=True))])
     #     responses.append(response)
     response = await asyncio.gather(*[
         asyncio.ensure_future(
             Client.route(coordinates=pt,
                          steps=True,
                          continue_straight=osrm.continue_straight.false))
         for pt in od_list
     ])
     await Client.close()
     return response
Exemplo n.º 7
0
    def setUp(self):
        self.loop = asyncio.new_event_loop()
        asyncio.set_event_loop(self.loop)

        async def _setUp():
            self.session = aiohttp.ClientSession(loop=self.loop)
            self.client = osrm.AioHTTPClient(
                host=OSRM_HOST, session=self.session, timeout=0.2
            )

        self.mock_session = MagicMock()
        self.mock_client = osrm.AioHTTPClient(
            host=OSRM_HOST, session=self.mock_session,
            timeout=0.2, max_retries=3
        )

        self.loop.run_until_complete(_setUp())
Exemplo n.º 8
0
 async def _setUp():
     self.session = aiohttp.ClientSession(loop=self.loop)
     self.client = osrm.AioHTTPClient(
         host=OSRM_HOST, session=self.session, timeout=0.2
     )