Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
H
HearingTest
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ed Rogers
HearingTest
Commits
0540cc2f
Commit
0540cc2f
authored
7 years ago
by
Ed Rogers
Browse files
Options
Downloads
Patches
Plain Diff
Rename bands to freqs and randomise sleep time
parent
bcc24f38
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
HearingTest.py
+17
-16
17 additions, 16 deletions
HearingTest.py
HearingTestGUI.py
+2
-2
2 additions, 2 deletions
HearingTestGUI.py
with
19 additions
and
18 deletions
HearingTest.py
+
17
−
16
View file @
0540cc2f
...
@@ -25,21 +25,22 @@ class HearingTest:
...
@@ -25,21 +25,22 @@ class HearingTest:
def
__init__
(
self
,
library
:
SoundLibrary
,
canvas
):
def
__init__
(
self
,
library
:
SoundLibrary
,
canvas
):
self
.
library
=
library
self
.
library
=
library
self
.
lower_bounds
=
np
.
full_like
(
self
.
band
s
,
fill_value
=
self
.
lower_lim
,
dtype
=
float
)
self
.
lower_bounds
=
np
.
full_like
(
self
.
freq
s
,
fill_value
=
self
.
lower_lim
,
dtype
=
float
)
self
.
upper_bounds
=
np
.
full_like
(
self
.
band
s
,
fill_value
=
self
.
upper_lim
,
dtype
=
float
)
self
.
upper_bounds
=
np
.
full_like
(
self
.
freq
s
,
fill_value
=
self
.
upper_lim
,
dtype
=
float
)
self
.
false_presses
=
0
self
.
false_presses
=
0
self
.
sounds
=
[]
self
.
sounds
=
[]
self
.
canvas
=
canvas
self
.
canvas
=
canvas
@property
@property
def
band
s
(
self
):
def
freq
s
(
self
):
return
self
.
library
.
freqs
return
self
.
library
.
freqs
def
handle_key_press
(
self
,
_time
):
def
handle_key_press
(
self
,
_time
):
recent_sound
=
self
.
sounds
[
-
1
]
sound
=
self
.
sounds
[
-
1
]
if
not
recent_sound
.
heard
and
(
_time
-
recent_sound
.
time
<=
self
.
max_response_time
):
if
not
sound
.
heard
and
(
_time
-
sound
.
time
<=
self
.
max_response_time
):
recent_sound
.
heard
=
True
sound
.
heard
=
True
self
.
set_lower_bound
(
recent_sound
.
freq
,
recent_sound
.
volume
)
if
self
.
lower_bounds
[
self
.
freqs
==
sound
.
freq
]
<
sound
.
volume
:
self
.
set_lower_bound
(
sound
.
freq
,
sound
.
volume
)
else
:
else
:
self
.
false_presses
+=
1
self
.
false_presses
+=
1
self
.
check_for_not_heard
(
_time
)
self
.
check_for_not_heard
(
_time
)
...
@@ -48,12 +49,11 @@ class HearingTest:
...
@@ -48,12 +49,11 @@ class HearingTest:
def
play_next_sound
(
self
):
def
play_next_sound
(
self
):
# TODO select tone based on results
# TODO select tone based on results
volume
=
random
.
random
()
volume
=
random
.
random
()
freq
=
random
.
choice
(
self
.
band
s
)
freq
=
random
.
choice
(
self
.
freq
s
)
self
.
library
.
play
(
freq
,
volume
)
self
.
library
.
play
(
freq
,
volume
)
played_time
=
time
.
time
()
played_time
=
time
.
time
()
# TODO randomise time
next_sleep_time
=
random
.
uniform
(
self
.
max_response_time
*
1.2
,
self
.
max_response_time
*
3
)
next_sleep_time
=
1
self
.
sounds
.
append
(
SoundRecord
(
freq
,
volume
,
played_time
))
self
.
sounds
.
append
(
SoundRecord
(
freq
,
volume
,
played_time
))
test_finished
=
False
test_finished
=
False
...
@@ -64,17 +64,18 @@ class HearingTest:
...
@@ -64,17 +64,18 @@ class HearingTest:
def
check_for_not_heard
(
self
,
event_time
):
def
check_for_not_heard
(
self
,
event_time
):
for
sound
in
reversed
(
self
.
sounds
):
for
sound
in
reversed
(
self
.
sounds
):
delay
=
event_time
-
sound
.
time
delay
=
event_time
-
sound
.
time
print
(
delay
)
#
print(delay)
if
sound
.
heard
is
not
None
:
if
sound
.
heard
is
not
None
:
break
break
elif
delay
>
self
.
max_response_time
:
elif
delay
>
self
.
max_response_time
:
sound
.
heard
=
False
sound
.
heard
=
False
if
self
.
upper_bounds
[
self
.
freqs
==
sound
.
freq
]
>
sound
.
volume
:
self
.
set_upper_bound
(
sound
.
freq
,
sound
.
volume
)
self
.
set_upper_bound
(
sound
.
freq
,
sound
.
volume
)
def
set_lower_bound
(
self
,
band
,
volume
):
def
set_lower_bound
(
self
,
freq
,
volume
):
self
.
lower_bounds
[
self
.
band
s
==
band
]
=
volume
self
.
lower_bounds
[
self
.
freq
s
==
freq
]
=
volume
self
.
canvas
.
update_result
(
self
)
self
.
canvas
.
update_result
(
self
)
def
set_upper_bound
(
self
,
band
,
volume
):
def
set_upper_bound
(
self
,
freq
,
volume
):
self
.
upper_bounds
[
self
.
band
s
==
band
]
=
volume
self
.
upper_bounds
[
self
.
freq
s
==
freq
]
=
volume
self
.
canvas
.
update_result
(
self
)
self
.
canvas
.
update_result
(
self
)
This diff is collapsed.
Click to expand it.
HearingTestGUI.py
+
2
−
2
View file @
0540cc2f
...
@@ -56,14 +56,14 @@ class HearingMplCanvas(FigureCanvas):
...
@@ -56,14 +56,14 @@ class HearingMplCanvas(FigureCanvas):
self
.
plot_result
(
HearingTest
(
parent
.
library
,
self
))
self
.
plot_result
(
HearingTest
(
parent
.
library
,
self
))
def
plot_result
(
self
,
result
:
HearingTest
):
def
plot_result
(
self
,
result
:
HearingTest
):
inds
=
np
.
arange
(
0
,
result
.
band
s
.
size
)
inds
=
np
.
arange
(
0
,
result
.
freq
s
.
size
)
self
.
axes
.
set_facecolor
(
'
k
'
)
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
.
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
.
ll_bar
=
self
.
axes
.
bar
(
inds
,
result
.
lower_bounds
-
self
.
baseline
,
color
=
(
0
,
1
,
0
),
bottom
=
self
.
baseline
)
xlim
=
self
.
axes
.
get_xlim
()
xlim
=
self
.
axes
.
get_xlim
()
for
i
in
np
.
arange
(
result
.
lower_lim
+
self
.
baseline
,
result
.
upper_lim
,
result
.
get_block_size
()):
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
'
)
self
.
axes
.
plot
(
self
.
axes
.
get_xlim
(),
np
.
ones
(
2
)
*
i
,
color
=
'
k
'
)
labels
=
[
str
(
b
)
for
b
in
result
.
band
s
]
labels
=
[
str
(
b
)
for
b
in
result
.
freq
s
]
labels
.
insert
(
0
,
''
)
labels
.
insert
(
0
,
''
)
self
.
axes
.
set_xticklabels
(
labels
)
self
.
axes
.
set_xticklabels
(
labels
)
self
.
axes
.
set_ylim
(
self
.
baseline
,
result
.
upper_lim
-
self
.
baseline
)
self
.
axes
.
set_ylim
(
self
.
baseline
,
result
.
upper_lim
-
self
.
baseline
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment