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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ed Rogers
HearingTest
Commits
d1563291
Commit
d1563291
authored
7 years ago
by
Ed Rogers
Browse files
Options
Downloads
Patches
Plain Diff
Add saving of data to file
parent
07613564
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
HearingTest.py
+18
-9
18 additions, 9 deletions
HearingTest.py
HearingTestGUI.py
+11
-6
11 additions, 6 deletions
HearingTestGUI.py
with
29 additions
and
15 deletions
HearingTest.py
+
18
−
9
View file @
d1563291
...
...
@@ -2,8 +2,7 @@ import time
import
numpy
as
np
import
random
from
SoundLibrary
import
SoundLibrary
from
typing
import
List
# from HearingTestGUI import HearingMplCanvas
class
SoundRecord
:
def
__init__
(
self
,
freq
,
volume
,
time
):
...
...
@@ -52,22 +51,22 @@ class HearingTest:
for
i
,
freq
in
enumerate
(
self
.
freqs
):
choices
.
extend
([(
freq
,
v
)
for
v
in
np
.
arange
(
self
.
lower_bounds
[
i
],
self
.
upper_bounds
[
i
],
self
.
get_block_size
())])
freq
,
volume
=
random
.
choice
(
choices
)
self
.
library
.
play
(
freq
,
volume
)
played_time
=
time
.
time
()
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
.
finished_freqs
())
self
.
check_for_not_heard
(
played_time
)
return
test_finished
,
freq
,
volume
,
played_time
,
next_sleep_time
return
self
.
test_finished
,
freq
,
volume
,
played_time
,
next_sleep_time
@property
def
test_finished
(
self
):
return
np
.
all
(
self
.
finished_freqs
)
@property
def
finished_freqs
(
self
):
return
self
.
upper_bounds
-
self
.
lower_bounds
<
self
.
get_block_size
()
*
1.2
return
self
.
upper_bounds
-
self
.
lower_bounds
<
self
.
get_block_size
()
*
0.9
def
check_for_not_heard
(
self
,
event_time
):
for
sound
in
reversed
(
self
.
sounds
):
...
...
@@ -87,3 +86,13 @@ class HearingTest:
def
set_upper_bound
(
self
,
freq
,
volume
):
self
.
upper_bounds
[
self
.
freqs
==
freq
]
=
volume
self
.
canvas
.
update_result
(
self
)
@property
def
thresholds
(
self
)
->
np
.
ndarray
:
if
not
self
.
test_finished
:
raise
ValueError
return
mean_two_arrays
(
self
.
lower_bounds
,
self
.
upper_bounds
)
def
mean_two_arrays
(
a
:
np
.
ndarray
,
b
:
np
.
ndarray
):
return
np
.
mean
(
np
.
array
([
a
,
b
]),
axis
=
0
)
This diff is collapsed.
Click to expand it.
HearingTestGUI.py
+
11
−
6
View file @
d1563291
...
...
@@ -77,7 +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
.
set_bar_colors
([
self
.
ul_bar
,
self
.
ll_bar
],
result
.
finished_freqs
)
self
.
draw
()
@staticmethod
...
...
@@ -126,7 +126,7 @@ class TestWindow(QMainWindow):
def
__init__
(
self
,
library
):
self
.
library
=
library
self
.
r
es
ul
t
=
None
self
.
t
est
=
None
self
.
testing_thread
=
None
self
.
test_running
=
False
...
...
@@ -175,7 +175,7 @@ class TestWindow(QMainWindow):
if
event
.
key
()
==
Qt
.
Qt
.
Key_Escape
:
self
.
testing_thread
.
abort
=
True
key_press_time
=
time
.
time
()
self
.
r
es
ul
t
.
handle_key_press
(
key_press_time
)
self
.
t
est
.
handle_key_press
(
key_press_time
)
self
.
record_key_press
(
event
,
key_press_time
)
def
record_key_press
(
self
,
event
:
QtGui
.
QKeyEvent
,
_time
):
...
...
@@ -185,8 +185,8 @@ class TestWindow(QMainWindow):
self
.
log
.
setText
(
''
)
self
.
title
.
setText
(
'
Test running
'
)
self
.
log
.
append
(
'
Starting...
'
)
self
.
r
es
ul
t
=
HearingTest
(
self
.
library
,
self
.
graph
)
self
.
testing_thread
=
HearingTestThread
(
self
.
r
es
ul
t
)
self
.
t
est
=
HearingTest
(
self
.
library
,
self
.
graph
)
self
.
testing_thread
=
HearingTestThread
(
self
.
t
est
)
self
.
testing_thread
.
played_sound
.
connect
(
self
.
sound_played
)
self
.
testing_thread
.
finished
.
connect
(
self
.
test_finished
)
self
.
testing_thread
.
aborted
.
connect
(
self
.
aborted
)
...
...
@@ -203,10 +203,15 @@ class TestWindow(QMainWindow):
self
.
test_running
=
False
self
.
title
.
setText
(
"
Press any key to start...
"
)
self
.
log
.
append
(
"
Finished test
"
)
self
.
log
.
append
(
"
Writing test result to file
"
)
thresholds
=
self
.
test
.
thresholds
thresholds
=
thresholds
.
reshape
(
thresholds
.
shape
[
0
],
-
1
)
# convert to 2d
with
open
(
'
data.csv
'
,
'
ba
'
)
as
file
:
np
.
savetxt
(
file
,
thresholds
.
T
,
fmt
=
'
%.2f
'
,
delimiter
=
'
,
'
)
# TODO store test
# TODO calculate score
# TODO display test
self
.
r
es
ul
t
=
None
self
.
t
est
=
None
def
main
():
...
...
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