【问题标题】:psychopy logging time when participant stopped moving cursor参与者停止移动光标时的心理记录时间
【发布时间】:2015-09-08 16:57:47
【问题描述】:

我正在使用评分量表。参与者使用“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)

【问题讨论】:

    标签: python keypress logfile psychopy response-time


    【解决方案1】:
    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]
    

    【讨论】:

    • 1.好决定。 2.也好打电话。我从 gedit 粘贴,所有内容都正确缩进。 3. 因为如果他们快速按下很多键,它会让光标移动得更快。否则,将光标从评分量表的一侧移动到另一侧可能需要很长时间。
    • 我想打印(或记录)最后一个键被按下的时间,而不是最后一个键是什么。我不知道该怎么做,但它可能涉及在按下最后一个键时将变量设置为等于clock.getTime()。编辑:我让它工作。谢谢!
    • 我更新了答案以获得反应时间。我还删除了两个不必要的行(b_list.append(key) 和另一个)。并提出第 5 点,您绝对应该查看昨天出现的另一个答案 :-)
    【解决方案2】:

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

    示例历史: [(无, 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-23
      • 2012-08-15
      • 1970-01-01
      • 1970-01-01
      • 2015-03-22
      相关资源
      最近更新 更多