Skip to content

Commit

Permalink
cleanup / address PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
tab-cmd committed Oct 14, 2021
1 parent b0afbff commit c6c4c77
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 17 deletions.
5 changes: 3 additions & 2 deletions bcipy/display/rsvp/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ class PreviewInquiryProperties:

def __init__(
self,
preview_only: bool,
preview_inquiry_length: float,
preview_inquiry_progress_method: int,
preview_inquiry_key_input: str,
Expand All @@ -190,7 +191,7 @@ def __init__(
self.preview_inquiry_length = preview_inquiry_length
self.preview_inquiry_key_input = preview_inquiry_key_input
self.press_to_accept = True if preview_inquiry_progress_method == 1 else False
self.preview_only = True if preview_inquiry_progress_method == 0 else False
self.preview_only = preview_only
self.preview_inquiry_isi = preview_inquiry_isi


Expand Down Expand Up @@ -433,7 +434,7 @@ def preview_inquiry(self) -> Tuple[List[float], bool]:
clock=self.experiment_clock,
)

# break if a response given unless this is preview only and wait the timer out
# break if a response given unless this is preview only and wait the timer
if response and not self._preview_inquiry.preview_only:
break

Expand Down
2 changes: 2 additions & 0 deletions bcipy/display/tests/rsvp/test_rsvp_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def setUp(self):
self.preview_inquiry_progress_method = 1 # preview only = 0; press to accept == 1; press to skip == 2
self.preview_inquiry_key_input = 'space'
self.preview_inquiry = PreviewInquiryProperties(
preview_only=False,
preview_inquiry_length=self.preview_inquiry_length,
preview_inquiry_isi=self.preview_inquiry_isi,
preview_inquiry_progress_method=self.preview_inquiry_progress_method,
Expand Down Expand Up @@ -308,5 +309,6 @@ def test_preview_inquiry_preview_only_no_response(self, get_key_press_mock):
expected = ([None], True)
self.assertEqual(response, expected)


if __name__ == '__main__':
unittest.main()
34 changes: 23 additions & 11 deletions bcipy/task/paradigm/rsvp/copy_phrase.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,27 @@ def __init__(self, win, daq, parameters, file_save, signal_model,
self.experiment_clock = Clock()
self.start_time = self.experiment_clock.getTime()

self.alp = alphabet(parameters)
self.alp = alphabet(self.parameters)

self.button_press_error_prob = 0.05
self.evidence_types = [EvidenceType.LM, EvidenceType.ERP]
if self.parameters['show_preview_inquiry']:
self.evidence_types.append(EvidenceType.BTN)
# set a preview_only parameter
self.parameters.add_entry(
'preview_only',
{
'value': True if self.parameters['preview_inquiry_progress_method'] == 0 else False,
'section': '',
'readableName': '',
'helpTip': '',
'recommended_values': '',
'type': 'bool'
}
)

self.rsvp = _init_copy_phrase_display(self.parameters, self.window,
self.daq, self.static_clock,
self.experiment_clock)
self.static_clock, self.experiment_clock)
self.file_save = file_save

self.trigger_save_location = f"{self.file_save}/{parameters['trigger_file_name']}"
Expand All @@ -121,12 +138,6 @@ def __init__(self, win, daq, parameters, file_save, signal_model,
self.language_model = language_model
self.signal_model = signal_model

# TODO: add a parameter for button_press_error_prob.
self.button_press_error_prob = 0.05
self.evidence_types = [EvidenceType.LM, EvidenceType.ERP]
if self.parameters['show_preview_inquiry']:
self.evidence_types.append(EvidenceType.BTN)

def setup(self) -> None:
"""Initialize/reset parameters used in the execute run loop."""

Expand Down Expand Up @@ -453,7 +464,7 @@ def compute_button_press_evidence(
"""
if not self.parameters['show_preview_inquiry'] \
or not self.current_inquiry \
or self.rsvp._preview_inquiry.preview_only:
or self.parameters['preview_only']:
return None
probs = compute_probs_after_preview(self.current_inquiry.stimuli[0],
self.alp,
Expand Down Expand Up @@ -624,9 +635,10 @@ def name(self) -> str:
return self.TASK_NAME


def _init_copy_phrase_display(parameters, win, daq, static_clock,
def _init_copy_phrase_display(parameters, win, static_clock,
experiment_clock):
preview_inquiry = PreviewInquiryProperties(
preview_only=parameters['preview_only'],
preview_inquiry_length=parameters['preview_inquiry_length'],
preview_inquiry_key_input=parameters['preview_inquiry_key_input'],
preview_inquiry_progress_method=parameters[
Expand Down
11 changes: 7 additions & 4 deletions bcipy/task/tests/paradigm/rsvp/test_copy_phrase.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@
from bcipy.acquisition.protocols.lsl.lsl_client import LslAcquisitionClient
from bcipy.acquisition.device_info import DeviceInfo
from bcipy.helpers.copy_phrase_wrapper import CopyPhraseWrapper
from bcipy.helpers.parameters import Parameter, Parameters
from bcipy.task.paradigm.rsvp.copy_phrase import RSVPCopyPhraseTask
from bcipy.task.data import Session, EvidenceType
from bcipy.helpers.stimuli import InquirySchedule, StimuliOrder
from bcipy.helpers.stimuli import InquirySchedule


class TestCopyPhrase(unittest.TestCase):
"""Tests for Copy Phrase task."""

def setUp(self):
"""Override; set up the needed path for load functions."""
self.parameters = {
parameters = {
'backspace_always_shown': True,
'decision_threshold': 0.8,
'down_sampling_rate': 2,
Expand Down Expand Up @@ -66,7 +67,7 @@ def setUp(self):
'stim_height': 0.6,
'stim_length': 10,
'stim_number': 100,
'stim_order': StimuliOrder.RANDOM,
'stim_order': 'random',
'stim_pos_x': 0.0,
'stim_pos_y': 0.0,
'stim_space_char': '–',
Expand All @@ -89,6 +90,7 @@ def setUp(self):
'wait_screen_message': 'Press Space to start or Esc to exit',
'wait_screen_message_color': 'white'
}
self.parameters = Parameters.from_cast_values(**parameters)

self.win = mock({'size': [500, 500], 'units': 'height'})

Expand All @@ -112,12 +114,13 @@ def setUp(self):

self.display = mock()
when(bcipy.task.paradigm.rsvp.copy_phrase)._init_copy_phrase_display(
self.parameters, self.win, self.daq, any,
self.parameters, self.win, any,
any).thenReturn(self.display)

when(bcipy.task.paradigm.rsvp.copy_phrase)._init_copy_phrase_wrapper(
...).thenReturn(self.copy_phrase_wrapper)


def tearDown(self):
"""Override"""
shutil.rmtree(self.temp_dir)
Expand Down

0 comments on commit c6c4c77

Please sign in to comment.