Implementing server side matrix test thread
This commit is contained in:
@@ -128,10 +128,79 @@ class StimGenThread(Thread):
|
||||
socketio.emit('processing-complete', {'data': ''}, namespace='/main')
|
||||
|
||||
|
||||
class MatTestThread(Thread):
|
||||
'''
|
||||
Thread for running server side matrix test operations
|
||||
'''
|
||||
def __init__(self, socketio):
|
||||
super(MatTestThread, self).__init__()
|
||||
self.newResp = False
|
||||
self.foundSRT = False
|
||||
self.pageLoaded = False
|
||||
self.response = ['','','','','']
|
||||
self.socketio = socketio
|
||||
self.socketio.on_event('submit_mat_response', self.submitMatResponse, namespace='/main')
|
||||
self.socketio.on_event('mat_page_loaded', self.setPageLoaded, namespace='/main')
|
||||
|
||||
def waitForResponse(self):
|
||||
while not self.newResp:
|
||||
time.sleep(0.75)
|
||||
return
|
||||
|
||||
def waitForPageLoad(self):
|
||||
while not self.pageLoaded:
|
||||
time.sleep(0.75)
|
||||
return
|
||||
|
||||
|
||||
def testLoop(self):
|
||||
'''
|
||||
An example process
|
||||
'''
|
||||
self.waitForPageLoad()
|
||||
while not self.foundSRT:
|
||||
self.playStimulus()
|
||||
self.waitForResponse()
|
||||
#socketio.emit('update-progress', {'data': '{}%'.format(percent)}, namespace='/main')
|
||||
|
||||
def playStimulus(self):
|
||||
self.newResp = False
|
||||
socketio.emit("mat_stim_playing", namespace="/main")
|
||||
print("Stim started...")
|
||||
time.sleep(7)
|
||||
socketio.emit("mat_stim_done", namespace="/main")
|
||||
print("stim played")
|
||||
|
||||
|
||||
def setPageLoaded(self):
|
||||
self.pageLoaded = True
|
||||
|
||||
|
||||
def submitMatResponse(self, msg):
|
||||
'''
|
||||
'''
|
||||
self.response = msg['resp']
|
||||
self.newResp = True
|
||||
|
||||
|
||||
def run(self):
|
||||
'''
|
||||
This function is called when the thread starts
|
||||
'''
|
||||
self.testLoop()
|
||||
socketio.emit('processing-complete', {'data': ''}, namespace='/main')
|
||||
|
||||
@socketio.on('start_mat_test', namespace='/main')
|
||||
def start_mat_test():
|
||||
'''
|
||||
Relay test start message to participant view
|
||||
'''
|
||||
socketio.emit('participant_start_mat', {'data': ''}, namespace='/main', broadcast=True)
|
||||
|
||||
global matThread
|
||||
thread = MatTestThread(socketio)
|
||||
thread.start()
|
||||
|
||||
@socketio.on('run_mat_stim_gen', namespace='/main')
|
||||
def generateStim(msg):
|
||||
'''
|
||||
@@ -148,11 +217,6 @@ def generateStim(msg):
|
||||
thread.start()
|
||||
|
||||
|
||||
@socketio.on('submit_mat_response', namespace='/main')
|
||||
def submitMatResponse(msg):
|
||||
'''
|
||||
'''
|
||||
pdb.set_trace()
|
||||
|
||||
@socketio.on('check-mat-processing-status', namespace='/main')
|
||||
def checkMatProcessingStatus():
|
||||
@@ -176,6 +240,7 @@ def openSaveDialog():
|
||||
# Send message with selected directory to the GUI
|
||||
socketio.emit('save-dialog-resp', {'data': directory}, namespace='/main')
|
||||
|
||||
|
||||
@socketio.on('open_mat_dialog', namespace='/main')
|
||||
def openMatDialog():
|
||||
# Open a file dialog interface for selecting a directory
|
||||
@@ -188,14 +253,17 @@ def openMatDialog():
|
||||
# Send message with selected directory to the GUI
|
||||
socketio.emit('mat-dialog-resp', {'data': directory}, namespace='/main')
|
||||
|
||||
|
||||
@server.route('/click_stim')
|
||||
def clickStim():
|
||||
return render_template("click_stim.html")
|
||||
|
||||
|
||||
@server.route('/da_stim')
|
||||
def daStim():
|
||||
return render_template("da_stim.html")
|
||||
|
||||
|
||||
def run_server():
|
||||
'''
|
||||
Start the Flask server
|
||||
|
||||
@@ -52,7 +52,6 @@
|
||||
socket.on('mat-processing-status', function(msg) {
|
||||
console.log(msg.data)
|
||||
if(msg.data) {
|
||||
// Update width of progress bar
|
||||
$('#main-div').find('input, textarea, button, select').attr('disabled','disabled');
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,69 +1,69 @@
|
||||
{% extends 'index.html' %}
|
||||
{% block content %}
|
||||
<div class="outer">
|
||||
<div id="main-div" class="outer">
|
||||
<div class="mat_grid">
|
||||
<button type="button" href="#" id="mat-0" class="Btn Btn-outline-secondary mat-button">Peter</button>
|
||||
<button type="button" href="#" id="mat-1" class="Btn Btn-outline-secondary mat-button">got</button>
|
||||
<button type="button" href="#" id="mat-2" class="Btn Btn-outline-secondary mat-button">three</button>
|
||||
<button type="button" href="#" id="mat-3" class="Btn Btn-outline-secondary mat-button">large</button>
|
||||
<button type="button" href="#" id="mat-4" class="Btn Btn-outline-secondary mat-button">desks</button>
|
||||
<button type="button" href="#" disabled id="mat-0" class="Btn Btn-outline-secondary mat-button">Peter</button>
|
||||
<button type="button" href="#" disabled id="mat-1" class="Btn Btn-outline-secondary mat-button">got</button>
|
||||
<button type="button" href="#" disabled id="mat-2" class="Btn Btn-outline-secondary mat-button">three</button>
|
||||
<button type="button" href="#" disabled id="mat-3" class="Btn Btn-outline-secondary mat-button">large</button>
|
||||
<button type="button" href="#" disabled id="mat-4" class="Btn Btn-outline-secondary mat-button">desks</button>
|
||||
|
||||
<button type="button" href="#" id="mat-0" class="Btn Btn-outline-secondary mat-button">Kathy</button>
|
||||
<button type="button" href="#" id="mat-1" class="Btn Btn-outline-secondary mat-button">sees</button>
|
||||
<button type="button" href="#" id="mat-2" class="Btn Btn-outline-secondary mat-button">nine</button>
|
||||
<button type="button" href="#" id="mat-3" class="Btn Btn-outline-secondary mat-button">small</button>
|
||||
<button type="button" href="#" id="mat-4" class="Btn Btn-outline-secondary mat-button">chairs</button>
|
||||
<button type="button" href="#" disabled id="mat-0" class="Btn Btn-outline-secondary mat-button">Kathy</button>
|
||||
<button type="button" href="#" disabled id="mat-1" class="Btn Btn-outline-secondary mat-button">sees</button>
|
||||
<button type="button" href="#" disabled id="mat-2" class="Btn Btn-outline-secondary mat-button">nine</button>
|
||||
<button type="button" href="#" disabled id="mat-3" class="Btn Btn-outline-secondary mat-button">small</button>
|
||||
<button type="button" href="#" disabled id="mat-4" class="Btn Btn-outline-secondary mat-button">chairs</button>
|
||||
|
||||
<button type="button" href="#" id="mat-0" class="Btn Btn-outline-secondary mat-button">Lucy</button>
|
||||
<button type="button" href="#" id="mat-1" class="Btn Btn-outline-secondary mat-button">bought</button>
|
||||
<button type="button" href="#" id="mat-2" class="Btn Btn-outline-secondary mat-button">five</button>
|
||||
<button type="button" href="#" id="mat-3" class="Btn Btn-outline-secondary mat-button">old</button>
|
||||
<button type="button" href="#" id="mat-4" class="Btn Btn-outline-secondary mat-button">shoes</button>
|
||||
<button type="button" href="#" disabled id="mat-0" class="Btn Btn-outline-secondary mat-button">Lucy</button>
|
||||
<button type="button" href="#" disabled id="mat-1" class="Btn Btn-outline-secondary mat-button">bought</button>
|
||||
<button type="button" href="#" disabled id="mat-2" class="Btn Btn-outline-secondary mat-button">five</button>
|
||||
<button type="button" href="#" disabled id="mat-3" class="Btn Btn-outline-secondary mat-button">old</button>
|
||||
<button type="button" href="#" disabled id="mat-4" class="Btn Btn-outline-secondary mat-button">shoes</button>
|
||||
|
||||
<button type="button" href="#" id="mat-0" class="Btn Btn-outline-secondary mat-button">Allan</button>
|
||||
<button type="button" href="#" id="mat-1" class="Btn Btn-outline-secondary mat-button">gives</button>
|
||||
<button type="button" href="#" id="mat-2" class="Btn Btn-outline-secondary mat-button">eight</button>
|
||||
<button type="button" href="#" id="mat-3" class="Btn Btn-outline-secondary mat-button">dark</button>
|
||||
<button type="button" href="#" id="mat-4" class="Btn Btn-outline-secondary mat-button">toys</button>
|
||||
<button type="button" href="#" disabled id="mat-0" class="Btn Btn-outline-secondary mat-button">Allan</button>
|
||||
<button type="button" href="#" disabled id="mat-1" class="Btn Btn-outline-secondary mat-button">gives</button>
|
||||
<button type="button" href="#" disabled id="mat-2" class="Btn Btn-outline-secondary mat-button">eight</button>
|
||||
<button type="button" href="#" disabled id="mat-3" class="Btn Btn-outline-secondary mat-button">dark</button>
|
||||
<button type="button" href="#" disabled id="mat-4" class="Btn Btn-outline-secondary mat-button">toys</button>
|
||||
|
||||
<button type="button" href="#" id="mat-0" class="Btn Btn-outline-secondary mat-button">Rachel</button>
|
||||
<button type="button" href="#" id="mat-1" class="Btn Btn-outline-secondary mat-button">sold</button>
|
||||
<button type="button" href="#" id="mat-2" class="Btn Btn-outline-secondary mat-button">four</button>
|
||||
<button type="button" href="#" id="mat-3" class="Btn Btn-outline-secondary mat-button">thin</button>
|
||||
<button type="button" href="#" id="mat-4" class="Btn Btn-outline-secondary mat-button">spoons</button>
|
||||
<button type="button" href="#" disabled id="mat-0" class="Btn Btn-outline-secondary mat-button">Rachel</button>
|
||||
<button type="button" href="#" disabled id="mat-1" class="Btn Btn-outline-secondary mat-button">sold</button>
|
||||
<button type="button" href="#" disabled id="mat-2" class="Btn Btn-outline-secondary mat-button">four</button>
|
||||
<button type="button" href="#" disabled id="mat-3" class="Btn Btn-outline-secondary mat-button">thin</button>
|
||||
<button type="button" href="#" disabled id="mat-4" class="Btn Btn-outline-secondary mat-button">spoons</button>
|
||||
|
||||
<button type="button" href="#" id="mat-0" class="Btn Btn-outline-secondary mat-button">Barry</button>
|
||||
<button type="button" href="#" id="mat-1" class="Btn Btn-outline-secondary mat-button">likes</button>
|
||||
<button type="button" href="#" id="mat-2" class="Btn Btn-outline-secondary mat-button">six</button>
|
||||
<button type="button" href="#" id="mat-3" class="Btn Btn-outline-secondary mat-button">green</button>
|
||||
<button type="button" href="#" id="mat-4" class="Btn Btn-outline-secondary mat-button">mugs</button>
|
||||
<button type="button" href="#" disabled id="mat-0" class="Btn Btn-outline-secondary mat-button">Barry</button>
|
||||
<button type="button" href="#" disabled id="mat-1" class="Btn Btn-outline-secondary mat-button">likes</button>
|
||||
<button type="button" href="#" disabled id="mat-2" class="Btn Btn-outline-secondary mat-button">six</button>
|
||||
<button type="button" href="#" disabled id="mat-3" class="Btn Btn-outline-secondary mat-button">green</button>
|
||||
<button type="button" href="#" disabled id="mat-4" class="Btn Btn-outline-secondary mat-button">mugs</button>
|
||||
|
||||
<button type="button" href="#" id="mat-0" class="Btn Btn-outline-secondary mat-button">Steven</button>
|
||||
<button type="button" href="#" id="mat-1" class="Btn Btn-outline-secondary mat-button">has</button>
|
||||
<button type="button" href="#" id="mat-2" class="Btn Btn-outline-secondary mat-button">two</button>
|
||||
<button type="button" href="#" id="mat-3" class="Btn Btn-outline-secondary mat-button">cheap</button>
|
||||
<button type="button" href="#" id="mat-4" class="Btn Btn-outline-secondary mat-button">ships</button>
|
||||
<button type="button" href="#" disabled id="mat-0" class="Btn Btn-outline-secondary mat-button">Steven</button>
|
||||
<button type="button" href="#" disabled id="mat-1" class="Btn Btn-outline-secondary mat-button">has</button>
|
||||
<button type="button" href="#" disabled id="mat-2" class="Btn Btn-outline-secondary mat-button">two</button>
|
||||
<button type="button" href="#" disabled id="mat-3" class="Btn Btn-outline-secondary mat-button">cheap</button>
|
||||
<button type="button" href="#" disabled id="mat-4" class="Btn Btn-outline-secondary mat-button">ships</button>
|
||||
|
||||
<button type="button" href="#" id="mat-0" class="Btn Btn-outline-secondary mat-button">Thomas</button>
|
||||
<button type="button" href="#" id="mat-1" class="Btn Btn-outline-secondary mat-button">kept</button>
|
||||
<button type="button" href="#" id="mat-2" class="Btn Btn-outline-secondary mat-button">ten</button>
|
||||
<button type="button" href="#" id="mat-3" class="Btn Btn-outline-secondary mat-button">pink</button>
|
||||
<button type="button" href="#" id="mat-4" class="Btn Btn-outline-secondary mat-button">rings</button>
|
||||
<button type="button" href="#" disabled id="mat-0" class="Btn Btn-outline-secondary mat-button">Thomas</button>
|
||||
<button type="button" href="#" disabled id="mat-1" class="Btn Btn-outline-secondary mat-button">kept</button>
|
||||
<button type="button" href="#" disabled id="mat-2" class="Btn Btn-outline-secondary mat-button">ten</button>
|
||||
<button type="button" href="#" disabled id="mat-3" class="Btn Btn-outline-secondary mat-button">pink</button>
|
||||
<button type="button" href="#" disabled id="mat-4" class="Btn Btn-outline-secondary mat-button">rings</button>
|
||||
|
||||
<button type="button" href="#" id="mat-0" class="Btn Btn-outline-secondary mat-button">Hannah</button>
|
||||
<button type="button" href="#" id="mat-1" class="Btn Btn-outline-secondary mat-button">wins</button>
|
||||
<button type="button" href="#" id="mat-2" class="Btn Btn-outline-secondary mat-button">twelve</button>
|
||||
<button type="button" href="#" id="mat-3" class="Btn Btn-outline-secondary mat-button">red</button>
|
||||
<button type="button" href="#" id="mat-4" class="Btn Btn-outline-secondary mat-button">tins</button>
|
||||
<button type="button" href="#" disabled id="mat-0" class="Btn Btn-outline-secondary mat-button">Hannah</button>
|
||||
<button type="button" href="#" disabled id="mat-1" class="Btn Btn-outline-secondary mat-button">wins</button>
|
||||
<button type="button" href="#" disabled id="mat-2" class="Btn Btn-outline-secondary mat-button">twelve</button>
|
||||
<button type="button" href="#" disabled id="mat-3" class="Btn Btn-outline-secondary mat-button">red</button>
|
||||
<button type="button" href="#" disabled id="mat-4" class="Btn Btn-outline-secondary mat-button">tins</button>
|
||||
|
||||
<button type="button" href="#" id="mat-0" class="Btn Btn-outline-secondary mat-button">Nina</button>
|
||||
<button type="button" href="#" id="mat-1" class="Btn Btn-outline-secondary mat-button">wants</button>
|
||||
<button type="button" href="#" id="mat-2" class="Btn Btn-outline-secondary mat-button">some</button>
|
||||
<button type="button" href="#" id="mat-3" class="Btn Btn-outline-secondary mat-button">big</button>
|
||||
<button type="button" href="#" id="mat-4" class="Btn Btn-outline-secondary mat-button">beds</button>
|
||||
<button type="button" href="#" disabled id="mat-0" class="Btn Btn-outline-secondary mat-button">Nina</button>
|
||||
<button type="button" href="#" disabled id="mat-1" class="Btn Btn-outline-secondary mat-button">wants</button>
|
||||
<button type="button" href="#" disabled id="mat-2" class="Btn Btn-outline-secondary mat-button">some</button>
|
||||
<button type="button" href="#" disabled id="mat-3" class="Btn Btn-outline-secondary mat-button">big</button>
|
||||
<button type="button" href="#" disabled id="mat-4" class="Btn Btn-outline-secondary mat-button">beds</button>
|
||||
</div>
|
||||
<div class="mat_submit">
|
||||
<button type="button" href="#" id="mat-submit" class="Btn Btn-primary">Submit</button>
|
||||
<button type="button" href="#" disabled id="mat-submit" class="Btn Btn-primary">Submit</button>
|
||||
</div>
|
||||
<script>
|
||||
|
||||
@@ -71,21 +71,14 @@
|
||||
// Initialise socketio with a namespace called "main"
|
||||
var socket = io.connect(location.protocol + '//' + document.domain + ':' + location.port + '/main');
|
||||
|
||||
socket.emit('mat_page_loaded');
|
||||
|
||||
var choice = Array(5).fill('');
|
||||
$('.mat-button').click(function(event) {
|
||||
choice[this.id.slice(-1)] = $(this).text();
|
||||
$('.mat-button#'+this.id).not(this).removeClass("active");
|
||||
$(this).toggleClass("active");
|
||||
console.log(choice);
|
||||
/*
|
||||
socket.emit('run_mat_stim_gen', {
|
||||
n_part: $("#n_part").val(),
|
||||
snr_len: $("#snr_len").val(),
|
||||
snr_num: $("#snr_num").val(),
|
||||
mat_dir: $("#mat-dir").val(),
|
||||
save_dir: $("#save-dir").val(),
|
||||
});
|
||||
*/
|
||||
return false;
|
||||
});
|
||||
|
||||
@@ -99,6 +92,15 @@
|
||||
resp: choice
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('mat_stim_playing', function(msg) {
|
||||
// Disable all inputs whilst processing
|
||||
$('#main-div').find('input, textarea, button, select').attr('disabled','disabled');
|
||||
});
|
||||
|
||||
socket.on('mat_stim_done', function(msg) {
|
||||
$('#main-div').find('input, textarea, button, select').removeAttr('disabled');
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user