Skip to content
Permalink
Browse files

Added support for switching course layouts

  • Loading branch information...
dpoulson committed Aug 14, 2019
1 parent 6388ade commit cd7b19e16ff1c50490b2dbd8aac8ee889621bee7
Showing with 90 additions and 6 deletions.
  1. +12 −4 database.py
  2. 0 {course → db}/config.csv
  3. +19 −0 main.py
  4. +7 −0 static/main.css
  5. +45 −2 templates/admin.html
  6. +7 −0 templates/scoreboard.html
@@ -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]
File renamed without changes.
19 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/<did>', 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/<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':
@@ -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;
@@ -8,10 +8,40 @@
<script type="text/javascript" src="{{ url_for('static',filename='jquery-1.4.2.min.js') }}"></script>
<script type="text/javascript" src="{{ url_for('static',filename='socket.io.min.js') }}"></script>
<script type="text/javascript" charset="utf-8">
function register(api) {
var xhttp = new XMLHttpRequest();
var base_url = window.location.protocol + "//" + window.location.hostname + ":" + window.location.port;
var call_url = base_url + api;
console.log(call_url);
xhttp.open("GET", call_url, true);
xhttp.send();
}
$(document).ready(function() {
namespace = '/comms';
reload_course_types();
var socket = io.connect(location.protocol + '//' + document.domain + ':' + location.port + namespace);
function reload_course_types() {
$.getJSON("/display/course_types",
function (json) {
var tbody;
var rows = json.length;
tbody = "";
for (var i = 0; i < rows; i++) {
var course = json[i];
tbody += "<tr>";
tbody += "<td>" + course + "</td>";
tbody += "<td><input type=button value=Select onclick=\"register('/admin/change_course/" + course + "')\"></td>";
tbody += "</tr>";
}
$('#course_types_body').empty().append(tbody);
});
}
// Display log messages at the bottom of the screen
socket.on('my_response', function(msg) {
$('.logs').append('<br>' + $('<div/>').text('Log # ' + msg.data).html());
@@ -21,6 +51,8 @@
</script>
</head>
<body>
<div class="admin-container">
<div class="admin-menu">
<h1>Admin options</h1>
<ul>
<li><a href="/contenders">List (and register) contenders</a></li>
@@ -32,8 +64,19 @@ <h1>Admin options</h1>
<li><a href="/admin/connected">List connected devices</a></li>
<li><a href="/run/RESET">Reset run</a></li>
</ul>
<div>
<div class="logs"></div>
</div>
<div class="admin-config">
<h2>Config Settings</h2>
<table class="results_table">
<thead>
<tr><th>Course Type</th><th></th></tr>
</thead>
<tbody id="course_types_body">
</tbody>
</table>

</div>
<div class="logs"></div>
</div>
</body>
</html>
@@ -12,6 +12,7 @@
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
var num_gates = 0;
function display_gates() {
$.getJSON("/display/list_gates",
function (json) {
var gates = document.getElementById('gates');
@@ -24,9 +25,11 @@
}
gates.innerHTML = gates_text;
});
}
namespace = '/comms';
display_gates();
reload_contender();
reload_current();
reload_gates();
@@ -171,6 +174,10 @@
reload_results();
});
socket.on('course_change', function(msg) {
display_gates();
});
// Do special display
socket.on('special_display', function(msg) {
document.body.style.backgroundColor = "black";

0 comments on commit cd7b19e

Please sign in to comment.
You can’t perform that action at this time.