Updated participant generation script for better display of info
This commit is contained in:
+36
-2
@@ -11,6 +11,12 @@ random.seed(42)
|
||||
np.random.seed(42)
|
||||
import itertools
|
||||
import copy
|
||||
import logging
|
||||
from loggerops import create_logger, log_newline
|
||||
import textwrap
|
||||
import re
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
from config import server, socketio, participants
|
||||
|
||||
@@ -150,7 +156,7 @@ def roll_independant(A, r):
|
||||
def main():
|
||||
'''
|
||||
'''
|
||||
print("***REMEMBER THIS SCRIPTS WILL NOT OVERWRITE ANY EXISTING PARTICIPANT DATA. PLEASE DELETE THIS MANUALLY IF NEEDED!***")
|
||||
logger.warning("***REMEMBER THIS SCRIPTS WILL NOT OVERWRITE ANY EXISTING PARTICIPANT DATA. PLEASE DELETE THIS MANUALLY IF NEEDED!***")
|
||||
participants = find_participants()
|
||||
with open('./test_params.json') as json_file:
|
||||
general_params = json.load(json_file)
|
||||
@@ -193,6 +199,13 @@ def main():
|
||||
participant_params['hl_sim_active'] = hl_sim_active
|
||||
# What order are the decoder stories presented?
|
||||
# What order are the behavioral test stimuli presented?
|
||||
participant_params['behavioral_train_lists'] = np.random.choice(
|
||||
general_params['behavioral_train_lists'],
|
||||
[general_params['behavioral_train_N']], replace=False)
|
||||
participant_params['behavioral_test_lists'] = np.random.choice(
|
||||
general_params['behavioral_test_lists'],
|
||||
[general_params['behavioral_test_N']], replace=False)
|
||||
|
||||
# What order are the tone SNRs presented at?
|
||||
n_tone_repeats = general_params['tone_repeats']
|
||||
tone_snrs = np.array(general_params['tone_SNRs'], dtype=float)
|
||||
@@ -208,12 +221,33 @@ def main():
|
||||
|
||||
|
||||
key = "participant_{}".format(i)
|
||||
print(f"Generating: {key}")
|
||||
logger.info("{:<78}".format(f"Generating: {key}"))
|
||||
participants[key] = Participant(participant_dir="./participant_data/{}".format(key), number=i, parameters=participant_params)
|
||||
participants[key].save("info")
|
||||
for key, val in participants[key].parameters.items():
|
||||
if type(val) is np.ndarray:
|
||||
val = val.tolist()
|
||||
trunc_str = re.sub(r'^(.{75}).*$', '\g<1>...', f"{key:<25}{val}")
|
||||
logger.info(f"{trunc_str: <78}")
|
||||
logger.info("-"*78)
|
||||
|
||||
print(f"Generated {part_nums.size} new participant databases")
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import shutil
|
||||
import os
|
||||
from pathlib import Path
|
||||
from datetime import datetime
|
||||
logs_dir = Path('./logs/')
|
||||
logs_dir.mkdir(exist_ok=True)
|
||||
logfile_dir = logs_dir / __file__
|
||||
logfile_dir.mkdir(exist_ok=True)
|
||||
logfile_name = datetime.now().strftime("%m-%d-%Y_%H-%M-%S")+'.log'
|
||||
logger = create_logger(
|
||||
logger_streamlevel=10,
|
||||
log_filename=str(logfile_dir/logfile_name),
|
||||
logger_filelevel=10
|
||||
)
|
||||
main()
|
||||
|
||||
@@ -7,6 +7,7 @@ from time import sleep
|
||||
from server import run_server
|
||||
import config
|
||||
from threading import Thread, Lock
|
||||
from loggerops import create_logger
|
||||
|
||||
socketio = config.socketio
|
||||
|
||||
@@ -28,7 +29,7 @@ def url_ok(url, port):
|
||||
r = conn.getresponse()
|
||||
return r.status == 200
|
||||
except:
|
||||
logger.exception("Server not started")
|
||||
logger.error("Server not started")
|
||||
return False
|
||||
|
||||
def create_new_window():
|
||||
@@ -38,6 +39,15 @@ def create_new_window():
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
logger = create_logger(
|
||||
logger_streamlevel=10,
|
||||
log_filename='./logs/main.log',
|
||||
logger_filelevel=10
|
||||
)
|
||||
log = logging.getLogger('werkzeug')
|
||||
log.setLevel(logging.ERROR)
|
||||
log = logging.getLogger('engineio')
|
||||
log.setLevel(logging.ERROR)
|
||||
logger.debug("Starting server")
|
||||
# Run server in seperate thread
|
||||
# socketio.start_background_task(run_server)
|
||||
|
||||
+25
-4
@@ -9,6 +9,9 @@ import random
|
||||
from scipy.optimize import minimize
|
||||
import csv
|
||||
from shutil import copy2
|
||||
import sys
|
||||
import traceback
|
||||
from loggerops import log_exceptions
|
||||
|
||||
from pysndfile import sndio, PySndfile
|
||||
from matrix_test.helper_modules.filesystem import globDir
|
||||
@@ -18,6 +21,9 @@ import pdb
|
||||
|
||||
from config import socketio
|
||||
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def run_matrix_thread(listN=3, sessionFilepath=None, participant=None):
|
||||
global matThread
|
||||
@@ -60,6 +66,7 @@ class MatTestThread(BaseThread):
|
||||
'''
|
||||
Thread for running server side matrix test operations
|
||||
'''
|
||||
@log_exceptions
|
||||
def __init__(self, listN=5, sessionFilepath=None,
|
||||
noiseFilepath="./matrix_test/behavioural_stim/stimulus/wav/noise/noise_norm.wav",
|
||||
noiseRMSFilepath="./matrix_test/behavioural_stim/stimulus/rms/noise_rms.npy",
|
||||
@@ -67,12 +74,25 @@ class MatTestThread(BaseThread):
|
||||
red_coef="./calibration/out/reduction_coefficients/mat_red_coef.npy",
|
||||
cal_coef="./calibration/out/calibration_coefficients/mat_cal_coef.npy",
|
||||
track_targets=[0.2, 0.5, 0.8],
|
||||
mode='testing',
|
||||
socketio=None, participant=None):
|
||||
|
||||
self.listDir = listFolder
|
||||
self.participant = participant
|
||||
self.participant_parameters = self.participant.data['parameters']
|
||||
if mode == "familiarisation":
|
||||
self.inds = self.participant_parameters['behavioural_training_lists']
|
||||
logger.info("Running participant_{self.participant.data['number']}, familiarisation")
|
||||
elif mode == "testing":
|
||||
self.inds = self.participant_parameters['behavioural_test_lists']
|
||||
logger.info("Running participant_{self.participant.data['number']}, testing")
|
||||
else:
|
||||
raise ValueError(f"{mode} is not a valid mode value")
|
||||
|
||||
|
||||
self.adaptiveTracks = [AdaptiveTrack(x, red_coef, cal_coef) for x in track_targets]
|
||||
self.trackOrder = []
|
||||
track_targets = np.array(self.participant.data['parameters']['behavioural_track_targets'])/100.
|
||||
|
||||
|
||||
self.listN = int(listN)
|
||||
@@ -302,6 +322,7 @@ class MatTestThread(BaseThread):
|
||||
self.playStimulus(self.y, self.fs)
|
||||
|
||||
def loadStimulus(self):
|
||||
|
||||
# Get folder path of all lists in the list directory
|
||||
lists = next(os.walk(self.listDir))[1]
|
||||
lists.pop(lists.index("demo"))
|
||||
@@ -310,10 +331,9 @@ class MatTestThread(BaseThread):
|
||||
for i in sorted(pop, reverse=True):
|
||||
del lists[i]
|
||||
# Randomly select n lists
|
||||
inds = list(range(len(lists)))
|
||||
random.shuffle(inds)
|
||||
inds = self.inds
|
||||
# random.shuffle(inds)
|
||||
# Pick first n shuffled lists
|
||||
inds = inds[:self.listN]
|
||||
for ind in inds:
|
||||
# Get filepaths to the audiofiles and word csv file for the current
|
||||
# list
|
||||
@@ -336,7 +356,8 @@ class MatTestThread(BaseThread):
|
||||
self.listsString[-1].append(words)
|
||||
|
||||
# Number of trials to split between adaptive tracks
|
||||
n = len(self.lists[0])*self.listN
|
||||
n = len(self.lists[0])*len(inds)
|
||||
#Number of adaptive tracks active
|
||||
tn = len(self.adaptiveTracks)
|
||||
self.trackOrder = list(np.repeat(np.arange(tn), np.floor(n/tn)))
|
||||
random.shuffle(self.trackOrder)
|
||||
|
||||
@@ -11,6 +11,13 @@
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<select class="form-control" name="mode" id="mode">
|
||||
<option>Familiarisation</option>
|
||||
<option>Testing</option>
|
||||
<option>Testingssjks</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group d-flex justify-content-center">
|
||||
<button type="button" id="submit" class="btn btn-primary mx-3">Start new test</button>
|
||||
<button type="button" id="load-saved" class="btn btn-primary mx-3">Load saved session</button>
|
||||
@@ -33,7 +40,7 @@
|
||||
return false;
|
||||
})
|
||||
$('#submit').click(function(event) {
|
||||
socket.emit('start_test', {listN: $("#listN").val(), part_key: $("#participant").val(), test_name: "mat_test"});
|
||||
socket.emit('start_test', {part_key: $("#participant").val(), mode: $("#mode").val(), test_name: "mat_test"});
|
||||
return false;
|
||||
})
|
||||
|
||||
|
||||
+10
-2
@@ -8,6 +8,10 @@ from shutil import copy2
|
||||
from threading import Thread, Event
|
||||
from config import socketio
|
||||
|
||||
import sys
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
from WavPlayer import WavPlayer
|
||||
|
||||
def run_test_thread(name, thread_type, sessionFilepath=None, participant=None, **kwargs):
|
||||
@@ -15,7 +19,7 @@ def run_test_thread(name, thread_type, sessionFilepath=None, participant=None, *
|
||||
if thread_name in globals():
|
||||
thread = globals()[thread_name]
|
||||
if thread.isAlive() and isinstance(thread, thread_type):
|
||||
daTestThread.join()
|
||||
thread.join()
|
||||
thread = thread_type(socketio=socketio, sessionFilepath=sessionFilepath,
|
||||
participant=participant, **kwargs)
|
||||
thread.start()
|
||||
@@ -274,4 +278,8 @@ class BaseThread(Thread):
|
||||
'''
|
||||
This function is called when the thread starts
|
||||
'''
|
||||
return self.testLoop()
|
||||
try:
|
||||
return self.testLoop()
|
||||
except:
|
||||
e = sys.exc_info()[0]
|
||||
logger.exception(e)
|
||||
|
||||
Reference in New Issue
Block a user