From bb2093ca2c7a7dd7da640e427cace74125c1bfd3 Mon Sep 17 00:00:00 2001 From: Chris Davoren Date: Fri, 20 Oct 2023 19:41:31 +1000 Subject: [PATCH] Added period verbose name for presentation purposes. --- periods.json | 5 +++++ simulation/simulation_thread.py | 8 +++++++- .../templates/trafficlightfrontend/index.html | 4 +--- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/periods.json b/periods.json index 6d10cad..50d0347 100644 --- a/periods.json +++ b/periods.json @@ -1,6 +1,7 @@ [ { "name" : "offpeak-morning", + "verbose-name" : "Morning off-peak", "timestart" : "00:00", "states" : [ { "duration" : 20, "north" : "green", "south" : "green", "east" : "red", "west" : "red", "north-right" : "red" }, @@ -16,6 +17,7 @@ }, { "name" : "peak-morning", + "verbose-name" : "Morning peak", "timestart" : "08:00", "states" : [ { "duration" : 40, "north" : "green", "south" : "green", "east" : "red", "west" : "red", "north-right" : "red" }, @@ -31,6 +33,7 @@ }, { "name" : "offpeak-middle", + "verbose-name" : "Middle off-peak", "timestart" : "10:00", "states" : [ { "duration" : 20, "north" : "green", "south" : "green", "east" : "red", "west" : "red", "north-right" : "red" }, @@ -46,6 +49,7 @@ }, { "name" : "peak-afternoon", + "verbose-name" : "Afternoon peak", "timestart" : "17:00", "states" : [ { "duration" : 40, "north" : "green", "south" : "green", "east" : "red", "west" : "red", "north-right" : "red" }, @@ -61,6 +65,7 @@ }, { "name" : "offpeak-evening", + "verbose-name" : "Evening off-peak", "timestart" : "19:00", "states" : [ { "duration" : 20, "north" : "green", "south" : "green", "east" : "red", "west" : "red", "north-right" : "red" }, diff --git a/simulation/simulation_thread.py b/simulation/simulation_thread.py index 59f1dfb..6633597 100644 --- a/simulation/simulation_thread.py +++ b/simulation/simulation_thread.py @@ -54,7 +54,13 @@ class SimulationThread(threading.Thread): def get_snapshot(self): self.mutex.acquire() - return_data = {"current_period": self.periods[self.current_period_index]["name"], "current_state": self.periods[self.current_period_index]["states"][self.current_state_index], "next_changeover_time": self.next_changeover_time, "simulation_time": self.current_simulation_datetime.time()} + return_data = { + "current_period_name": self.periods[self.current_period_index]["name"], + "current_period_verbose_name": self.periods[self.current_period_index]["verbose-name"], + "current_state": self.periods[self.current_period_index]["states"][self.current_state_index], + "next_changeover_time": self.next_changeover_time, + "simulation_time": self.current_simulation_datetime.time(), + } self.mutex.release() return return_data diff --git a/trafficlightfrontend/templates/trafficlightfrontend/index.html b/trafficlightfrontend/templates/trafficlightfrontend/index.html index 6870e86..10278e4 100644 --- a/trafficlightfrontend/templates/trafficlightfrontend/index.html +++ b/trafficlightfrontend/templates/trafficlightfrontend/index.html @@ -73,12 +73,10 @@ return; } light_status = JSON.parse(this.responseText); - // console.log(light_status); - // console.log(light_status.current_period); let static_path_prefix = "/static/trafficlightfrontend/"; document.getElementById("status").innerHTML = JSON.stringify(light_status.current_state); - document.getElementById("period").innerHTML = light_status.current_period; + document.getElementById("period").innerHTML = light_status.current_period_verbose_name; document.getElementById("time").innerHTML = light_status.simulation_time; document.getElementById("north").style.backgroundImage = "url(" + static_path_prefix + light_status.current_state.north + ".png)";