def make_experiment(): MyConfig = osrm.RequestConfig("localhost:5000/v1/driving") for size in range(2000, 2001, 1): points = [random_point() for i in range(size)] st = time() res = osrm.table(points, points, url_config=MyConfig) print(res[0]) print(size, round(time() - st, 4))
def test_RequestConfig(self): default_host = osrm.RequestConfig.host # Make a new RequestConfig object MyConfig = osrm.RequestConfig() MyConfig.host = "http://0.0.0.0:5000" # Only change the host # ..so the profile and the version should remain unchanged self.assertEqual(str(MyConfig), "http://0.0.0.0:5000/*/v1/driving") # Make a new one by writing directly the pattern to use : MyOtherConfig = MyConfig("192.168.1.1/v1/biking") self.assertEqual(MyOtherConfig.profile, "biking") # Two equivalent ways are available to write the url pattern : MyOtherConfig2 = MyConfig("192.168.1.1/*/v1/biking") self.assertEqual(str(MyOtherConfig), str(MyOtherConfig2)) # Parameters from the original RequestConfig object haven't changed: self.assertEqual(osrm.RequestConfig.host, default_host)
def test_non_existing_host(self): Profile = osrm.RequestConfig("localhost/v1/flying") self.assertEqual(Profile.host, "localhost") with self.assertRaises(URLError): osrm.nearest((12.36, 45.36), url_config=Profile) with self.assertRaises(URLError): osrm.trip([(13.38886, 52.51703), (10.00, 53.55), (52.374444, 9.738611)], url_config=Profile) with self.assertRaises(URLError): osrm.simple_route((13.38886, 52.51703), (10.00, 53.55), url_config=Profile) with self.assertRaises(URLError): osrm.AccessIsochrone((13.38886, 52.51703), points_grid=100, url_config=Profile) with self.assertRaises(URLError): osrm.match([(10.00, 53.55), (52.374444, 9.738611)], url_config=Profile) with self.assertRaises(URLError): osrm.table([(10.00, 53.55), (52.374444, 9.738611)], [(10.00, 53.55), (52.374444, 9.738611)], url_config=Profile)
# кодирование строки в base64 - https://tech.yandex.ru/maps/doc/archive/jsapi/1.x/dg/tasks/how-to-add-polyline-docpage/#encoding-polyline-points import osrm #https://github.com/ustroetz/python-osrm from osrm import Point, simple_route import csv import operator import json import time MyConfig = osrm.RequestConfig("localhost:9999/v1/biking", basic_auth=("user", "pass")) MyConfig.profile = "biking" osrm.RequestConfig.host = "router.project-osrm.org" #запись данных в массив stations из staions_spb.csv index = 0 stations = {} new_stations = [] with open('stations_spb.csv', 'r', encoding="utf8") as stations_spb: reader = csv.reader(stations_spb, dialect=csv.excel_tab) for row in reader: if index > 0: #print(stations[index]) new_stations.append(row) index += 1 new_stations.sort() print(new_stations) #вывод значения hint по 2 точкам i = 0