Moved initialization parameters to settings.

This commit is contained in:
Chris Davoren 2023-10-21 14:34:11 +10:00
parent dc36e151bb
commit d07c1eeb9c
2 changed files with 9 additions and 4 deletions

View File

@ -19,12 +19,12 @@ class TrafficlightfrontendConfig(AppConfig):
if TrafficlightfrontendConfig.initialized or os.environ.get("RUN_MAIN") is None: if TrafficlightfrontendConfig.initialized or os.environ.get("RUN_MAIN") is None:
return return
print("Traffic Light Frontend: initialization.") # print("Traffic Light Frontend: initialization.")
print("Current working directory: {}".format(os.getcwd())) # print("Current working directory: {}".format(os.getcwd()))
periods = json.load(open("periods.json")) periods = json.load(open(os.path.join(settings.BASE_DIR, settings.SIMULATION_DATA_FILE)))
SimulationThread.initialize(periods, start_time=datetime.time.fromisoformat("07:59"), time_factor=4.0) SimulationThread.initialize(periods, start_time=datetime.time.fromisoformat(settings.SIMULATION_START_TIME), time_factor=settings.SIMULATION_TIME_FACTOR)
SimulationThread.get_instance().start() SimulationThread.get_instance().start()
TrafficlightfrontendConfig.initialized = True TrafficlightfrontendConfig.initialized = True

View File

@ -122,3 +122,8 @@ STATIC_URL = 'static/'
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field # https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
# Simulation-specific settings
SIMULATION_DATA_FILE = 'periods.json'
SIMULATION_START_TIME = '07:59'
SIMULATION_TIME_FACTOR = 4.0