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 065caee9 authored by Ed Rogers's avatar Ed Rogers
Browse files

Add color change on freq finished

parent 44512c43
......@@ -61,11 +61,14 @@ class HearingTest:
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 = np.all(self.upper_bounds - self.lower_bounds < self.get_block_size()*1.2)
test_finished = np.all(self.finished_freqs())
self.check_for_not_heard(played_time)
return test_finished, freq, volume, played_time, next_sleep_time
def finished_freqs(self):
return self.upper_bounds - self.lower_bounds < self.get_block_size() * 1.2
def check_for_not_heard(self, event_time):
for sound in reversed(self.sounds):
delay = event_time - sound.time
......
......@@ -37,6 +37,9 @@ from matplotlib.figure import Figure
class HearingMplCanvas(FigureCanvas):
"""Ultimately, this is a QWidget (as well as a FigureCanvasAgg, etc.)."""
false_color = np.array([0., 1., 0.])
true_color = np.array([0., 0., 1.])
def __init__(self, parent=None, width=5, height=4, dpi=100):
self.baseline = -0.1
fig = Figure(figsize=(width, height), dpi=dpi)
......@@ -58,8 +61,10 @@ class HearingMplCanvas(FigureCanvas):
def plot_result(self, result: HearingTest):
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)
self.ul_bar = self.axes.bar(inds, result.upper_bounds - self.baseline,
color=0.5*self.false_color, bottom=self.baseline)
self.ll_bar = self.axes.bar(inds, result.lower_bounds - self.baseline,
color=self.false_color, 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')
......@@ -72,6 +77,7 @@ class HearingMplCanvas(FigureCanvas):
def update_result(self, result: HearingTest) -> None:
self.set_bar_heights(self.ul_bar, result.upper_bounds-self.baseline)
self.set_bar_heights(self.ll_bar, result.lower_bounds-self.baseline)
self.set_bar_colors([self.ul_bar, self.ll_bar], result.finished_freqs())
self.draw()
@staticmethod
......@@ -79,6 +85,16 @@ class HearingMplCanvas(FigureCanvas):
for bar, h in zip(bars, vals):
bar.set_height(h)
@staticmethod
def set_bar_colors(bars, finished):
depth = [0.5, 1]
for i, bar_line in enumerate(bars):
for bar, f in zip(bar_line, finished):
if f:
bar.set_facecolor(depth[i] * HearingMplCanvas.true_color)
else:
bar.set_facecolor(depth[i] * HearingMplCanvas.false_color)
# TODO add animation
......
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