From cd7b19e16ff1c50490b2dbd8aac8ee889621bee7 Mon Sep 17 00:00:00 2001 From: Darren Poulson Date: Wed, 14 Aug 2019 01:45:57 +0100 Subject: [PATCH] Added support for switching course layouts --- database.py | 16 +++++++++---- {course => db}/config.csv | 0 main.py | 19 ++++++++++++++++ static/main.css | 7 ++++++ templates/admin.html | 47 +++++++++++++++++++++++++++++++++++++-- templates/scoreboard.html | 7 ++++++ 6 files changed, 90 insertions(+), 6 deletions(-) rename {course => db}/config.csv (100%) diff --git a/database.py b/database.py index 50eaf79..5166493 100644 --- a/database.py +++ b/database.py @@ -38,7 +38,8 @@ first_half_time integer NULL, second_half_time integer NULL, clock_time integer NULL, - final_time integer NULL + final_time integer NULL, + type text NULL ); """ sql_create_penalties_table = """ CREATE TABLE IF NOT EXISTS penalties ( @@ -66,13 +67,13 @@ def db_init(): # Best load initial config values: if __debug__: print("Loading initial config values to course table") - with open ('course/config.csv', 'rt') as fin: + with open ('db/config.csv', 'rt') as fin: dr = csv.DictReader(fin) to_db = [(i['config_name'], i['config_value']) for i in dr] c = conn.cursor() c.executemany("INSERT INTO course (config_name, config_value) VALUES (?, ?);", to_db) conn.commit() - load_gates("course/" + get_config('course_type') + "/sensors.csv") + load_gates() else: print("Error!") @@ -95,8 +96,15 @@ def get_config(setting): else: return row[0] -def load_gates(gates_csv): +def set_config(setting, value): + conn = create_connection(db_location) + execute_sql(conn, "UPDATE course SET config_value=\"" + value + "\" WHERE config_name=\"" + setting + "\";") + return + + +def load_gates(): """ Load gate config """ + gates_csv = "course/" + get_config('course_type') + "/sensors.csv" with open (gates_csv, 'rt') as fin: dr = csv.DictReader(fin) to_db = [(i['id'], i['type'], i['name'], i['penalty']) for i in dr] diff --git a/course/config.csv b/db/config.csv similarity index 100% rename from course/config.csv rename to db/config.csv diff --git a/main.py b/main.py index 3a86cdd..dce4053 100755 --- a/main.py +++ b/main.py @@ -34,6 +34,10 @@ audio = audio.AudioLibrary("sounds", 1) +def course_types(): + subdirs = os.listdir("course") + return json.dumps(subdirs) + @app.route('/') def index(): """GET to generate a list of endpoints and their docstrings""" @@ -90,6 +94,8 @@ def display(cmd): return database.list_droids() if cmd == 'members': return database.list_members() + if cmd == 'course_types': + return course_types() return "Ok" @app.route('/droid/', methods=['GET']) @@ -154,6 +160,7 @@ def run_cmd(cmd, milliseconds): current_run = database.run(0, cmd, current_member.member_uid, current_droid.droid_uid, 0) socketio.emit('my_response', {'data': 'Start Run'}, namespace='/comms') socketio.emit('reload_current', {'data': 'reload current'}, namespace='/comms') + audio.TriggerSound("air_horn") current_state = 1 if cmd == 'MIDDLE_WAIT' and current_state == 1: database.run(current_run, cmd, current_member.member_uid, current_droid.droid_uid, milliseconds) @@ -217,6 +224,18 @@ def clear_db(): socketio.emit('reload_results', {'data': 'reload results'}, namespace='/comms') return "Ok" +@app.route('/admin/change_course/', methods=['GET']) +def change_course(course): + if request.method == 'GET': + database.set_config("course_type", course) + database.load_gates() + socketio.emit('my_response', {'data': '**ADMIN** Changing Course Type'}, namespace='/comms') + socketio.emit('reload_results', {'data': 'reload results'}, namespace='/comms') + socketio.emit('reload_gates', {'data': 'reload current'}, namespace='/comms') + socketio.emit('course_change', {'data': 'course change'}, namespace='/comms') + return "Ok" + + @app.route('/admin/refresh/members', methods=['GET']) def refresh_members(): if request.method == 'GET': diff --git a/static/main.css b/static/main.css index 954c602..4a09b7e 100644 --- a/static/main.css +++ b/static/main.css @@ -73,6 +73,13 @@ table.contender_table th { grid-template-areas: "logo contender" "current gates-container" "results results" "logs logs"; } +.admin-container { + display: grid; + grid-template-columns: 900px auto; + grid-template-rows: auto 75px; + grid-template-areas: "admin-menu admin-config" "logs logs"; +} + .gates-container { display: grid; max-width: 1000px; diff --git a/templates/admin.html b/templates/admin.html index a6093d9..c4b9811 100644 --- a/templates/admin.html +++ b/templates/admin.html @@ -8,10 +8,40 @@ +
+

Admin options

-
-
+
+
+

Config Settings

+ + + + + + +
Course Type
+ +
+
diff --git a/templates/scoreboard.html b/templates/scoreboard.html index 01b3d43..efaf3ce 100644 --- a/templates/scoreboard.html +++ b/templates/scoreboard.html @@ -12,6 +12,7 @@