0

我正在使用评级量表。参与者使用“t”和“b”键沿刻度移动光标。目前,每个试验的时长为 6 秒。如果参与者在 6 秒结束前停止按“t”或“b”,我想在我的日志文件中记录最后一次按键的时间。但是,我不确定如何检查哪个按键是最后一个。我正在考虑记录列表中最后一个按键的 RT,但代码会在每次刷新时检查按键。这是我到目前为止所拥有的:

trialNum=0
for eachPic in catPictures:
    prevPos = 0
    key=[]
    b_list=[]
    t_list=[]
    timer = core.CountdownTimer(TrialDuration)
    event.clearEvents() # get rid of other, unprocessed events
    while timer.getTime() > 0:
    for key in event.getKeys():
        if key in ['escape']:
            core.quit() # quit if they press escape
        if key in ['b']:
            # add keypress to list for each keypress. then move cursor proportionally to length of this list
            b_list.append(key)
            prevPos+=len(b_list)
        if key in ['t']:
            t_list.append(key)
            prevPos-=len(t_list)
4

2 回答 2

2
  1. 我只会有一个键列表并在计时器到时检查最后一个元素,即在while循环之后(完成试验后)。
  2. 不要在每个循环中启动一个全新的计时器。只需重置它。资源效率更高。
  3. 缩进while循环中的内容。
  4. 我不明白为什么您将光标移动到该试验中先前按键次数的距离。每次按键将其移动固定距离似乎更合理。所以我在下面做了。
  5. 一定要看看 Jeremy Gray 提出的使用内置的建议psychopy.visual.RatingScale(这个问题的另一个答案)。

未经测试的代码:

timer = core.CountdownTimer(TrialDuration)
stepSize = 1
for eachPic in catPictures:
    prevPos = 0  # keeps track of the slider position
    rts=[]  # used to keep track of what the latest reaction time was. Reset in the beginning of every trial.

    timer.reset()
    event.clearEvents() # get rid of other, unprocessed events
    while timer.getTime() > 0:
    for key, rt in event.getKeys(timeStamped=timer):  # time keys to this clock
        rts += [rt]  # add this reaction time to the list
        if key in ['escape']:
            core.quit() # quit if they press escape
        if key in ['b']:
            # add keypress to list for each keypress. then move cursor proportionally to length of this list
            prevPos+=stepSize
        if key in ['t']:
            prevPos-=stepSize

    # Log here instead of print
    print rts[-1]
于 2015-09-08T21:13:41.793 回答
2

对于给定的评分量表 rs,受试者的所有活动都可以在 rs.history 中获得,无论是在试验期间还是之后。历史只是一个元组列表,其中每个元组是(评级,时间)。如果规模已经开始,第一个元组总是(无,0.0)。如果最后两个评级相同,则受试者接受该评级。如果它们不同,则表明受试者在量表上四处走动,但在量表超时时尚未接受评分。

历史示例:[(None, 0.0), (3, 0.777), (3, 1.396)]

from psychopy import visual, core
win = visual.Window()
rs = visual.RatingScale(win)

c = core.CountdownTimer(3)
while c.getTime() > 0:
    rs.draw()
    win.flip()

# print or log:
print rs.history  # entire history
print rs.history[-1][1]  # just the time of the last rating
于 2015-09-09T11:57:31.107 回答