def get_user_input(window, position, fontsize=50): """ Allows the user to type and see what they type on the screen (This is more annoying than it should be on Psychopy, but it works fine now so you shouldn't need to change it) """ input_name = "" user_input = TextStim(win=window, text=input_name, pos=position, height=fontsize) user_input.setAutoDraw(True) window.flip() while True: char = event.waitKeys()[0] if char.isalpha() and len(char) == 1: input_name += char if char == 'return': user_input.setAutoDraw(False) window.flip() return input_name if char == 'comma': # psychopy inexplicably doesn't respond to the backspace key, # so I use the '<' symbol instead input_name = input_name[:-1] user_input.text = input_name window.flip()
score += 1 #process right schedule if mouse.isPressedIn(rbox, buttons=[0]): rpressed = True if not mouse.isPressedIn(rbox, buttons=[0]) and rpressed == True: rpressed = False R2 += 1 if p == p_list[0]: score += 1 lbox.draw() rbox.draw() #target text.text = u'Вы часто видите число 1?' text.pos = (0, -0.2) text.draw() #responses text.text = u'Да' text.pos = (-0.3, -0.6) text.draw() text.text = u'Нет' text.pos = (+0.3, -0.6) text.draw() #instructions if global_time.getTime() < 25: text.text = u'Отвечайте на вопрос, чтобы заработать очки'
lpressed = False R1 += 1 n1 += 1 Cs1 += 1 n2 = 0 #resets sequence from right if mouse.isPressedIn(rbox, buttons=[0]): rpressed = True if not mouse.isPressedIn(rbox, buttons=[0]) and rpressed == True: rpressed = False n1 = 0 R2 += 1 n2 += 1 Cs2 += 1 text.text = n1 text.pos = (-0.5, +0.25) text.draw() text.text = n2 text.pos = (+0.5, +0.25) text.draw() #processes terminal link schedule if n1 >= ratio or n2 >= ratio: #resets timer for the first time if initial == True: if schedule == 'ConcChFR20VI5/FR20FI5': interval_timer = CountdownTimer(exponential(interval)) if schedule == 'ConcChFR20FI5/FR20VI5':
message = incorrect_message if bl == 0: # only give a message in the learning block trial_routine.wait_for_time_limit( components=[message], time_seconds=messages_duration, label='choice_feedback') data = data.append( {'trial':int(t+1), 'rt':rt, 'choice':key, 'accuracy':accuracy_trial, 'image':image_trial, 'block':['learning', 'transfer'][bl], 'difficulty':block['difficulty'][t], 'correct_response':correct_resp_trial, 'category':block['category'][t]}, ignore_index=True) # record the responses #save data to file for label in expInfo.keys(): data[label] = expInfo[label] data.to_csv(fileName + '.csv') # final message with accuracy feedback accuracy_learning = int(data.loc[data.block == 'learning', 'accuracy'].mean()*100) accuracy_transfer = int(data.loc[data.block == 'transfer', 'accuracy'].mean()*100) end_transfer_message.text = "Congratulations, you finished the experiment. You accuracy was {}% in the learning part and {}% in the test.".format(accuracy_learning, accuracy_transfer) trial_routine.wait_for_time_limit( components=[end_transfer_message], time_seconds=message_beginning_duration, label='message_end') #cleanup mywin.close() core.quit()
fixation_cross = TextStim(win=mywin, text='+', color=text_color) rewards = np.arange(0, 601, 30) rewards[0] += 1 n_trials = len(rewards) #create the dataframe data = pd.DataFrame([]) #draw the stimuli trial_routine = Routine(window=mywin, frames_per_second=frames_per_second, escape_key=escape_key) for t in range(n_trials): # put here things that change every trial changing_gamble.text = 'a sure gain of CHF %s' % rewards[t] # first event trial_routine.wait_for_time_limit( components=[fixation_cross], time_seconds=fixation_duration, label='fixation_cross') # second event key, rt = trial_routine.wait_for_keys_or_time_limit( components=[fixed_gamble, changing_gamble], valid_keys=choice_keys, time_seconds=choice_time_limit, label='gamble_choice') data = data.append({'rt':rt, 'choice': key, 'trial': t, 'reward': rewards[t]}, ignore_index=True) # record the responses
# this will continue to loop until the participant clicks 'q' key char_pressed = psychopy.event.waitKeys( ) #input("Please enter a character: 'a', 'b', 'c' or 'd' to reveal your winnings. Type 'q' to quit: ") if char_pressed == ['a']: # character 'a' refers to Deck A #obtaining winning & losing amount from Deck winningsLoses = deckA.getWinsLoses() print( f"This is winnings Loses {winningsLoses} of type: {type(winningsLoses)}" ) print( f"This is winnings {int(winningsLoses[0])} of type: {type(int(winningsLoses[0]))}" ) #winning losing amount display text winningsVariableText.text = participantA.getWinnings( ) #todo check how winnings are being calculated and make sure they are correct #Obtaining the amount won as display text amountWonVariableText.text = str(deckA.getWins()) #amountWonVariableText.draw() #todo: investigate is this going to cut it or do I need to display flip or refresh as well? #Obtaining the amount lost as display text amountLostVariableText.text = str( deckA.getLosses()) #todo: check if winningLoses are correct #Recalculating the participants winnings participantA.setWinnings( winningsLoses ) #todo: requires two actions? positional argument 'winnings_loses') participantA.recordKeysPressed('a') print( f"The total row number is {deckA.getTotalRows()} of type {type(deckA.getTotalRows())}" )
stimuli.loc[stimuli.right_image == 'C.png', 'right_feedback'] = rewards_C stimuli = stimuli.sample(frac=1).reset_index(drop=True) stimuli['trial'] = np.arange(n_trials) + 1 #create the dataframe data = pd.DataFrame([]) #draw the stimuli trial_routine = Routine(window=mywin, frames_per_second=frames_per_second, escape_key=escape_key) for t in range(n_trials): # put here things that change every trial left_feedback.text = '%s' % stimuli.loc[t, 'left_feedback'] right_feedback.text = '%s' % stimuli.loc[t, 'right_feedback'] left_picture.image = os.path.join(os.getcwd(), 'stimuli', 'example_4', stimuli.loc[t, 'left_image']) right_picture.image = os.path.join(os.getcwd(), 'stimuli', 'example_4', stimuli.loc[t, 'right_image']) # first event trial_routine.wait_for_time_limit(components=[fixation_cross], time_seconds=fixation_duration, label='fixation_cross') # second event key, rt = trial_routine.wait_for_keys_or_time_limit( components=[left_picture, right_picture],
size=image_size, image=os.path.join(os.getcwd(), 'stimuli', 'B.png')) fixation_cross = TextStim(win=mywin, text='+', color=text_color) #create the dataframe data = pd.DataFrame([]) #draw the stimuli trial_routine = Routine(window=mywin, frames_per_second=frames_per_second, escape_key=escape_key) for t in range(n_trials): # put here things that change every trial A_feedback.text = '%s' % A_feedback_trials[t] B_feedback.text = '%s' % B_feedback_trials[t] # first event trial_routine.wait_for_time_limit(components=[fixation_cross], time_seconds=fixation_duration, label='fixation_cross') # second event key, rt = trial_routine.wait_for_keys_or_time_limit( components=[A_picture, B_picture], valid_keys=choice_keys, time_seconds=choice_time_limit, label='choice') data = data.append( {
if schedule == 'ConcVI15FI15': T2 = CountdownTimer(interval) #fixed interval elif schedule == 'ConcFI15VI15': T2 = CountdownTimer(exponential(interval)) #finishes script if 'escape' pressed if 'escape' in resp_key: break #record data tempArray = [global_time.getTime(), R1, R2, Rf1, Rf2, phase, schedule] data.append(tempArray) #drawer text.text, text.pos = score, (0, 0) text.draw() #displays earned points if global_time.getTime() < 25.0: text.text = u'Кликайте внутри красных прямоугольников, чтобы заработать очки' text.pos = (0, +0.5) text.draw() win.flip() final = CountdownTimer(25) while final.getTime() > 0: text.text = u'Ваш результат - %i. Благодарим за участие в эксперименте. Окно закроется автоматически через %i сек.' % ( score, round(final.getTime(), 0)) text.pos = (0, 0) text.draw()
value_current = 1500 value_upper = 3000 value_lower = 0 #create the dataframe data = pd.DataFrame([]) #draw the stimuli trial_routine = Routine(window=mywin, frames_per_second=frames_per_second, escape_key=escape_key) for t in range(n_trials): # put here things that change at the beginning of every trial value_current = int(np.round(np.mean([value_upper, value_lower]))) safe_gamble.text = "100% chance of CHF {}".format(value_current) # first event trial_routine.wait_for_time_limit(components=[], time_seconds=fixation_duration, label='fixation_cross') # second event key, rt = trial_routine.wait_for_keys( components=[safe_gamble, risky_gamble], valid_keys=choice_keys, label='gamble_choice') data = data.append( { 'rt': rt, 'choice': key,