114 lines
4.0 KiB
Python
114 lines
4.0 KiB
Python
import datetime
|
|
import random
|
|
import unittest
|
|
|
|
from app.App import App
|
|
from core.domain.map.GeoLocation import GeoLocation
|
|
from core.domain.optimization.TransportMode import TransportMode
|
|
|
|
|
|
class test_RoutingService(unittest.TestCase):
|
|
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
App.init()
|
|
|
|
def test_speed(self):
|
|
starts = [GeoLocation(lat=46.0399789 + random.uniform(-0.1, 0.1), lon=14.5076505 + random.uniform(-0.1, 0.1)) for i in range(100)]
|
|
ends = [GeoLocation(lat=46.1399789 + random.uniform(-0.1, 0.1), lon=14.6076505 + random.uniform(-0.1, 0.1)) for i in range(100)]
|
|
start = datetime.datetime.now()
|
|
routeInfos = App.services.routingService.getRouteInfoMatrix(transportMode=TransportMode.WALK, starts=starts, ends=ends, accurate=True)
|
|
end = datetime.datetime.now()
|
|
diff = (end - start).total_seconds()
|
|
print(diff, len(routeInfos))
|
|
|
|
def test_routeInfo_walk(self):
|
|
start = GeoLocation(lat=46.0399789, lon=14.5076505)
|
|
end = GeoLocation(lat=46.0423508, lon=14.509163)
|
|
matrix = App.services.routingService.getRouteInfoMatrix(
|
|
transportMode=TransportMode.WALK,
|
|
starts=[start],
|
|
ends=[end],
|
|
accurate=True
|
|
)
|
|
print(matrix)
|
|
|
|
def test_routing_steps(self):
|
|
start = GeoLocation(46.093579794174296, 14.27906301507719)
|
|
end = GeoLocation(46.06541666237525, 14.314559238921543)
|
|
polyline = App.services.routingService._getPolyline(transportMode=TransportMode.CAR, legs=[start, end])
|
|
routeInfo = App.services.routingService.getRouteInfo(transportMode=TransportMode.CAR, legs=[start, end])
|
|
#
|
|
# steps2 = App.services.routingService.getRouteMatrix(
|
|
# transportMode=TransportMode.CAR,
|
|
# crnPoints=[start],
|
|
# )
|
|
|
|
print(polyline)
|
|
print(routeInfo.duration / 60,routeInfo)
|
|
# print(steps2)
|
|
|
|
def test_distance_matrix(self):
|
|
crnPoints = App.services.postaService.getCrnPoints(posta=1355)[:10]
|
|
routeMatrix = App.services.routingService.getRouteMatrix(
|
|
crnPoints=crnPoints,
|
|
transportMode=TransportMode.CAR
|
|
)
|
|
routeInfo = App.services.routingService.getRouteInfo(
|
|
legs=[crn.location for crn in crnPoints],
|
|
transportMode=TransportMode.CAR
|
|
)
|
|
print(routeMatrix.data)
|
|
print(routeInfo)
|
|
|
|
|
|
def test_matrix(self):
|
|
crns = App.services.postaService.getCrnPoints(posta=1355)
|
|
posta = App.repos.postOfficeRepo.get(posta = 1355)
|
|
crns.insert(0, posta.getCrnPoint())
|
|
|
|
locations = []
|
|
for i in [0, 12, 418]:
|
|
print(f"Index: {i}: {crns[i]}")
|
|
|
|
locations.append(crns[i].location)
|
|
|
|
for i in [0, 12, 418]:
|
|
for j in [0, 12, 418]:
|
|
crnStart = crns[i]
|
|
crnEnd = crns[j]
|
|
routeInfo = App.services.routingService.getRouteInfo(transportMode=TransportMode.CAR, legs=[crnStart.location, crnEnd.location])
|
|
print(f"Start house: {crnStart.hisa}, end house: {crnEnd.hisa}, distance={routeInfo.distance}, duration={routeInfo.duration/60}")
|
|
|
|
routeMatrix = App.services.routingService.getRouteMatrix(starts=locations, ends=locations, transportMode=TransportMode.CAR)
|
|
|
|
print("Durations [min]")
|
|
print(routeMatrix.durations / 60)
|
|
print("Distances [m]")
|
|
print(routeMatrix.distances)
|
|
|
|
def test_matrix2(self):
|
|
crns = App.services.postaService.getCrnPoints(posta=1355)
|
|
posta = App.repos.postOfficeRepo.get(posta = 1355)
|
|
crns.insert(0, posta.getCrnPoint())
|
|
|
|
locations = []
|
|
for i in [0, 12, 418]:
|
|
print(f"Index: {i}: {crns[i]}")
|
|
locations.append(crns[i])
|
|
|
|
routeMatrix = App.services.routingService.getRouteMatrix(crnPoints=locations, transportMode=TransportMode.CAR)
|
|
print(routeMatrix.data.dtypes)
|
|
print(routeMatrix.data.to_string())
|
|
|
|
def test_matrix_route(self):
|
|
start = GeoLocation(46.039868240098436, 14.527908242928524)
|
|
end = GeoLocation(46.04046411845911, 14.52994784714586)
|
|
# matrix = App.services.routingService.getRouteMatrix(geoLocations=[start, end], transportMode=TransportMode.CAR)
|
|
# route = App.services.routingService.getRouteInfo(transportMode=TransportMode.CAR, legs=[start, end])
|
|
route = App.services.routingService._getPolyline(transportMode=TransportMode.CAR, legs=[start, end])
|
|
print(route)
|
|
|
|
# print(matrix)
|
|
# print(route.duration,route.distance)
|