From 784471ca6df223b3b90fe2bf09ad637cbe24ee4a Mon Sep 17 00:00:00 2001 From: atos Date: Sun, 15 Oct 2023 13:47:24 +0200 Subject: [PATCH 1/2] Documentation corrected and return changed by yield when stopIteration --- app/routes/simulation.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/app/routes/simulation.py b/app/routes/simulation.py index 5cdec16..cec6918 100644 --- a/app/routes/simulation.py +++ b/app/routes/simulation.py @@ -8,15 +8,9 @@ @simulation_blueprint.route("/simulation") -def start_simulation(HOST="localhost", PORT=999): +def start_simulation(): """ - TODO: Provide a more insightful description! - Start a simulation of the vehicle routing problem. This includes creating a server socket thread, - creating client socket processes, and emitting images from the vehicles to the client side. - - Parameters: - HOST (str, optional): Host of the server. Default is "localhost". - PORT (int, optional): Port number the server listens to. Default is 999. + Start a simulation of the vehicle routing problem. """ def stream(simulation, simulation_path): @@ -26,7 +20,7 @@ def stream(simulation, simulation_path): string_data = f"data: {json.dumps(coords)}\n\n" yield string_data except StopIteration: - return "data: None\n\n" + yield "data: None\n\n" current_app.simulation = True # Define simulation path From 9901062a88bea047e428aab203305ad0ec5d0535 Mon Sep 17 00:00:00 2001 From: atos Date: Sun, 15 Oct 2023 13:48:06 +0200 Subject: [PATCH 2/2] Catched the end of the simulation --- app/static/js/simulation.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/static/js/simulation.js b/app/static/js/simulation.js index dc0ee24..acf65a7 100644 --- a/app/static/js/simulation.js +++ b/app/static/js/simulation.js @@ -9,12 +9,11 @@ function startSimulation () { updatePoseMarkers(n_vehicles) eventSourcePose = new EventSource('/simulation') eventSourcePose.onmessage = function (event) { - const data = JSON.parse(event.data) - if (data === null) { - // TODO: SOLVE! - console.log(data) + if (event.data == 'None') { stopSimulation() + return } + const data = JSON.parse(event.data) for (let i = 0; i < data.length; i++) { ml = pose_markers[i].length if (ml >= 1) {