multimodalsim-viewer 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- multimodalsim_viewer/__init__.py +0 -0
- multimodalsim_viewer/server/__init__.py +0 -0
- multimodalsim_viewer/server/http_routes.py +125 -0
- multimodalsim_viewer/server/log_manager.py +15 -0
- multimodalsim_viewer/server/scripts.py +72 -0
- multimodalsim_viewer/server/server.py +210 -0
- multimodalsim_viewer/server/server_utils.py +129 -0
- multimodalsim_viewer/server/simulation.py +154 -0
- multimodalsim_viewer/server/simulation_manager.py +607 -0
- multimodalsim_viewer/server/simulation_visualization_data_collector.py +756 -0
- multimodalsim_viewer/server/simulation_visualization_data_model.py +1693 -0
- multimodalsim_viewer/ui/__init__.py +0 -0
- multimodalsim_viewer/ui/cli.py +45 -0
- multimodalsim_viewer/ui/server.py +44 -0
- multimodalsim_viewer/ui/static/bitmap-fonts/custom-sans-serif.png +0 -0
- multimodalsim_viewer/ui/static/bitmap-fonts/custom-sans-serif.xml +1 -0
- multimodalsim_viewer/ui/static/chunk-MTC2LSCT.js +1 -0
- multimodalsim_viewer/ui/static/chunk-U5CGW4P4.js +7 -0
- multimodalsim_viewer/ui/static/favicon.ico +0 -0
- multimodalsim_viewer/ui/static/images/control-bar.png +0 -0
- multimodalsim_viewer/ui/static/images/sample-bus.png +0 -0
- multimodalsim_viewer/ui/static/images/sample-stop.png +0 -0
- multimodalsim_viewer/ui/static/images/sample-wait.png +0 -0
- multimodalsim_viewer/ui/static/images/simulation-control-bar.png +0 -0
- multimodalsim_viewer/ui/static/images/zoom-out-passenger.png +0 -0
- multimodalsim_viewer/ui/static/images/zoom-out-vehicle.png +0 -0
- multimodalsim_viewer/ui/static/index.html +15 -0
- multimodalsim_viewer/ui/static/main-X7OVCS3N.js +3648 -0
- multimodalsim_viewer/ui/static/media/layers-2x-TBM42ERR.png +0 -0
- multimodalsim_viewer/ui/static/media/layers-55W3Q4RM.png +0 -0
- multimodalsim_viewer/ui/static/media/marker-icon-2V3QKKVC.png +0 -0
- multimodalsim_viewer/ui/static/polyfills-FFHMD2TL.js +2 -0
- multimodalsim_viewer/ui/static/styles-KU7LTPET.css +1 -0
- multimodalsim_viewer-0.0.1.dist-info/METADATA +21 -0
- multimodalsim_viewer-0.0.1.dist-info/RECORD +38 -0
- multimodalsim_viewer-0.0.1.dist-info/WHEEL +5 -0
- multimodalsim_viewer-0.0.1.dist-info/entry_points.txt +8 -0
- multimodalsim_viewer-0.0.1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,154 @@
|
|
1
|
+
import os
|
2
|
+
import threading
|
3
|
+
|
4
|
+
from multimodalsim.observer.data_collector import DataContainer, StandardDataCollector
|
5
|
+
from multimodalsim.observer.environment_observer import EnvironmentObserver
|
6
|
+
from multimodalsim.simulator.simulator import Simulator
|
7
|
+
from multimodalsim.statistics.data_analyzer import FixedLineDataAnalyzer
|
8
|
+
from multimodalsim_viewer.server.server_utils import (
|
9
|
+
build_simulation_id,
|
10
|
+
get_available_data,
|
11
|
+
get_data_directory_path,
|
12
|
+
set_event_on_input,
|
13
|
+
verify_simulation_name,
|
14
|
+
)
|
15
|
+
from multimodalsim_viewer.server.simulation_visualization_data_collector import (
|
16
|
+
SimulationVisualizationDataCollector,
|
17
|
+
)
|
18
|
+
|
19
|
+
|
20
|
+
def run_simulation(
|
21
|
+
simulation_id: str,
|
22
|
+
data: str,
|
23
|
+
max_duration: float | None,
|
24
|
+
stop_event: threading.Event | None = None,
|
25
|
+
is_offline: bool = False,
|
26
|
+
) -> None:
|
27
|
+
data_container = DataContainer()
|
28
|
+
|
29
|
+
data_collector = SimulationVisualizationDataCollector(
|
30
|
+
FixedLineDataAnalyzer(data_container),
|
31
|
+
max_duration=max_duration,
|
32
|
+
simulation_id=simulation_id,
|
33
|
+
input_data_description=data,
|
34
|
+
offline=is_offline,
|
35
|
+
stop_event=stop_event,
|
36
|
+
)
|
37
|
+
|
38
|
+
environment_observer = EnvironmentObserver(
|
39
|
+
[StandardDataCollector(data_container), data_collector],
|
40
|
+
)
|
41
|
+
|
42
|
+
simulation_data_directory = get_data_directory_path(data) + "/"
|
43
|
+
|
44
|
+
if not os.path.exists(simulation_data_directory):
|
45
|
+
print(f"Simulation data directory {simulation_data_directory} does not exist")
|
46
|
+
return
|
47
|
+
|
48
|
+
simulator = Simulator(
|
49
|
+
simulation_data_directory,
|
50
|
+
visualizers=environment_observer.visualizers,
|
51
|
+
data_collectors=environment_observer.data_collectors,
|
52
|
+
)
|
53
|
+
simulation_thread = threading.Thread(target=simulator.simulate)
|
54
|
+
simulation_thread.start()
|
55
|
+
|
56
|
+
# Wait for the simulation to finish
|
57
|
+
while simulation_thread.is_alive() and (
|
58
|
+
stop_event is None or not stop_event.is_set()
|
59
|
+
):
|
60
|
+
simulation_thread.join(timeout=5) # Check every 5 seconds
|
61
|
+
|
62
|
+
if simulation_thread.is_alive():
|
63
|
+
print("Simulation is still running, stopping it")
|
64
|
+
simulator.stop()
|
65
|
+
|
66
|
+
simulation_thread.join()
|
67
|
+
|
68
|
+
if stop_event is not None:
|
69
|
+
stop_event.set()
|
70
|
+
|
71
|
+
|
72
|
+
def run_simulation_cli():
|
73
|
+
import argparse
|
74
|
+
|
75
|
+
import questionary
|
76
|
+
|
77
|
+
parser = argparse.ArgumentParser(description="Run a simulation")
|
78
|
+
parser.add_argument("--name", type=str, help="The name of the simulation")
|
79
|
+
parser.add_argument("--data", type=str, help="The data to use for the simulation")
|
80
|
+
parser.add_argument(
|
81
|
+
"--max-duration", type=float, help="The maximum duration to run the simulation"
|
82
|
+
)
|
83
|
+
parser.add_argument(
|
84
|
+
"--offline",
|
85
|
+
action="store_true",
|
86
|
+
help="Run the simulation in offline mode without requiring internet access",
|
87
|
+
)
|
88
|
+
|
89
|
+
args = parser.parse_args()
|
90
|
+
|
91
|
+
name = args.name
|
92
|
+
data = args.data
|
93
|
+
max_duration = args.max_duration
|
94
|
+
is_offline = args.offline
|
95
|
+
|
96
|
+
name_error = verify_simulation_name(name)
|
97
|
+
|
98
|
+
while name_error is not None:
|
99
|
+
print(f"Error: {name_error}")
|
100
|
+
name = questionary.text(
|
101
|
+
"Enter the name of the simulation (spaces will be replaced by underscores)"
|
102
|
+
).ask()
|
103
|
+
name_error = verify_simulation_name(name)
|
104
|
+
|
105
|
+
name = name.replace(" ", "_")
|
106
|
+
|
107
|
+
available_data = get_available_data()
|
108
|
+
|
109
|
+
if len(available_data) == 0:
|
110
|
+
print("No input data is available, please provide some in the data folder")
|
111
|
+
exit(1)
|
112
|
+
|
113
|
+
if data is None:
|
114
|
+
# Get all available data
|
115
|
+
|
116
|
+
data = questionary.select(
|
117
|
+
"Select the data to use for the simulation",
|
118
|
+
choices=available_data,
|
119
|
+
).ask()
|
120
|
+
|
121
|
+
print("Selected data:", data)
|
122
|
+
|
123
|
+
if data not in available_data:
|
124
|
+
print("The provided data is not available")
|
125
|
+
exit(1)
|
126
|
+
|
127
|
+
simulation_id, _ = build_simulation_id(name)
|
128
|
+
|
129
|
+
print(
|
130
|
+
f"Running simulation with id: {simulation_id}, data: {data} and {f'max duration: {max_duration}' if max_duration is not None else 'no max duration'}{is_offline and ' in offline mode' or ''}"
|
131
|
+
)
|
132
|
+
|
133
|
+
stop_event = threading.Event()
|
134
|
+
input_listener_thread = threading.Thread(
|
135
|
+
target=set_event_on_input,
|
136
|
+
args=("stop the simulation", "q", stop_event),
|
137
|
+
name="InputListener",
|
138
|
+
# This is a daemon thread, so it will be
|
139
|
+
# automatically terminated when the main thread is terminated.
|
140
|
+
daemon=True,
|
141
|
+
)
|
142
|
+
|
143
|
+
input_listener_thread.start()
|
144
|
+
|
145
|
+
run_simulation(simulation_id, data, max_duration, stop_event, is_offline)
|
146
|
+
|
147
|
+
print("To run a simulation with the same configuration, use the following command:")
|
148
|
+
print(
|
149
|
+
f"python simulation.py --data {data}{f' --max-duration {max_duration}' if max_duration is not None else ''} --name {name}{f' --offline' if is_offline else ''}"
|
150
|
+
)
|
151
|
+
|
152
|
+
|
153
|
+
if __name__ == "__main__":
|
154
|
+
run_simulation_cli()
|