Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

[solved] Time pressure within experiments

edited May 2015 in OpenSesame

Hi all,

I am trying to insert a timer in my experiment using OpenSesame, and I went through some codes in python websites, however I couldn't find any solution for this.

To be more obvious, what I do need, is a timer that counts down the 'remaining time' to finish the task by the participants. Aim: putting time-pressure as a variable in the experiment.

Thanks to all!

Regards,
Francisco

Comments

  • edited 4:24AM

    Hi Francisco,

    You can access a timer by calling self.time(). This will give you the current system time.
    If you sample it twice and take its difference, you will get a duration of the interval between the 2 samples:

    t0 = self.time()
    self.sleep(1000)
    t1 = self.time()
    print t1-t0 # should print something like 1000
    
    # a timer
    
    timer_start = 10000 # 10 seconds
    used_time = timer_start - (t1-t0)
    while used_time > 0:
        t1 = self.time()
        used_time = timer_start - (t1-t0)
        # do other stuff
    

    The only thing you have to make sure, is that the timer is updated while the participant is doing the task, because otherwise the entire while-loop structure is pointless.

    Does this help?

    Eduard

    Buy Me A Coffee

  • edited 4:24AM

    Hi Edward,

    I will try it and let you know. Thanks for your answer!!
    Francisco

  • edited April 2015

    Hi Edward,

    I tried to do what you suggested. I think I miss some part.. I can call self-time() in a inline_script you mean? And what should I put in the prepare_phase and run_phase of my inline_script?

    However, I don't know if that is going to make what I want. The timer will appear in the screen with this?

    Sorry being so dummy..

    Thanks a lot!
    Francisco

  • edited April 2015

    Hi Francisco,

    So the goal is to display a timer onscreen, while the participant is doing the experiment? (you didn't specify this before).
    Yes, you can call self.time() in an inline script. Since displaying the timer is going to be an ongoing process during the task (updating the time onscreen every millisecond for example), this should go in the run phase. Beware though, that any given taskscreen is a static thing by default - meaning that there is no way to create and display a canvas (= screen) only once but still have an ongoing timer. That's why I would suggest displaying the seconds only (i.e., not milliseconds) so that you only have to refresh this static screen once every second. Further, it will definitely be easier if the task itself can be displayed on a single screen per trial as well (at least for as long as the timer should be active). A way to go about this (using an 8 seconds timer) would be:

       from openexp.keyboard import keyboard
       my_keyboard = keyboard(exp, keylist=['z', 'm']) # if it's a 2-button response task, say)
    
       task_done = False
       start_time = self.time()
       last_digit = "8"
       exp.canvas.text(last_digit)
       exp.canvas.show()
    
       while (task_done == False and timer_out > 0):
              timer = 8000 - (self.time() - start_time)
              current_digit = str(timer)[0]  # takes the current second
              if current_digit != last_digit:  # i.e. when current_digit becomes '7'
                    last_digit = current_digit
                    exp.canvas.clear()
                    exp.canvas.text(last_digit)
                    exp.canvas.show()
              response_given = my_keyboard.flush()
              if response_given == True:
                    task_done == True
    
        if timer_out < 0:
               exp.canvas.clear()
               exp.canvas.text("Time out!")
               exp.canvas.show()
    

    This would display an 8 on screen that ticks down to zero. The different screens displaying their respective digits are made on the go; an alternative way (that might make the experiment run more smoothly) is to make all those eight screens in the prepare phase. Then you only have to use the .show() command in the run phase.

    Hope this helps.

    Cheers,
    Josh

  • edited 4:24AM

    Hi Josh,

    First of all. Thanks for your both answers. I was confused with the other discussion and thought it was "the same" as I wanted to do. However after your comments I realize it wasn't.

    So ok, what you just mentioned in your comment (in this discussion) is what I do need to do.

    I have a trial in my experiment with 10 different images. In each of them there is a correct answer (I am using Z and M as key_response). I am using an experiment_loop to run randomly the ten images (as the OpenSesame tutorial shows) with a [cr] for the correct response on the keyboard.

    I need to get the timer onscreen when the images appear, and after the participant makes the decision it will appear another fixation_dot and another image with another timer too.

    I tried to use the code you suggested, but probably I did it in the wrong way because I got an error when the experiment got to the trial. The code you wrote I putted it in the run_phase. Should I do anything in the command break_if?

    I will send the appearance of my experiment. - file:///Users/FranciscoMarcus/Desktop/Captura%20de%20ecra%CC%83%202015-04-28,%20a%CC%80s%2000.59.01.png

    Thank you very much indeed!

    Kind regards,
    Francisco

  • edited May 2015

    Hi Francisco,

    If you bump into errors, it is always wise to post the error message together with your question. This makes our life a lot easier to find out what went wrong.

    In case you copied Josh's code as he wrote it above, your problem is that the code is not ready to be run yet. I took the freedom to add some things that enable you to see the timer on screen and adapt it to your wishes. Also I couldn't resist to make a pretty clock timer. If you don't like it, or it slows down your experiment, for whatever reason, of course you can use the simple seconds timer as well.


    from openexp.keyboard import keyboard from openexp.canvas import canvas my_keyboard = keyboard(exp, keylist=['z', 'm']) # if it's a 2-button response task, say) cv = canvas(exp) # initialize a canvas def timer2clock(timer): ''' converts a plain integer representing the seconds left to a proper clock ''' clock = str(timer//60000) + ':' + str(timer%60000)[:-3] # do the formatting if len(clock) == 2: clock = '0' + clock[:2] + '00' + clock[2:] elif len(clock) == 3: clock = '0' + clock[:2] + '0' + clock[2:] elif len(clock) == 4: clock = '0' + clock return clock # define parameters task_done = False start_time = self.time() timer = 10000 # 2 minutes rest_time = 10000 clock = timer2clock(timer) # show initial screen cv.text(clock) cv.show() # update screen while (task_done == False and rest_time > 0): # update time cur_time = self.time() rest_time = timer - (cur_time - start_time) clock = timer2clock(rest_time) # draw to screen cv.clear() cv.text(clock) ############## # DRAW YOUR STIMULUS HERE ############## cv.show() # get response k,t = my_keyboard.get_key(timeout = 50) if k != None: task_done = True # visualization of effects if task_done: cv.clear() cv.text("Correct!") cv.show() self.sleep(1000) if rest_time < 0: cv.clear() cv.text("Time out!") cv.show() self.sleep(1000)

    Buy Me A Coffee

  • edited 4:24AM

    Hi Edward,

    So it seems that your piece of code gets me the timer onscreen!!

    However the timer gets first or after the stimulus (as I put it before or after my stimulus in the 'sequence').

    I saw that you wrote a parte in the code where I can/should put my stimulus, but I already have the stimulus written inside the sequence (fixation_dot; sketchpad; key_response).

    Also, my response should be with the [cr] that I have linked to my stimulus, which seems that with the timer I have to possible responses (my [cr] and the two options the code gives) which probably will mess my results and data.

    That is how I am inserting the Timer on my experiment - file:///Users/FranciscoMarcus/Desktop/Captura%20de%20ecra%CC%83%202015-05-3,%20a%CC%80s%2017.44.42.png

    Any advices how to get the timer with the stimulus onscreen at the same time?

    Thanks a lot for your help!!

    Cheers
    Francisco

  • edited 4:24AM

    Hi Francisco,

    First of all, the pictures you're posting are not accessible. Can you give it another try uploading them, if you think they would help solving your issues?

    You're right. Using fixdot, sketchpad and keyboard_response is rather difficult to combine with the timer-inline_script. The only way that maybe would work, at least as far as I know, is finding out how to access the canvas which is created by the fixdot and the sketchpad item and manipulate them in your inline_script to contain the timer.

    Another option, which seams easier to me, is not using these items at all, and draw your stimuli also in the inline_script. The way to do it is explained in thisdocumentation. So basically, you need to initialize a canvas, then draw a fixation dot on the canvas and finally your stimulus. You could do this in the prepare phase of your inline_script to save computation time. During the while loop you'll have to add the timer to the canvas, so that you can see both at the same time.

    The response collection is a smaller issue. In the beginning of your inline_script you can access your [cr] variable to get the correct response (e.g. exp.get('cr') or so), then you change this line:

    my_keyboard = keyboard(exp, keylist=['z', 'm'])

    into a more generic way of creating your keyboard:

    my_keyboard = keyboard(exp, keylist=correct_resp) # correct_resp needs to be defined first.

    Does this help?

    Eduard

    Buy Me A Coffee

  • edited 4:24AM

    Hi Edward,

    Thanks a lot!
    I just got it.

    Best wishes!!
    Francisco

  • Hey everyone.

    I have a similar task like Francisco.

    I want my participants to work under time pressure. For that reason I want to show a 30 second timer on the top right corner of my sketchpad for every trial. I am not using keyboard but mouse_response and I only have one sketchpad (so no fixdot etc).

    I tried to modify the code above to fit my aims, which are:


    placing the countdown on my sketchpad in the top right corner (not in the middle)

    using a mouse response (instead of keyboard)

    and using the countdown only on one sketchpad.


    but I just can't manage... like not even a little :(


    Could anyone help my modify that code for my purpose?


    Regards.

    Charlotte

Sign In or Register to comment.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu http://45.77.173.118/ Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games