Administrator approval is now required for registering new accounts. If you are registering a new account, and are external to the University, please ask the repository owner to contact ServiceLine to request your account be approved. Repository owners must include the newly registered email address, and specific repository in the request for approval.

Commit 0540cc2f authored by Ed Rogers's avatar Ed Rogers
Browse files

Rename bands to freqs and randomise sleep time

parent bcc24f38
......@@ -25,21 +25,22 @@ class HearingTest:
def __init__(self, library: SoundLibrary, canvas):
self.library = library
self.lower_bounds = np.full_like(self.bands, fill_value=self.lower_lim, dtype=float)
self.upper_bounds = np.full_like(self.bands, fill_value=self.upper_lim, dtype=float)
self.lower_bounds = np.full_like(self.freqs, fill_value=self.lower_lim, dtype=float)
self.upper_bounds = np.full_like(self.freqs, fill_value=self.upper_lim, dtype=float)
self.false_presses = 0
self.sounds = []
self.canvas = canvas
@property
def bands(self):
def freqs(self):
return self.library.freqs
def handle_key_press(self, _time):
recent_sound = self.sounds[-1]
if not recent_sound.heard and (_time - recent_sound.time <= self.max_response_time):
recent_sound.heard = True
self.set_lower_bound(recent_sound.freq, recent_sound.volume)
sound = self.sounds[-1]
if not sound.heard and (_time - sound.time <= self.max_response_time):
sound.heard = True
if self.lower_bounds[self.freqs == sound.freq] < sound.volume:
self.set_lower_bound(sound.freq, sound.volume)
else:
self.false_presses += 1
self.check_for_not_heard(_time)
......@@ -48,12 +49,11 @@ class HearingTest:
def play_next_sound(self):
# TODO select tone based on results
volume = random.random()
freq = random.choice(self.bands)
freq = random.choice(self.freqs)
self.library.play(freq, volume)
played_time = time.time()
# TODO randomise time
next_sleep_time = 1
next_sleep_time = random.uniform(self.max_response_time*1.2, self.max_response_time*3)
self.sounds.append(SoundRecord(freq, volume, played_time))
test_finished = False
......@@ -64,17 +64,18 @@ class HearingTest:
def check_for_not_heard(self, event_time):
for sound in reversed(self.sounds):
delay = event_time - sound.time
print(delay)
# print(delay)
if sound.heard is not None:
break
elif delay > self.max_response_time:
sound.heard = False
self.set_upper_bound(sound.freq, sound.volume)
if self.upper_bounds[self.freqs == sound.freq] > sound.volume:
self.set_upper_bound(sound.freq, sound.volume)
def set_lower_bound(self, band, volume):
self.lower_bounds[self.bands == band] = volume
def set_lower_bound(self, freq, volume):
self.lower_bounds[self.freqs == freq] = volume
self.canvas.update_result(self)
def set_upper_bound(self, band, volume):
self.upper_bounds[self.bands == band] = volume
def set_upper_bound(self, freq, volume):
self.upper_bounds[self.freqs == freq] = volume
self.canvas.update_result(self)
......@@ -56,14 +56,14 @@ class HearingMplCanvas(FigureCanvas):
self.plot_result(HearingTest(parent.library, self))
def plot_result(self, result: HearingTest):
inds = np.arange(0, result.bands.size)
inds = np.arange(0, result.freqs.size)
self.axes.set_facecolor('k')
self.ul_bar = self.axes.bar(inds, result.upper_bounds - self.baseline, color=(0, 0.5, 0), bottom=self.baseline)
self.ll_bar = self.axes.bar(inds, result.lower_bounds - self.baseline, color=(0, 1, 0), bottom=self.baseline)
xlim = self.axes.get_xlim()
for i in np.arange(result.lower_lim + self.baseline, result.upper_lim, result.get_block_size()):
self.axes.plot(self.axes.get_xlim(), np.ones(2)*i, color='k')
labels = [str(b) for b in result.bands]
labels = [str(b) for b in result.freqs]
labels.insert(0, '')
self.axes.set_xticklabels(labels)
self.axes.set_ylim(self.baseline, result.upper_lim - self.baseline)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment