Example #1
0
def EncodeTrial(self, config, trial_dict):
    """Show an image for encoding """
    with Parallel():
        Label(text="+", font_size=s(config.CROSS_FONT_SIZE))
        with UntilDone():
            Image(source=trial_dict['stim'],
                  height=s(config.STIM_HEIGHT),
                  width=s(config.STIM_WIDTH),
                  allow_stretch=True,
                  keep_ratio=True,
                  duration=config.STIM_ENCODE_DUR)
            Wait(config.ISI, jitter=config.ISI_JIT)
    Log(trial_dict, name="ENCODE")
Example #2
0
def Trial(self,
          config,
          stim,
          center_x,
          center_y,
          condition,
          correct_resp=None,
          color='white',
          pulse_server=None):

    self.eeg_pulse_time = None
    # present the dots
    fl = Flanker(center_x=center_x,
                 center_y=center_y,
                 sep=s(config.CONFIG_SEP),
                 df=s(config.CONFIG_DF),
                 line_width=s(config.LW),
                 stim=stim)
    with UntilDone():
        # Collect key response
        Wait(until=fl.appear_time)
        if config.EEG:
            pulse_fn = LSLPush(server=pulse_server,
                               val=Ref.getitem(config.EEG_CODES, condition))
            Log(name="FLKR_PULSES", start_time=pulse_fn.push_time)
            self.eeg_pulse_time = pulse_fn.push_time
        gr = GetResponse(correct_resp=correct_resp,
                         base_time=fl.appear_time['time'],
                         duration=config.RESPONSE_DURATION,
                         keys=config.RESP_KEYS)

    self.pressed = gr.pressed
    self.press_time = gr.press_time
    self.rt = gr.rt
    self.correct = gr.correct

    # save vars
    self.appear_time = fl.appear_time
    self.disappear_time = fl.disappear_time
Example #3
0
def SSVEPExp(self, config):

    res = Func(gen_stim, config)

    Wait(.5)

    Label(text=config.INST_TEXT,
          markup=True,
          text_size=(s(1100), None),
          font_size=s(config.INST_FONT)
          )
    with UntilDone():

        KeyPress(keys=['SPACEBAR'])

    Wait(1.0)

    with Loop(res.result) as block:

        Label(text="+", font_size=s(config.ORIENT_FONT))
        with UntilDone():

            with Loop(block.current) as trial:

                rect = Rectangle(center_x=self.exp.screen.center_x + \
                                          s(config.SPACING_RECT)*trial.current['orientation'],
                                 alpha=0.0, height=config.RECT_DIM,
                                 width=config.RECT_DIM)
                with UntilDone():

                    rect.animate(color=lambda t, initial: (1.0, 1.0, 1.0,
                                                           (1. + Ref(sin, 2*pi*t/trial.current['period']))/2.),
                                 duration=config.ANI_DURATION)

                Wait(config.ISI, jitter=config.JITTER)
        Label(text='Short Break! When you are ready to continue, press Spacebar.')
        with UntilDone():
            KeyPress(keys=['SPACEBAR'])
Example #4
0
def Instruct(self, config):

    et = Func(gen_instruct_blocks, config)

    Label(text=config.INST1,
          font_size=s(config.INST_FONT_SIZE),
          text_size=(s(1000), None))
    with UntilDone():
        KeyPress()
    Wait(.5)

    with Loop(et.result[0]) as lp:
        EncodeTrial(config, lp.current)

    Label(text=config.INST2,
          font_size=s(config.INST_FONT_SIZE),
          text_size=(s(1000), None))
    with UntilDone():
        KeyPress()
    Wait(.5)

    Label(text=config.INST3,
          font_size=s(config.INST_FONT_SIZE),
          text_size=(s(1000), None))
    with UntilDone():
        KeyPress()
    Wait(.5)

    Label(text=config.INST4,
          font_size=s(config.INST_FONT_SIZE),
          text_size=(s(1000), None))
    with UntilDone():
        KeyPress()
    Wait(.5)

    with Loop(et.result[1]) as lp:
        TestTrial(config, lp.current)
Example #5
0
def BartuvaExp(self,
               config,
               run_num,
               sub_dir,
               task_dir=None,
               full_instructions=True,
               practice=False,
               pulse_server=None):

    if task_dir is not None:
        config.TASK_DIR = task_dir
    config.INST2_IMG_PATH = os.path.join(config.TASK_DIR,
                                         config.INST2_IMG_PATH)

    if config.TOUCH:
        config.KEY_TEXT = config.TOUCH_TEXT
        config.CONT_KEY_STR = "the screen"

    if len(config.CONT_KEY) > 1:
        cont_key_str = str(config.CONT_KEY[0]) + " or " + \
                       str(config.CONT_KEY[-1])
    else:
        cont_key_str = "the screen"

    Log(name="BARTUVAinfo",
        version=version.__version__,
        author=version.__author__,
        date_time=version.__date__,
        email=version.__email__)

    Wait(1.)

    # Do instructions along with a mini block.
    with If(practice | full_instructions):
        Instruct(config=config,
                 run_num=run_num,
                 sub_dir=sub_dir,
                 task_dir=task_dir,
                 full_instructions=full_instructions,
                 practice=practice)

    balloon_setup = config.BALLOON_SETUP
    num_balloons = config.NUM_BALLOONS

    Label(text='You will now begin the balloon task.' +
          '\nPress %s to continue.' % (cont_key_str),
          halign='center',
          font_size=s(config.LABEL_FONT_SIZE))
    with UntilDone():
        Wait(.5)
        GetResponse(keys=config.CONT_KEY)

    number_of_sets = 1
    self.set_number = 0
    self.grand_total = config.GRAND_TOTAL
    self.balloon_number_session = 0
    self.trkp_press_time = None

    # FMRI STUFF
    if config.FMRI:

        Label(text="Waiting for Experimenter...",
              font_size=s(config.INST_FONT_SIZE))
        with UntilDone():
            KeyPress(keys=config.FMRI_TECH_KEYS)

        Label(text="+", font_size=s(config.CROSS_FONTSIZE))
        with UntilDone():
            trkp = KeyPress(keys=config.FMRI_TR)
            Log(name="BARTUVA_TR", press_time=trkp.press_time)
            self.trkp_press_time = trkp.press_time
        Wait(duration=config.INIT_TR_WAIT)

    Wait(1.)
    # main loop
    with Loop(number_of_sets):
        Wait(.5, jitter=.5)

        # Calling listgen as 'bags'
        bg = Func(add_air,
                  total_number_of_balloons=config.NUM_BALLOONS,
                  num_ranges=len(config.BALLOON_SETUP),
                  balloon_setup=config.BALLOON_SETUP,
                  randomize=config.RANDOMIZE_BALLOON_NUM,
                  reward_low=config.REWARD_LOW,
                  reward_high=config.REWARD_HIGH,
                  subject_directory=sub_dir,
                  practice=False,
                  shuffle_bags=config.SHUFFLE_BAGS)
        bags = bg.result

        self.block_tic = 0

        # with Loop(bag.current) as balloon:
        with Loop(bags) as balloon:
            Balloon = BARTSub(
                config,
                balloon=balloon.current,
                block=self.block_tic,
                set_number=self.set_number,
                grand_total=self.grand_total,
                balloon_number_session=self.balloon_number_session,
                subject=self._exp.subject,
                run_num=run_num,
                trkp_press_time=self.trkp_press_time,
                pulse_server=pulse_server)
            self.balloon_number_session += 1
            self.grand_total = Balloon.grand_total
        self.block_tic += 1

        self.set_number += 1

    # Press 6 to say we are done recording then show them their score.
    if config.FMRI:
        self.keep_tr_checking = True
        Wait(config.POST_TR_WAIT)
        Label(text="Waiting for Experimenter...",
              font_size=s(config.INST_FONT_SIZE))
        with UntilDone():
            with Loop(conditional=self.keep_tr_checking):
                post_trkp = KeyPress(keys=config.FMRI_TR,
                                     duration=config.POST_CHECK_TR_DUR)
                with If(post_trkp.pressed == ''):
                    self.keep_tr_checking = False
            KeyPress(keys=config.FMRI_TECH_KEYS)

        Wait(1.0)
Example #6
0
    config.EEG = True

    if config.EEG:
        pulse_server = init_lsl_outlet(server_name='MarkerStream',
                                       server_type='Markers',
                                       nchans=1,
                                       suggested_freq=500,
                                       channel_format='int32',
                                       unique_id='COGBATT_LSL_OUT')
    else:
        pulse_server = None

    config.FLIP_BART = True
    exp = Experiment(name="BARTUVA_ONLY",
                     debug=True,
                     background_color=((.35, .35, .35, 1.0)))
    Wait(1.0)
    InputSubject(exp_title="BARTUVA")
    BartuvaExp(config,
               run_num=0,
               sub_dir=exp.subject_dir,
               full_instructions=True,
               practice=True,
               pulse_server=pulse_server)
    Label(text=
          "Task Complete! Please wait for the program to automatically close.",
          font_size=s(config.INST_FONT_SIZE),
          duration=2.0)

    exp.run()
Example #7
0
def Trial(self,
          cross,
          config,
          correct_resp=None,
          incorrect_resp=None,
          color='white',
          num_dots=100,
          right_coherence=0.0,
          left_coherence=0.0,
          pulse_server=None):

    self.eeg_pulse_time = None
    with Serial():
        # present the dots
        with Parallel():
            cross.update(color=(.35, .35, .35, 1.0))
            md = MovingDots(color=color,
                            scale=s(config.SCALE),
                            num_dots=num_dots,
                            radius=s(config.RADIUS),
                            motion_props=[{
                                "coherence": right_coherence,
                                "direction": 0,
                                "direction_variance": 0
                            }, {
                                "coherence": left_coherence,
                                "direction": 180,
                                "direction_variance": 0
                            }],
                            lifespan=config.LIFESPAN,
                            lifespan_variance=config.LIFESPAN_VAR,
                            speed=s(config.SPEED))
        with UntilDone():
            # Collect key response
            Wait(until=md.appear_time)
            if config.EEG:
                pulse_fn = LSLPush(server=pulse_server,
                                   val=Ref.getitem(config.EEG_CODES, "code"))
                Log(name="RDM_PULSES", start_time=pulse_fn.push_time)
                self.eeg_pulse_time = pulse_fn.push_time

            gr = GetResponse(correct_resp=correct_resp,
                             base_time=md.appear_time['time'],
                             duration=config.RESPONSE_DURATION,
                             keys=config.RESP_KEYS)
        self.pressed = gr.pressed
        self.press_time = gr.press_time
        self.rt = gr.rt
        self.correct = gr.correct
        # give feedback
        with If(self.pressed == correct_resp):
            # They got it right
            Label(text=u"\u2713",
                  color='green',
                  duration=config.FEEDBACK_TIME,
                  font_size=s(config.FEEDBACK_FONT_SIZE),
                  font_name='DejaVuSans.ttf')
        with Elif(self.pressed == incorrect_resp):
            # they got it wrong
            Label(text=u"\u2717",
                  color='red',
                  font_size=s(config.FEEDBACK_FONT_SIZE),
                  duration=config.FEEDBACK_TIME,
                  font_name='DejaVuSans.ttf')
        with Else():
            # too slow
            Label(text="Too Slow!",
                  font_size=s(config.FEEDBACK_FONT_SIZE),
                  duration=config.FEEDBACK_TIME * 2.)

    # bring the cross back
    cross.update(color=config.CROSS_COLOR)

    # save vars
    self.appear_time = md.appear_time
    self.disappear_time = md.disappear_time
    self.refresh_rate = md.widget.refresh_rate
Example #8
0
Wait(.1)

Instruct(config=config, lang="E")

Wait(.1)

with Loop(blocks) as block:
    with Loop(block.current) as ds:  #dots set
        fixation_point = Label(text="+",
                               duration=0.75,
                               font_size=80,
                               bold=False,
                               color=[0, 0, 0, 1])
        with Parallel():
            md_white = MovingDots(radius=s(300),
                                  scale=s(2.5),
                                  color="white",
                                  num_dots=250,
                                  motion_props=ds.current['motion_props'])
            md_black = MovingDots(radius=s(300),
                                  scale=s(2.5),
                                  color="black",
                                  num_dots=250,
                                  motion_props=ds.current['motion_props'])
        with UntilDone():
            Wait(until=fixation_point.disappear_time)
            kp = KeyPress(keys=["F", "J"],
                          duration=3.,
                          correct_resp=ds.current['CR'],
                          base_time=fixation_point.disappear_time['time'])
Example #9
0
def Instruct(self, config, lang="E"):
    cont_key_str = 'SPACE'
    print(cont_key_str)
    with If(lang == "E"):
        self.top_text = 'Your goal is to determine the direction that\n [i]MOST[/i] of the dots are moving.\n Please respond quickly and accurately.'  # Ref.object(top_text)['E']
        # self.tap_text_M = 'Tap [b]the screen[/b] when you ' + 'are ready to begin the block.'
        self.tap_text_C = 'Press [b]%s[/b] when you are ready to begin the block.' % (
            cont_key_str)

    # handle the reverse mapping
    with Parallel():
        Label(text=self.top_text,
              markup=True,
              halign='center',
              text_size=(s(s(config['INST_RADIUS']) * 4.5), None),
              bottom=self.exp.screen.center_y + s(config['INST_RADIUS']) +
              s(60),
              font_size=s(config['INST_FONT_SIZE']) * 2)
        md_l_w = MovingDots(color='white',
                            scale=s(2),
                            num_dots=config['NUM_DOTS'],
                            radius=s(config['INST_RADIUS']),
                            coherence=config['COHERENCES'],
                            direction=180,
                            lifespan=config['INST_LIFESPAN'],
                            center_y=self.exp.screen.center_y + s(45),
                            lifespan_variance=config['INST_LIFESPAN_VAR'],
                            speed=s(config['INST_SPEED']),
                            right=self.exp.screen.center_x - s(100))
        md_l_b = MovingDots(color='black',
                            scale=s(2),
                            num_dots=config['NUM_DOTS'],
                            radius=s(config['INST_RADIUS']),
                            coherence=config['COHERENCES'],
                            direction=180,
                            lifespan=config['INST_LIFESPAN'],
                            center_y=self.exp.screen.center_y + s(45),
                            lifespan_variance=config['INST_LIFESPAN_VAR'],
                            speed=s(config['INST_SPEED']),
                            right=self.exp.screen.center_x - s(100))
        md_r_w = MovingDots(color='white',
                            scale=s(2),
                            num_dots=config['NUM_DOTS'],
                            radius=s(config['INST_RADIUS']),
                            coherence=config['COHERENCES'],
                            direction=0,
                            lifespan=config['INST_LIFESPAN'],
                            center_y=self.exp.screen.center_y + s(45),
                            lifespan_variance=config['INST_LIFESPAN_VAR'],
                            speed=s(config['INST_SPEED']),
                            right=self.exp.screen.center_x + s(500))
        md_r_b = MovingDots(color='black',
                            scale=s(2),
                            num_dots=config['NUM_DOTS'],
                            radius=s(config['INST_RADIUS']),
                            coherence=config['COHERENCES'],
                            direction=0,
                            lifespan=config['INST_LIFESPAN'],
                            center_y=self.exp.screen.center_y + s(45),
                            lifespan_variance=config['INST_LIFESPAN_VAR'],
                            speed=s(config['INST_SPEED']),
                            right=self.exp.screen.center_x + s(500))
        lt = Label(
            text=Ref(bottom_text, config, True, lang),
            markup=True,
            halign='left',
            text_size=(s(config['INST_RADIUS']) * 1.9, None),
            left_top=(self.exp.screen.center_x -
                      (2 * s(config['INST_RADIUS'])) - s(50),
                      self.exp.screen.center_y - (s(config['INST_RADIUS']))),
            font_size=s(config['INST_FONT_SIZE']))
        Label(text=Ref(bottom_text, config, False, lang),
              markup=True,
              halign='right',
              text_size=(s(config['INST_RADIUS']) * 1.9, None),
              right_top=(self.exp.screen.center_x +
                         2 * s(config['INST_RADIUS']) + s(50),
                         self.exp.screen.center_y - s(config['INST_RADIUS'])),
              font_size=s(config['INST_FONT_SIZE']))

        Label(text=self.tap_text_C,
              font_size=s(config['INST_FONT_SIZE'] * 1.5),
              top=lt.bottom - s(80),
              markup=True,
              halign='center')

    with UntilDone():
        kp = KeyPress(keys=["SPACEBAR"])
Example #10
0
# following line in the command line:
#                python your_code.py -f -r **width**x**height**
# Where width and height are replaced with the resolution of the monitor you
# want to test.

RADIUS = 100

# Set a scale_box to [600, 500] which is [width, height] and scale_up/scale_down
# to make sure that no matter what the monitor size is, everything will be scale
# to fit in side a scale_box.
exp = Experiment(scale_box=[600, 500], scale_up=True, scale_down=True)

# As an example, if you run this file on one computer, and then another one
# with a different monitor size, the first number in this debug should be
# different on both machines, but the second number will be 10.
Debug(s=s(10), b=10)

# Font size is a perfect example of something you would want to scale with
# monitor size and screen density.
Label(text="These are some instructions", font_size=s(20))
with UntilDone():
    if platform == "android":
        with ButtonPress():
            Button(size=exp.screen.size, background_color=(0, 0, 0, 0))
    else:
        KeyPress()
Wait(1.)

with Loop([20, 10, 5, 1]) as lp:
    # MovingDots allows us to to play with many different sizing and positioning
    # parameters. The scale of the dots, the radius of the apature, the speed of the
Example #11
0
def Obfuscation(self, config):
    blocks = Func(gen_stim, config, ".").result

    Instruct(config)

    Label(text="You have now finished the practice instructions.\n" +
          "Press any key to continue to the experiment.",
          font_size=s(config.FONT_SIZE))
    with UntilDone():
        KeyPress()

    Wait(config.ISI)

    with Loop(blocks) as block:

        Label(text="Prepare for a block of the experiment.\n" +
              "Press any key to continue.",
              font_size=s(config.FONT_SIZE))
        with UntilDone():
            KeyPress()

        Wait(.3)

        Label(text=config.ENCODE_REMINDER,
              multiline=True,
              font_size=s(config.INST_FONT_SIZE),
              text_size=(s(1000), None))
        with UntilDone():
            KeyPress()

        Wait(1.0)

        with Loop(block.current[0]) as encode_trial:
            EncodeTrial(config, trial_dict=encode_trial.current)

        Label(
            text=
            "You are now about to do a different task.\n\nPress any key to continue.",
            font_size=s(config.FONT_SIZE))
        with UntilDone():
            KeyPress()

        with Serial():
            FlankerExp(Flanker_config,
                       run_num=block.i,
                       lang="E",
                       pulse_server=None)
            Label(
                text=
                "Please wait, the rest of the experiment will begin shortly.",
                font_size=s(config.FONT_SIZE))
        with UntilDone():
            Wait(config.INTER_PART_WAIT)

        Label(text=config.TEST_REMINDER,
              multiline=True,
              font_size=s(config.INST_FONT_SIZE),
              text_size=(s(1000), None))
        with UntilDone():
            KeyPress()

        Wait(1.0)

        with Loop(block.current[1]) as test_trial:
            TestTrial(config, trial_dict=test_trial.current)

        Label(
            text=
            "You are now about to do a different task.\n\nPress any key to continue.",
            font_size=s(config.FONT_SIZE),
            text_size=(s(1000), None))
        with UntilDone():
            KeyPress()
        with If(block.i < 1):
            with Serial():
                FlankerExp(Flanker_config,
                           run_num=block.i,
                           lang="E",
                           pulse_server=None)
                Label(
                    text=
                    "Please wait, the rest of the experiment will begin shortly.",
                    font_size=s(config.FONT_SIZE))
            with UntilDone():
                Wait(config.INTER_PART_WAIT)
Example #12
0
def TestTrial(self, config, trial_dict):
    """Show an image and test memory/confidence """

    stim_img = Image(source=trial_dict['stim'],
                     height=s(config.STIM_HEIGHT),
                     width=s(config.STIM_WIDTH),
                     allow_stretch=True,
                     keep_ratio=True)
    with UntilDone():

        Label(text="Seen or New\n\n%s or %s" %
              (config.ON_KEYS[0], config.ON_KEYS[1]),
              font_size=s(config.FONT_SIZE),
              top=stim_img.bottom - s(10),
              halign='center')
        with UntilDone():

            Wait(until=stim_img.appear_time)
            kp1 = KeyPress(keys=config.ON_KEYS,
                           correct_resp=trial_dict['corr_resp'],
                           base_time=stim_img.appear_time['time'])

        # Ask for confidence
        with Parallel():
            conlbl = Label(text="Confidence?",
                           font_size=s(config.FONT_SIZE),
                           top=stim_img.bottom - s(10))
            conunderlbl = Label(text="%s" % (config.KEYS[0]),
                                top=conlbl.bottom - s(10),
                                right=self.exp.screen.center_x - s(250),
                                font_size=s(config.FONT_SIZE))
            conunderlblb = Label(text="%s" % (config.KEYS[1]),
                                 top=conlbl.bottom - s(10),
                                 right=self.exp.screen.center_x - s(150),
                                 font_size=s(config.FONT_SIZE))
            conunderlblc = Label(text="%s" % (config.KEYS[2]),
                                 top=conlbl.bottom - s(10),
                                 right=self.exp.screen.center_x - s(50),
                                 font_size=s(config.FONT_SIZE))
            conunderlbld = Label(text="%s" % (config.KEYS[3]),
                                 top=conlbl.bottom - s(10),
                                 left=self.exp.screen.center_x + s(50),
                                 font_size=s(config.FONT_SIZE))
            conunderlble = Label(text="%s" % (config.KEYS[4]),
                                 top=conlbl.bottom - s(10),
                                 left=self.exp.screen.center_x + s(150),
                                 font_size=s(config.FONT_SIZE))
            conunderlblf = Label(text="%s" % (config.KEYS[5]),
                                 top=conlbl.bottom - s(10),
                                 left=self.exp.screen.center_x + s(250),
                                 font_size=s(config.FONT_SIZE))
            Label(text="0%",
                  top=conunderlbl.bottom - s(10),
                  center_x=conunderlbl.center_x,
                  font_size=s(config.FONT_SIZE))
            Label(text="20%",
                  top=conunderlbl.bottom - s(10),
                  center_x=conunderlblb.center_x,
                  font_size=s(config.FONT_SIZE))
            Label(text="40%",
                  top=conunderlbl.bottom - s(10),
                  center_x=conunderlblc.center_x,
                  font_size=s(config.FONT_SIZE))
            Label(text="60%",
                  top=conunderlbl.bottom - s(10),
                  center_x=conunderlbld.center_x,
                  font_size=s(config.FONT_SIZE))
            Label(text="80%",
                  top=conunderlbl.bottom - s(10),
                  center_x=conunderlble.center_x,
                  font_size=s(config.FONT_SIZE))
            Label(text="100%",
                  top=conunderlbl.bottom - s(10),
                  center_x=conunderlblf.center_x,
                  font_size=s(config.FONT_SIZE))
        with UntilDone():

            Wait(until=conlbl.appear_time)
            kp2 = KeyPress(keys=config.KEYS,
                           base_time=conlbl.appear_time['time'])

    Log(trial_dict,
        name="TEST",
        stim_appear_time=stim_img.appear_time,
        conf_appear_time=conlbl.appear_time,
        oldnew_pressed=kp1.pressed,
        conf_pressed=kp2.pressed,
        oldnew_rt=kp1.rt,
        conf_rt=kp2.rt,
        oldnew_base_time=kp1.base_time,
        conf_base_time=kp2.base_time)
    Wait(config.ISI)
Example #13
0
for y in range(numblocks):
    dots_set = []
    for x in range(lenblocks):  # trials in each block
        for i in Left_coh:
            for j in Right_coh:
                if i > j:
                    CR = 'F'  #allowed key left
                elif i < j:
                    CR = 'J'  #allowed key right
                else:
                    continue
                    # CR = None #equal
                motion_props = [{
                    "coherence": i,
                    "direction": 180,
                    "speed": s(110),
                    "lifespan": 2 / 60
                }, {
                    "coherence": j,
                    "direction": 0,
                    "speed": s(110),
                    "lifespan": 2 / 60
                }, {
                    "coherence": 1 - i - j,
                    "direction": 0,
                    "direction_variance": 180,
                    "speed": s(450),
                    "speed_variance": s(100),
                    "lifespan": 2 / 60
                }]
                trial_dots = {
Example #14
0
def Instruct(self, config, text_names):  #, resp_keys, touch, font_size):

    texts = get_text(config)
    with Parallel():
        if not config.TOUCH:
            MouseCursor(blocking=False)
        with Serial(blocking=False):
            for doc in text_names:
                with Parallel():
                    title = Label(text='Memory Task Instructions',
                                  font_size=s(config.INST_TITLE_FONT_SIZE),
                                  text_size=(s(config.TEXT_SIZE_WIDTH), None),
                                  top=self.exp.screen.center_y + s(415))

                    # image != None for 4 example slides
                    with If(texts[doc]['image'] != None):
                        image = Image(source=texts[doc]['image'],
                                      top=(title.bottom - s(10)),
                                      width=s(config.INST_IMG_WIDTH),
                                      height=s(config.INST_IMG_HEIGHT),
                                      allow_stretch=True,
                                      keep_ratio=False)
                    with If(texts[doc]['image'] != None):
                        Label(text=texts[doc]['text'],
                              font_size=s(config.INST_FONT_SIZE),
                              text_size=(s(config.TEXT_SIZE_WIDTH), None),
                              top=(image.bottom - s(10)))

                # image == None for first and last slides (instructions and reminder)
                    with If(texts[doc]['image'] == None):
                        Label(text=texts[doc]['text'],
                              text_size=(s(config.TEXT_SIZE_WIDTH), None),
                              font_size=s(config.INST_FONT_SIZE),
                              top=(title.bottom - s(10)))

                with UntilDone():
                    Wait(1.0)
                    GetResponse(keys=texts[doc]['keys'])

                #RstDocument(text=texts[doc]['text'],
                #width=self.exp.screen.height,
                #height=self.exp.screen.height,
                #base_font_size=s(config.RST_FONT_SIZE))

        with Serial(blocking=False):
            with ButtonPress():
                Button(text="Skip Practice",
                       right=self.exp.screen.width,
                       bottom=0,
                       width=s(config.SKIP_SIZE[0]),
                       height=s(config.SKIP_SIZE[1]),
                       blocking=False,
                       font_size=s(config.SKIP_FONT_SIZE))
    Wait(2.0)
Example #15
0
def BARTSub(self,
            config,
            balloon=[],
            block=0,
            set_number=0,
            balloon_number_session=0,
            grand_total=0.00,
            subject="test000",
            run_num=0,
            trkp_press_time=None,
            pulse_server=None):
    BANK_IMG = os.path.join(config.TASK_DIR, "stim", "Bank.png")
    POP_IMG = os.path.join(config.TASK_DIR, 'stim', 'Pop.png')

    #sets updating index from main.py
    self.set_number = set_number

    #setting up necessary refs for experiment
    self.subject = subject

    #self.reward_dist_type = self.balloon['reward_dist']
    self.total = 0.00
    self.grand_total = grand_total
    self.curr_balloon_size = config.BALLOON_START_SIZE

    self.eeg_pulse_time = None

    ###################################################################
    #Conditional that breaks loop when false.
    self.pressed_key = True
    if (config.FLIP_BART):
        pos = -1
    else:
        pos = 1

    # Generating images,labels, and objects on screen
    with Parallel():

        Nozzle = Triangle(color=balloon['color'],
                          points=[self.exp.screen.center_x,
                                  self.exp.screen.center_y + s(config.TRIAN_SIZE),
                                  self.exp.screen.center_x - s(config.TRIAN_SIZE)/2.,
                                  self.exp.screen.center_y,
                                  self.exp.screen.center_x + s(config.TRIAN_SIZE)/2.,
                                  self.exp.screen.center_y])
        Balloon = Ellipse(color=balloon['color'],
                          size=(s(self.curr_balloon_size), s(self.curr_balloon_size)),
                          bottom=Nozzle.top-s(18))
        Bank_outline1 = Rectangle(color=(0,0,0,0),
                         center_x=self.exp.screen.center_x + (s(250)*pos),
                         center_y=self.exp.screen.center_y - s(75),
                         width=s(config.BANK_WIDTH) + s(5),
                         height=s(config.BANK_HEIGHT) + s(5))
        Bank = Image(source=BANK_IMG,
                     center=Bank_outline1.center,
                     allow_stretch=True, keep_ratio=False,
                     width=s(config.BANK_WIDTH),
                     height=s(config.BANK_HEIGHT))
        Gtotal = Label(text=Ref(str.format, '${:,.2f}', self.grand_total),
                      font_size=s(config.TOTAL_FONT_SIZE),
                      center=Bank.center)
        Air_line = Rectangle(color='white',
                             center_x=self.exp.screen.center_x,
                             top=Nozzle.bottom + s(25),
                             width=s(config.NOZZLE_WIDTH),
                             height=s(config.NOZZLE_HEIGHT))
        Air_pump_outline = Rectangle(color='white',
                             center_x=self.exp.screen.center_x,
                             top=Air_line.bottom,
                             width=s(config.AIR_PUMP_WIDTH) + s(5),
                             height=s(config.AIR_PUMP_HEIGHT) + s(5))
        Air_pump = Rectangle(color='black',
                             center=Air_pump_outline.center,
                             width=s(config.AIR_PUMP_WIDTH),
                             height=s(config.AIR_PUMP_HEIGHT))
        Total = Label(text=Ref(str.format, '${:.2f}', self.total),
                      font_size=s(config.TOTAL_FONT_SIZE),
                      color='black',
                      center=Balloon.center)
        LChoice_label = Label(text='%s to pump'%config.KEY_TEXT[0],
                              font_size=s(config.TRIAL_FONT_SIZE),
                              color='white', halign="center",
                              top=Air_pump_outline.bottom - s(10),
                              )
        RChoice_label = Label(text='%s to collect'%config.KEY_TEXT[1],
                          font_size=s(config.TRIAL_FONT_SIZE),
                          color='white', halign="center",
                          center_x=Bank_outline1.center_x,
                          top=Bank_outline1.bottom - s(1))


    with UntilDone():
        with Loop(Ref(len,balloon['pop'])) as trial:
            with If(self.pressed_key==True):
                Wait(0.5, jitter=.3)
                Fixation_cross = Label(text='+',
                                       font_size=s(config.CROSS_FONT_SIZE),
                                       color=config.CROSS_COLOR,
                                       center=Air_pump.center)
                with UntilDone():
                    Wait(0.5, jitter=0.3)
                Reward_label = Label(text=Ref(str.format, '${:,.2f}', balloon['rewards'][trial.i]),
                                     font_size=s(config.TRIAL_FONT_SIZE),
                                     color='white',
                                     center=Air_pump.center)
                with UntilDone():
                    Wait(until=Reward_label.appear_time)
                    if config.EEG:
                        pulse_fn = LSLPush(server=pulse_server,
                                           val=Ref.getitem(config.EEG_CODES, "code"))
                        Log(name="BARTUVA_PULSES",
                            start_time=pulse_fn.push_time)
                        self.eeg_pulse_time = pulse_fn.push_time
                    with Serial():
                        Gtotal.update(color='white')
                        Wait(until=Reward_label.appear_time)
                        with Loop():
                            Wait(0.4)
                            with Parallel():
                                self.grand_total -= 0.01
                                Gtotal.update(text=Ref(str.format, '${:,.2f}', self.grand_total),
                                              color='yellow')
                            Wait(0.05)
                            Gtotal.update(color='white')
                    # get response using subroutine
                    with UntilDone():
                        gr = GetResponse(keys=config.RESP_KEYS,
                                         base_time=Reward_label.appear_time['time'])
                        self.grand_total += 0.01
                        Gtotal.update(text=Ref(str.format, '${:,.2f}', self.grand_total),
                                      color='white')
                        self.pressed = gr.pressed
                        self.press_time = gr.press_time
                        self.rt = gr.rt

                    with If(self.pressed == config.RESP_KEYS[0]):
                        with If(balloon['pop'][trial.i] == 0):
                            self.total = 0
                            with Serial():
                                Reward_label.slide(duration=config.REWARD_SLIDE_DURATION,
                                                   center=Balloon.center,
                                                   color=(0,0,0,0))
                                with Parallel():
                                    Total.slide(duration=0.5,
                                                center_y=Balloon.center_y)
                                    Balloon.slide(duration=0.5,
                                                  size=(s(config.BALLOON_EXPLODE_SIZE[0]),
                                                        s(config.BALLOON_EXPLODE_SIZE[1])),
                                                  color=(0,0,0,0))
                                with Parallel():
                                    Pop_image = Image(source=POP_IMG,
                                                      duration=config.POP_ANIMATION_DURATION,
                                                      size=(s(config.POP_SIZE[0]), s(config.POP_SIZE[1])),
                                                      center=Balloon.center)
                                    Total.update(color=(0,0,0,0))
                                    Nozzle.update(color=(0,0,0,0))

                                Gtotal.update(text=Ref(str.format, '${:,.2f}', self.grand_total))
                                self.pop_status='popped'
                                self.pressed_key = False

                        with Elif(balloon['pop'][trial.i] != 0):

                            with If(balloon['rewards'][trial.i] >= 0):
                                self.total +=  balloon['rewards'][trial.i]

                                with Parallel():
                                    self.curr_balloon_size += s(config.INC_BALLOON_SIZE)

                                    with Serial():
                                        Reward_label.slide(duration=config.REWARD_SLIDE_DURATION,
                                                           center=Balloon.center,
                                                           color=(0,0,0,0))

                                        with Parallel():
                                            Balloon.slide(duration=config.BALLOON_GROWTH_DURATION,
                                                          size=(s(self.curr_balloon_size),s(self.curr_balloon_size)),
                                                          #center_y=Balloon.center_y + s(config.INC_BALLOON_SIZE))
                                                          )
                                            Total.slide(duration=config.BALLOON_GROWTH_DURATION,
                                                        center_y=Balloon.center_y
                                                        )

                                        Total.update(text=Ref(str.format, '${:,.2f}', self.total))

                                    self.pop_status = 'not_popped'

                            with Elif(balloon['rewards'][trial.i]<0):

                                with Serial():
                                    Reward_label.slide(duration=config.PUMP_DURATION,
                                                       center=Bank.center,
                                                       color=(0,0,0,0))
                                    self.grand_total +=  balloon['rewards'][trial.i]
                                    Gtotal.update(text=Ref(str.format, '${:,.2f}', self.grand_total))
                                    self.pop_status = 'buy-in'

                    with Elif(self.pressed == config.RESP_KEYS[-1]):

                        with Parallel():
                            Total.update(text=Ref(str.format, '${:,.2f}', self.total))

                            with Serial():
                                Nozzle.update(color=(0,0,0,0))

                                with Parallel():
                                    Total.slide(duration=config.COLLECT_DURATION,
                                                center=Bank.center)
                                    Balloon.slide(duration=config.COLLECT_DURATION,
                                                  center=Bank.center)

                                Balloon.update(color=(0,0,0,0))
                                Total.update(color=(0,0,0,0))
                                self.grand_total += self.total
                                Gtotal.update(text=Ref(str.format, '${:,.2f}', self.grand_total))
                                self.pop_status="not_popped"

                        self.pressed_key = False

                #Logging trial info
                Log(name="OBART",
                    subject=self.subject,
                    run_num=run_num,
                    balloon_number_session=balloon_number_session,
                    set_number=self.set_number,
                    balloon_number=balloon['balloon_number'],
                    block=block,
                    bag_ID_number=balloon['bag_ID_number'],
                    balloon_in_bag=balloon['balloon_in_bag'],
                    trial=trial.i,
                    pop_range=balloon['pump_range'],
                    pop_status=self.pop_status,
                    reward_appear_time=Reward_label.appear_time,
                    rt=self.rt,
                    press_time=self.press_time,
                    key_pressed=self.pressed,
                    total=self.total,
                    grand_total=self.grand_total,
                    rewards=balloon['rewards'][trial.i],
                    balloon_size=self.curr_balloon_size,
                    trkp_press_time=trkp_press_time,
                    eeg_pulse_time=self.eeg_pulse_time)
                    # reward_dist_type=self.reward_dist_type[trial.i],

    Wait(config.INTER_PUMP_DURATION)
    grand_total_carryover = self.grand_total
Example #16
0
def Instruct(self, config, lang="E"):

    inst = Func(get_instructions, config).result

    # with If(practice==True):
    with Parallel():
        if not config.TOUCH:
            MouseCursor(blocking=False)
        with Serial(blocking=False):
            with Parallel():
                toplbl = Label(text=inst['top_text'],
                               markup=True,
                               halign='center',
                               center_x=self.exp.screen.center_x,
                               center_y=self.exp.screen.center_y,
                               font_size=s(config.INST_FONT_SIZE))

                # upper left
                Flanker(center_x=self.exp.screen.center_x - s(400),
                        center_y=toplbl.top + s(125),
                        sep=s(config.CONFIG_SEP),
                        df=s(config.CONFIG_DF),
                        line_width=s(config.LW),
                        stim="__<__\n_<<<_\n<<<<<\n_<<<_\n__<__\n")
                # upper middle
                Flanker(center_x=self.exp.screen.center_x,
                        center_y=toplbl.top + s(125),
                        sep=s(config.CONFIG_SEP),
                        df=s(config.CONFIG_DF),
                        line_width=s(config.LW),
                        stim="__>__\n_><>_\n><<<>\n_><>_\n__>__\n")
                # upper right
                Flanker(center_x=self.exp.screen.center_x + s(400),
                        center_y=toplbl.top + s(125),
                        sep=s(config.CONFIG_SEP),
                        df=s(config.CONFIG_DF),
                        line_width=s(config.LW),
                        stim="__<__\n_<><_\n<><><\n_<><_\n__<__\n")

                # lower left
                Flanker(center_x=self.exp.screen.center_x - s(400),
                        center_y=toplbl.bottom - s(125),
                        sep=s(config.CONFIG_SEP),
                        df=s(config.CONFIG_DF),
                        line_width=s(config.LW),
                        stim="__<__\n_<><_\n<><><\n_<><_\n__<__\n")
                # lower middle
                Flanker(center_x=self.exp.screen.center_x,
                        center_y=toplbl.bottom - s(125),
                        sep=s(config.CONFIG_SEP),
                        df=s(config.CONFIG_DF),
                        line_width=s(config.LW),
                        stim="__>__\n_><>_\n><><>\n_><>_\n__>__\n")
                # lower right
                Flanker(center_x=self.exp.screen.center_x + s(400),
                        center_y=toplbl.bottom - s(125),
                        sep=s(config.CONFIG_SEP),
                        df=s(config.CONFIG_DF),
                        line_width=s(config.LW),
                        stim="__<__\n_<><_\n<>>><\n_<><_\n__<__\n")

            with UntilDone():
                Wait(until=toplbl.appear_time)
                GetResponse(keys=config.CONT_KEY)

            Wait(1.0)

            with Loop(
                [["__<__\n_<<<_\n<<<<<\n_<<<_\n__<__\n", config.RESP_KEYS[0]],
                 ["__>__\n_><>_\n><<<>\n_><>_\n__>__\n", config.RESP_KEYS[0]],
                 ["__<__\n_<><_\n<>>><\n_<><_\n__<__\n", config.RESP_KEYS[-1]],
                 ["__>__\n_><>_\n><><>\n_><>_\n__>__\n",
                  config.RESP_KEYS[-1]]]) as prac_ev:
                Wait(1.0)
                p2 = Trial(config,
                           stim=prac_ev.current[0],
                           center_x=self.exp.screen.center_x,
                           center_y=self.exp.screen.center_y,
                           correct_resp=prac_ev.current[1],
                           condition='+')
                with If(p2.correct):
                    # They got it right
                    Label(text=u"\u2713",
                          color='green',
                          duration=config.FEEDBACK_TIME,
                          font_size=s(config.FEEDBACK_FONT_SIZE),
                          font_name='DejaVuSans.ttf')
                with Else():
                    # they got it wrong
                    Label(text=u"\u2717",
                          color='red',
                          font_size=s(config.FEEDBACK_FONT_SIZE),
                          duration=config.FEEDBACK_TIME,
                          font_name='DejaVuSans.ttf')

            with Meanwhile():
                with Parallel():
                    Ellipse(color='red', size=(s(55), s(55)))
                    Ellipse(color=config.INNER_CIRCLE_COLOR,
                            size=(s(45), s(45)))
                    Label(text=inst['inst_1'],
                          markup=True,
                          halign='center',
                          center_x=self.exp.screen.center_x,
                          center_y=self.exp.screen.center_y + s(300),
                          font_size=s(config.INST_FONT_SIZE))

            Wait(1.0)
            Label(text=inst['inst_2'],
                  markup=True,
                  halign='center',
                  center_x=self.exp.screen.center_x,
                  center_y=self.exp.screen.center_y + s(300),
                  font_size=s(config.INST_FONT_SIZE))
            with UntilDone():
                GetResponse(keys=config.CONT_KEY)

            with Loop([[
                    "__<__\n_<><_\n<>>><\n_<><_\n__<__\n", config.RESP_KEYS[1],
                    cos(radians((360. / config.NUM_LOCS) * 5)),
                    sin(radians((360. / config.NUM_LOCS) * 5))
            ],
                       [
                           "__<__\n_<><_\n<><><\n_<><_\n__<__\n",
                           config.RESP_KEYS[0],
                           cos(radians((360. / config.NUM_LOCS) * 1)),
                           sin(radians((360. / config.NUM_LOCS) * 1))
                       ],
                       [
                           "__>__\n_><>_\n><><>\n_><>_\n__>__\n",
                           config.RESP_KEYS[1],
                           cos(radians((360. / config.NUM_LOCS) * 3.)),
                           sin(radians((360. / config.NUM_LOCS) * 3.))
                       ],
                       [
                           "__>__\n_><>_\n><><>\n_><>_\n__>__\n",
                           config.RESP_KEYS[1],
                           cos(radians((360. / config.NUM_LOCS) * 4.)),
                           sin(radians((360. / config.NUM_LOCS) * 4.))
                       ],
                       [
                           "__>__\n_>>>_\n>>>>>\n_>>>_\n__>__\n",
                           config.RESP_KEYS[1],
                           cos(radians((360. / config.NUM_LOCS) * 0)),
                           sin(radians((360. / config.NUM_LOCS) * 0))
                       ],
                       [
                           "__>__\n_><>_\n><<<>\n_><>_\n__>__\n",
                           config.RESP_KEYS[0],
                           cos(radians((360. / config.NUM_LOCS) * 2)),
                           sin(radians((360. / config.NUM_LOCS) * 2))
                       ]]) as prac_ev:
                Wait(1.0)
                with Parallel():
                    Ellipse(color='red',
                            size=(s(55), s(55)),
                            center_x=self.exp.screen.center_x +
                            prac_ev.current[2] * s(config.FROM_CENTER),
                            center_y=self.exp.screen.center_y +
                            prac_ev.current[3] * s(config.FROM_CENTER),
                            blocking=False)
                    Ellipse(color=config.INNER_CIRCLE_COLOR,
                            size=(s(45), s(45)),
                            center_x=self.exp.screen.center_x +
                            prac_ev.current[2] * s(config.FROM_CENTER),
                            center_y=self.exp.screen.center_y +
                            prac_ev.current[3] * s(config.FROM_CENTER),
                            blocking=False)
                    p4 = Trial(config,
                               stim=prac_ev.current[0],
                               center_x=self.exp.screen.center_x +
                               prac_ev.current[2] * s(config.FROM_CENTER),
                               center_y=self.exp.screen.center_y +
                               prac_ev.current[3] * s(config.FROM_CENTER),
                               correct_resp=prac_ev.current[1],
                               condition='+')
                with If(p4.correct):
                    # They got it right
                    Label(text=u"\u2713",
                          color='green',
                          duration=config.FEEDBACK_TIME,
                          font_size=s(config.FEEDBACK_FONT_SIZE),
                          font_name='DejaVuSans.ttf')
                with Else():
                    # they got it wrong
                    Label(text=u"\u2717",
                          color='red',
                          font_size=s(config.FEEDBACK_FONT_SIZE),
                          duration=config.FEEDBACK_TIME,
                          font_name='DejaVuSans.ttf')

            Label(text=inst['to_cont'],
                  halign='center',
                  center_x=self.exp.screen.center_x,
                  center_y=self.exp.screen.center_y,
                  font_size=s(config.INST_FONT_SIZE))
            with UntilDone():
                GetResponse(keys=config.CONT_KEY)

            Wait(1.0)
            Label(text=inst['inst_3'],
                  markup=True,
                  halign='center',
                  center_x=self.exp.screen.center_x,
                  center_y=self.exp.screen.center_y + s(200),
                  font_size=s(config.INST_FONT_SIZE))
            with UntilDone():
                GetResponse(keys=config.CONT_KEY)

            with Loop([[
                    "__<__\n_<><_\n<>>><\n_<><_\n__<__\n", config.RESP_KEYS[1],
                    cos(radians((360. / config.NUM_LOCS) * 5)),
                    sin(radians((360. / config.NUM_LOCS) * 5))
            ],
                       [
                           "__<__\n_<><_\n<><><\n_<><_\n__<__\n",
                           config.RESP_KEYS[0],
                           cos(radians((360. / config.NUM_LOCS) * 1)),
                           sin(radians((360. / config.NUM_LOCS) * 1))
                       ],
                       [
                           "__>__\n_><>_\n><><>\n_><>_\n__>__",
                           config.RESP_KEYS[1],
                           cos(radians((360. / config.NUM_LOCS) * 3)),
                           sin(radians((360. / config.NUM_LOCS) * 3))
                       ],
                       [
                           "__>__\n_>>>_\n>>>>>\n_>>>_\n__>__\n",
                           config.RESP_KEYS[1],
                           cos(radians((360. / config.NUM_LOCS) * 6)),
                           sin(radians((360. / config.NUM_LOCS) * 6))
                       ],
                       [
                           "__>__\n_><>_\n><<<>\n_><>_\n__>__\n",
                           config.RESP_KEYS[0],
                           cos(radians((360. / config.NUM_LOCS) * 2)),
                           sin(radians((360. / config.NUM_LOCS) * 2))
                       ]]) as prac_ev:
                Wait(1.0)
                p5 = Trial(config,
                           stim=prac_ev.current[0],
                           center_x=self.exp.screen.center_x +
                           prac_ev.current[2] * s(config.FROM_CENTER),
                           center_y=self.exp.screen.center_y +
                           prac_ev.current[3] * s(config.FROM_CENTER),
                           correct_resp=prac_ev.current[1],
                           condition='+')

                with If(p5.correct):
                    # They got it right
                    Label(text=u"\u2713",
                          color='green',
                          duration=config.FEEDBACK_TIME,
                          font_size=s(config.FEEDBACK_FONT_SIZE),
                          center_y=self.exp.screen.center_y + s(50),
                          font_name='DejaVuSans.ttf')
                with Else():
                    # they got it wrong
                    Label(text=u"\u2717",
                          color='red',
                          font_size=s(config.FEEDBACK_FONT_SIZE),
                          center_y=self.exp.screen.center_y + s(50),
                          duration=config.FEEDBACK_TIME,
                          font_name='DejaVuSans.ttf')
            with Meanwhile():
                Label(text="+", font_size=s(config.ORIENT_FONT_SIZE))

        with Serial(blocking=False):
            with ButtonPress():
                Button(text=inst['skip_text'],
                       right=self.exp.screen.width,
                       bottom=0,
                       width=s(config.SKIP_SIZE[0]),
                       height=s(config.SKIP_SIZE[1]),
                       blocking=False,
                       font_size=s(config.SKIP_FONT_SIZE))

    Wait(1.0)

    Label(text=inst['done'],
          halign='center',
          center_x=self.exp.screen.center_x,
          center_y=self.exp.screen.center_y,
          font_size=s(config.INST_FONT_SIZE))
    with UntilDone():
        GetResponse(keys=config.CONT_KEY)
Example #17
0
def Instruct(self, config, lang="E"):
    if len(config.CONT_KEY) > 1:
        cont_key_str = str(config.CONT_KEY[0]) + " or " + str(
            config.CONT_KEY[-1])
    else:
        cont_key_str = str(config.CONT_KEY[0])
    print(cont_key_str)
    with If(lang == "E"):
        self.top_text = Ref.object(top_text)['E']
        self.tap_text_M = 'Tap [b]the screen[/b] when you ' + 'are ready to begin the block.'
        self.tap_text_C = 'Press [b]%s[/b] when you are ready to begin the block.' % (
            cont_key_str)
    with Elif(lang == "S"):
        self.top_text = Ref.object(top_text)['S']
        self.tap_text_M = 'Toque [b]la pantalla[/b] cuando usted esté listo para comenzar el bloque.'
        self.tap_text_C = 'Press [b]%s[/b] when you are ready to begin the block.' % (
            cont_key_str)
    with Elif(lang == "P"):
        self.top_text = Ref.object(top_text)['P']
        self.tap_text_M = 'Pressione a tela quando você estiver pronto para começar este bloco.'
        self.tap_text_C = 'Press [b]%s[/b] when you are ready to begin the block.' % (
            cont_key_str)

    # handle the reverse mapping
    with Parallel():
        Label(text=self.top_text,
              markup=True,
              halign='center',
              text_size=(s(config.TEST_WIDTH), None),
              bottom=self.exp.screen.center_y + s(config.INST_RADIUS) + s(60),
              font_size=s(config.INST_FONT_SIZE))
        md_l = MovingDots(color='white',
                          scale=s(config.INST_SCALE),
                          num_dots=config.NUM_DOTS,
                          radius=s(config.INST_RADIUS),
                          coherence=config.COHERENCES[2],
                          direction=180,
                          lifespan=config.INST_LIFESPAN,
                          center_y=self.exp.screen.center_y + s(45),
                          lifespan_variance=config.INST_LIFESPAN_VAR,
                          speed=s(config.INST_SPEED),
                          right=self.exp.screen.center_x - s(10))
        md_r = MovingDots(color='white',
                          scale=s(config.INST_SCALE),
                          num_dots=config.NUM_DOTS,
                          radius=s(config.INST_RADIUS),
                          coherence=config.COHERENCES[2],
                          direction=0,
                          lifespan=config.INST_LIFESPAN,
                          center_y=self.exp.screen.center_y + s(45),
                          lifespan_variance=config.INST_LIFESPAN_VAR,
                          speed=s(config.INST_SPEED),
                          left=self.exp.screen.center_x + s(10))
        lt = Label(
            text=Ref(bottom_text, config, True, lang),
            markup=True,
            halign='left',
            text_size=(s(config.INST_RADIUS) * 1.9, None),
            left_top=(self.exp.screen.center_x - (2 * s(config.INST_RADIUS)) -
                      s(10),
                      self.exp.screen.center_y - (s(config.INST_RADIUS))),
            font_size=s(config.INST_FONT_SIZE))
        Label(text=Ref(bottom_text, config, False, lang),
              markup=True,
              halign='right',
              text_size=(s(config.INST_RADIUS) * 1.9, None),
              right_top=(self.exp.screen.center_x + 2 * s(config.INST_RADIUS) +
                         s(10),
                         self.exp.screen.center_y - s(config.INST_RADIUS)),
              font_size=s(config.INST_FONT_SIZE))
        if config.TOUCH:
            Label(text=self.tap_text_M,
                  font_size=s(config.INST_FONT_SIZE),
                  top=lt.bottom - s(10),
                  markup=True,
                  halign='center')
        else:
            Label(text=self.tap_text_C,
                  font_size=s(config.INST_FONT_SIZE),
                  top=lt.bottom - s(10),
                  markup=True,
                  halign='center')

    with UntilDone():
        GetResponse(keys=config.CONT_KEY)
Example #18
0
def Instruct(
    self,
    config,
    run_num,
    sub_dir,
    task_dir=None,
    full_instructions=True,
    practice=True,
    lang="E",
):

    if len(config.CONT_KEY) > 1:
        cont_key_str = str(config.CONT_KEY[0]) + " or " + str(
            config.CONT_KEY[-1])
    else:
        cont_key_str = str(config.CONT_KEY[0])

    if config.TOUCH:
        with Loop(computer_list) as instruction:
            txt = instruction.current
            with Parallel():
                with If((instruction.i == 3)):
                    Label(text=txt %
                          (config.TOUCH_INST[0], config.TOUCH_INST[-1]),
                          halign='left',
                          font_size=s(config.LABEL_FONT_SIZE))
                with Elif((instruction.i == 7)):
                    Label(text=txt % (config.NUM_BALLOONS),
                          halign='left',
                          font_size=s(config.LABEL_FONT_SIZE))
                with Elif((instruction.i == 8)):
                    Label(text=txt %
                          (config.NUM_BAGS, config.BALLOONS_PER_BAG),
                          halign='left',
                          font_size=s(config.LABEL_FONT_SIZE))
                with Else():
                    Label(text=txt,
                          halign='left',
                          font_size=s(config.LABEL_FONT_SIZE))
                Label(text='Press %s to continue' % (config.CONT_KEY_STR),
                      halign='left',
                      bottom=(self.exp.screen.center_x, 0),
                      font_size=s(config.LABEL_FONT_SIZE))
            with UntilDone():
                Wait(.5)
                GetResponse(keys=config.CONT_KEY)

    else:
        with Parallel():
            MouseCursor(blocking=False)
            with Serial(blocking=False):
                with If(full_instructions):
                    with Loop(computer_list) as instruction:
                        txt = instruction.current
                        with Parallel():
                            with If((instruction.i == 2)):
                                with Parallel():
                                    img2 = Image(source=config.INST2_IMG_PATH,
                                                 top=self.exp.screen.height,
                                                 keep_ratio=True,
                                                 allow_stretch=True,
                                                 width=s(1000))
                                    lbl2 = Label(
                                        text=txt % (config.KEY_TEXT[0],
                                                    config.KEY_TEXT[-1]),
                                        halign='left',
                                        top=img2.bottom + s(100),
                                        font_size=s(config.LABEL_FONT_SIZE))
                                    Label(text='Press %s to continue' %
                                          (config.CONT_KEY_STR),
                                          halign='left',
                                          top=lbl2.bottom,
                                          font_size=s(config.LABEL_FONT_SIZE))
                            with Else():
                                with Parallel():
                                    lbl1 = Label(text=txt,
                                                 halign='left',
                                                 font_size=s(
                                                     config.LABEL_FONT_SIZE))
                                    Label(text='Press %s to continue' %
                                          (config.CONT_KEY_STR),
                                          halign='left',
                                          top=lbl1.bottom - s(75),
                                          font_size=s(config.LABEL_FONT_SIZE))
                        with UntilDone():
                            Wait(.5)
                            GetResponse(keys=config.CONT_KEY)

                with If(practice):

                    Label(
                        text=
                        "You will now have a short practice bag of balloons.\n"
                        +
                        "Please note how the money in the bank drops until you"
                        + " make a decision.\nPress %s to continue." %
                        (cont_key_str),
                        halign='center',
                        font_size=s(config.LABEL_FONT_SIZE))
                    with UntilDone():
                        Wait(.5)
                        GetResponse(keys=config.CONT_KEY)

                    number_of_sets = 1
                    self.set_number = 0
                    self.grand_total = config.GRAND_TOTAL
                    self.balloon_number_session = 0
                    self.trkp_press_time = None

                    Wait(1.)
                    # Loop over practice blocks
                    with Loop(number_of_sets):
                        Wait(.5, jitter=.5)

                        # Calling listgen as 'bags'
                        bg = Func(add_air,
                                  total_number_of_balloons=len(
                                      config.PRACTICE_SETUP),
                                  num_ranges=len(config.PRACTICE_SETUP),
                                  balloon_setup=config.PRACTICE_SETUP,
                                  randomize=config.RANDOMIZE_BALLOON_NUM,
                                  reward_low=config.REWARD_LOW,
                                  reward_high=config.REWARD_HIGH,
                                  subject_directory=sub_dir,
                                  practice=True,
                                  shuffle_bags=config.SHUFFLE_BAGS)
                        bags = bg.result

                        self.block_tic = 0

                        # with Loop(bag.current) as balloon:
                        with Loop(bags) as balloon:
                            Balloon = BARTSub(
                                config,
                                balloon=balloon.current,
                                block=self.block_tic,
                                set_number=self.set_number,
                                grand_total=self.grand_total,
                                balloon_number_session=self.
                                balloon_number_session,
                                subject=self._exp.subject,
                                run_num=run_num,
                                trkp_press_time=self.trkp_press_time)
                            self.balloon_number_session += 1
                            self.grand_total = Balloon.grand_total
                        self.block_tic += 1

                        self.set_number += 1

                    Wait(.5)
                    Label(text='You have completed the practice.\n' +
                          'Press %s to continue.' % (cont_key_str),
                          halign='center',
                          font_size=s(config.LABEL_FONT_SIZE))
                    with UntilDone():
                        Wait(1.5)
                        GetResponse(keys=config.CONT_KEY)
            with Serial(blocking=False):
                with ButtonPress():
                    Button(text="Skip Practice",
                           width=s(config.SKIP_SIZE[0]),
                           bottom=0,
                           right=self.exp.screen.width,
                           height=s(config.SKIP_SIZE[1]),
                           font_size=s(config.SKIP_FONT_SIZE))
Example #19
0
    from smile.common import Experiment
    from smile.startup import InputSubject
    import config

    config.TEST_REMINDER = config.TEST_REMINDER % (
        config.ON_KEYS[0], config.ON_KEYS[1], config.KEYS[0], config.KEYS[1],
        config.KEYS[2], config.KEYS[3], config.KEYS[4], config.KEYS[5],
        config.KEYS[0], config.KEYS[1], config.KEYS[5])

    config.INST4 = config.INST4 % (
        config.ON_KEYS[0], config.ON_KEYS[1], config.KEYS[0], config.KEYS[1],
        config.KEYS[2], config.KEYS[3], config.KEYS[4], config.KEYS[5],
        config.KEYS[0], config.KEYS[1], config.KEYS[5])
    Flanker_config.RESP_KEYS = config.ON_KEYS[:]
    Flanker_config.CONT_KEY = config.ON_KEYS[:]
    Flanker_config.TOUCH = False
    exp = Experiment(background_color=(.35, .35, .35, 1.0), name="obfuscate")

    InputSubject(name="Obfuscation")

    Obfuscation(config)

    Label(
        text=
        "You are now finished with the experiment,\nLet your experimenter Know!",
        font_size=s(config.FONT_SIZE))
    with UntilDone():
        KeyPress()

    exp.run()