From 610ce01e6b713198d1d01eaa84aa1635925427d7 Mon Sep 17 00:00:00 2001 From: Zebreu Date: Sun, 21 Apr 2024 00:15:20 -0400 Subject: [PATCH] Add an implicit default session if no files are uploaded and fix up map and vehicle uploads --- dkroutingtool/src/py/server.py | 14 ++++++++++---- dkroutingtool/src/py/ui/dashboard.py | 8 ++++++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/dkroutingtool/src/py/server.py b/dkroutingtool/src/py/server.py index ad74f63..b3c6bbd 100644 --- a/dkroutingtool/src/py/server.py +++ b/dkroutingtool/src/py/server.py @@ -43,15 +43,18 @@ def update_vehicle_or_map(session_id: str=''): if vehicle_files: for curr_file in vehicle_files: os.replace(curr_file, os.path.join('/osrm-backend/profiles', os.path.basename(curr_file))) + veh_directory = '/'+os.path.basename(curr_file)[:-4] # removing the extension + if not os.path.exists(veh_directory): + os.makedirs(veh_directory) build_profiles = True # Look for osm.pbf file. Just pulls the first in sorted order if multiple are present. map_files = sorted(glob.glob(f'/data{session_id}/*.pbf')) if map_files: os.environ['osm_filename'] = 'upload_map' - os.replace(map_files[0], '/upload_map.osm') + os.replace(map_files[0], '/upload_map.osm.pbf') build_profiles = True if build_profiles: - temporary_build_profiles() + temporary_build_profiles(osmpbf=True) @app.get('/get_solution') def get_solution(session_id: str=''): @@ -133,7 +136,7 @@ def get_vehicles(): return desired_vehicles -def temporary_build_profiles(): +def temporary_build_profiles(osmpbf=False): desired_vehicles = get_vehicles() print('Extracting-contracting networks per vehicle') @@ -149,7 +152,10 @@ def temporary_build_profiles(): if vehicle_name not in desired_vehicles: continue print('Building', vehicle_file) - subprocess.run(['osrm-extract', '-p', vehicle_file, f'/{osm_filename}.osm']) + if not osmpbf: + subprocess.run(['osrm-extract', '-p', vehicle_file, f'/{osm_filename}.osm']) + else: + subprocess.run(['osrm-extract', '-p', vehicle_file, f'/{osm_filename}.osm.pbf']) subprocess.run(f'mv {osm_filename}.osrm* {vehicle_name}/', shell=True) subprocess.run(['osrm-contract', f'{osm_filename}.osrm'], cwd=vehicle_name) diff --git a/dkroutingtool/src/py/ui/dashboard.py b/dkroutingtool/src/py/ui/dashboard.py index 2a65535..c071cf0 100644 --- a/dkroutingtool/src/py/ui/dashboard.py +++ b/dkroutingtool/src/py/ui/dashboard.py @@ -14,7 +14,8 @@ st.set_page_config(page_title='Container-based Action Routing Tool (CART)', layout="wide") runtime = get_instance() -session_id = get_script_run_ctx().session_id +session_id = '' + host_url = 'http://{}:5001'.format(os.environ['SERVER_HOST']) def download_solution(solution_path, map_path): @@ -68,6 +69,9 @@ def adjust(adjusted_file): return message, solution, map, solution_zip def upload_data(files_from_streamlit): + global session_id + session_id = get_script_run_ctx().session_id # Only identifies a session if configuration files are uploaded + files = [('files', file) for file in files_from_streamlit] headers = { @@ -117,7 +121,7 @@ def main(): if len(uploaded_files) > 0: response = upload_data(uploaded_files) st.write(response) - vehicle_or_map_update_requested = st.button('If updated vehicles + updated build_paramters.yml or a *.osm.pbf map was uploaded, click here to update.') + vehicle_or_map_update_requested = st.button('If you uploaded modified *.lua, build_parameters.yml, or *.osm.pbf files, click here to update the network') if vehicle_or_map_update_requested: with st.spinner('Rebuilding based on updated vehicles/maps. This may take a few minutes, please wait...'): update_vehicle_or_map()