57 lines
1.7 KiB
Python
57 lines
1.7 KiB
Python
import inspect
|
|
import logging
|
|
import unittest
|
|
|
|
import folium
|
|
from folium import TileLayer
|
|
|
|
from app.App import App
|
|
from core.domain.map.GeoLocation import GeoLocation
|
|
from core.domain.optimization.TransportMode import TransportMode
|
|
from core.extend import fs
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
class Test_main(unittest.TestCase):
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
cls.dataDir = fs.getPath(__file__, "test_data")
|
|
App.init()
|
|
|
|
@classmethod
|
|
def __drawRouteInfo(cls, transportMode: TransportMode, legs: list[GeoLocation], testName: str):
|
|
output = cls.dataDir.joinpath(f"{testName}.html")
|
|
routeInfo = App.services.routingService.getRouteInfo(transportMode=TransportMode.CAR, legs=legs)
|
|
print(routeInfo)
|
|
|
|
latSum = 0
|
|
lonSum = 0
|
|
|
|
for g in routeInfo.steps:
|
|
latSum += g.lat
|
|
lonSum += g.lon
|
|
|
|
folium_map = folium.Map(location=[latSum / len(routeInfo.steps), lonSum / len(routeInfo.steps)], zoom_start=18, max_zoom=30,
|
|
tiles=TileLayer(max_zoom=30, max_native_zoom=30, name="OpenStreetMap"))
|
|
|
|
folium.PolyLine(locations=[(step.lat, step.lon) for step in routeInfo.steps], color="blue", weight=2.5, opacity=0.8).add_to(folium_map)
|
|
|
|
folium_map.save(output)
|
|
|
|
def test_000(self):
|
|
testName = inspect.currentframe().f_code.co_name
|
|
|
|
legs=[
|
|
GeoLocation(lat=46.56157837316846, lon=15.036126073183372),
|
|
GeoLocation(lat=46.55359554022851, lon=15.030295168115506)
|
|
]
|
|
|
|
self.__drawRouteInfo(transportMode=TransportMode.CAR, legs=legs, testName=testName + "_car")
|
|
self.__drawRouteInfo(transportMode=TransportMode.EV, legs=legs, testName=testName + "_ev")
|
|
self.__drawRouteInfo(transportMode=TransportMode.MK, legs=legs, testName=testName + "_mk")
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|