Howdy, Stranger!

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

Supported by

[solved] Rating Scale

edited July 2015 in OpenSesame

Dear all,

I need to show my participants a rating scale (e.g., ''how happy are you?'') with a 10-points Likert. Being in the MR scanner, they can only use 3 buttons (i.e., they cannot simply enter the desired number).
My idea is that they move a little square around the 10 numbers (starting from 5, which is in the middle), from one number to another using the left and the right button to go left/right on the scale, and they press the middle button to 'accept' when the little square is around the correct number.
I think I need to write an inline where, based on the given response, I can modify the x-position of the square so that participant can move it as many times as she wants (for instance, if she makes a mistake and goes to further in the scale) before accepting the correct number. At least, this is how I would do with E-prime, for instance.

However, my Python skills are not good at that, and I couldn't find the right solution. Also, I don't know if this would work in a loop or sequence (same for declaring variables like the x-position).

Could any of you help me?
This would be of great help!
Many thanks in advance,
Manuela

Comments

  • edited June 2015

    Hi Manuela,

    Yes, an inline_script would be the most effective way. You could make a canvas (http://osdoc.cogsci.nl/python/canvas/) that displays your scale. In the run phase of your inline_script, you would then display this canvas in a while-loop. The while-statement would be something like: "while buttonpress != middle_button".

    Now the trick is to have a variable that determines the location of a pointer on this scale. In the prepare phase, you could simply create this by inserting the line "pointer = 5".
    In the while-loop in the run phase, you adjust the value of pointer based on keypresses. (http://osdoc.cogsci.nl/python/keyboard/#function-__keyboardget_key__keylistnone-timeoutnone). Hence every iteration through the loop you collect a key response, and then insert some code like this:

      if response == 'left':   # your left button
           pointer -= 1    # pointer becomes pointer minus one.
      elif response == 'right':
           pointer += 1  # pointer becomes pointer plus one.
    

    In the while loop you insert a function that creates a line on the canvas, with its x-coordinate determined by pointer: http://osdoc.cogsci.nl/python/canvas/#function-__canvasline__sx-sy-ex-ey-colornone-penwidthnone
    You just have to figure out what exact coordinates on the scale belong to which pointer value. Of course you also have to depict the scale itself. You can create this image beforehand and depict it on canvas with the canvas.image function.

    Lastly, before you update the canvas, you have to clear the previous one; otherwise the pointers will stack up. So each run through the while loop will see the following steps: 1) get a keyboard response, and update pointer; 2) exp.canvas.clear() (clears canvas, if your canvasname is "canvas" at least); 3) draw scale and draw line on scale based on pointer value. And if the subject presses the middle button, you will exit the while loop and continue to whatever you had planned next in your experiment.

    Let me know how it goes.

    Cheers,

    Josh

  • edited 11:57PM

    Hi Josh,

    thanks for your very quick and detailed reply.

    I think I'm making some stupid mistake in declaring/writing variables, since I keep getting a NameError. I tried many ways to call the 'pointer' variable in the function to draw a triangle as my pointer, but it doesn't work.

    That's what I've done so far (sorry for not using different colors).

    In the Prepare inline:

    exp.set ('pointer',510)

    exp.set ('response','')

    from openexp.canvas import canvas

    my_canvas = canvas(exp)

    my_canvas.line(100, 400, 900, 400, "white", 2)

    my_canvas.text('How happy are you?', y=200)

    my_canvas.text('not at all happy', y=500, x=100)

    my_canvas.text('moderately happy', y=500)

    my_canvas.text('extremely happy', y=500, x=900)

    my_canvas.text('5', y=450)

    my_canvas.text('0', y=450, x=100)

    my_canvas.text('10', y=450, x=900)

    my_canvas.show()

    In the Run inline:

    while 'response' != 'down':

    from openexp.keyboard import keyboard
    
    my_keyboard = keyboard(exp)
    
    response, timestamp = my_keyboard.get_key()
    
    self.get(pointer == 510)
    
    if response == 'left':
    
        pointer -= 10
    
    elif response == 'right':
    
        pointer += 10
    
    exp.canvas.clear(exp)
    
    my_canvas.show()
    
    my_canvas.line(['pointer'], 320, ['pointer'], 350, "white", 3)
    

    Thanks again in advance,
    Manuela

  • edited 11:57PM

    Hi Josh,

    forget about the previous comment. It's now working! Thanks again.

    I have a final problem...
    When pressing the middle button, it doesn't go aout from the while loop. Also, if I have another event (e.g., a sequence with a similar inline with a different question to ask participants) after that, it immediately jumps to the new event and then it comes back to the first. That's pretty weird, I might have placed the show/clear canvas in the wrong position...

    Any tip?

    Best
    Manuela

  • edited 11:57PM

    Hi Manuela,

    How did you define the middle button, and what is your while statement? As long as the logic is sound (e.g. "while buttonresponse is not middle") and you got all your values right, it should work. To give you an example: if you store the button response in a variable called 'response', and the used middle button is 'b' (I just picked something on my keyboard here), the line should look as follows

        while response != 'v':
               # your loop.
    

    If you have another question after that, it's better to consider it as a new trial and place it in a new sequence - or perhaps a new inline script and at least a new while loop (Otherwise it's going to loop everything of course!). Problems like these are often, like you suspected, of a structural nature. Further you may want to use different variable names for different types of questions. Could be that your trials are mixed in a certain way where one variable overwrites another.

    Good luck!

    Josh

  • edited 11:57PM

    Hi Josh,

    many many thanks, in the end the script seems working with one inline only. However I still don't get the final response for each question. Any tip on that? A counter? I actually don't know how to log responses.

    Here is my last try (sorry for the looong copy and paste, I had to put spaces between lines otherwise they got crowded):

    In a sequence I have an inline and a logger.

    In the Prepare phase of the inline I have:

    self.experiment.set('pointer',510)

    self.experiment.set('response','')

    self.experiment.set('False','')

    self.experiment.set('correct','')

    pointer = 510

    self.experiment.set('pointer_2',510)

    self.experiment.set('response_2','')

    self.experiment.set('False','')

    self.experiment.set('correct_2','')

    pointer_2 = 510

    from openexp.canvas import canvas

    my_canvas = canvas(exp)

    my_canvas.line(110, 400, 910, 400, "white", 2)

    my_canvas.text('How bored are you?', y=200)

    my_canvas.text('not at all bored', y=500, x=110)

    my_canvas.text('moderately bored', y=500)

    my_canvas.text('extremely bored', y=500, x=910)

    my_canvas.text('5', y=450, x=510)

    my_canvas.text('0', y=450, x=110)

    my_canvas.text('1', y=450, x=190)

    my_canvas.text('2', y=450, x=270)

    my_canvas.text('3', y=450, x=350)

    my_canvas.text('4', y=450, x=430)

    my_canvas.text('6', y=450, x=590)

    my_canvas.text('7', y=450, x=670)

    my_canvas.text('8', y=450, x=750)

    my_canvas.text('9', y=450, x=830)

    my_canvas.text('10', y=450, x=910)

    my_canvas.line(pointer, 320, pointer, 350, "white", 4)

    my_canvas.show()

    from openexp.canvas import canvas

    my_canvas_2 = canvas(exp)

    my_canvas_2.line(110, 400, 910, 400, "white", 2)

    my_canvas_2.text('Please rate your current level of arousal', y=200)

    my_canvas_2.text('calm and relaxed', y=500, x=110)

    my_canvas_2.text('moderately aroused', y=500)

    my_canvas_2.text('extremely aroused', y=500, x=910)

    my_canvas_2.text('5', y=450, x=510)

    my_canvas_2.text('0', y=450, x=110)

    my_canvas_2.text('1', y=450, x=190)

    my_canvas_2.text('2', y=450, x=270)

    my_canvas_2.text('3', y=450, x=350)

    my_canvas_2.text('4', y=450, x=430)

    my_canvas_2.text('6', y=450, x=590)

    my_canvas_2.text('7', y=450, x=670)

    my_canvas_2.text('8', y=450, x=750)

    my_canvas_2.text('9', y=450, x=830)

    my_canvas_2.text('10', y=450, x=910)

    my_canvas_2.line(pointer_2, 320, pointer_2, 350, "white", 4)

    from openexp.canvas import canvas

    my_canvas_3 = canvas(exp)

    my_canvas_3.fixdot()

    In the Run phase of the inline I have:

    self.experiment.set('pointer',510)

    self.experiment.set('response','')

    self.experiment.set('False','')

    self.experiment.set('correct','')

    self.experiment.set('pointer_2',510)

    self.experiment.set('response_2','')

    self.experiment.set('False','')

    self.experiment.set('correct_2','')

    while 'response' != 'down':

    from openexp.keyboard import keyboard
    
    my_keyboard = keyboard(exp)
    
    response, timestamp = my_keyboard.get_key()
    
    if response == 'left':
    
        correct = 0
    
        self.set_response(response=response, correct=correct)
    
        pointer -= 80
    
        my_canvas = canvas(exp)
    
        my_canvas.line(110, 400, 910, 400, "white", 2)
    
        my_canvas.text('How bored are you?', y=200)
    
        my_canvas.text('not at all bored', y=500, x=110)
    
        my_canvas.text('moderately bored', y=500)
    
        my_canvas.text('extremely bored', y=500, x=910)
    
        my_canvas.text('5', y=450, x=510)
    
        my_canvas.text('0', y=450, x=110)
    
        my_canvas.text('1', y=450, x=190)
    
        my_canvas.text('2', y=450, x=270)
    
        my_canvas.text('3', y=450, x=350)
    
        my_canvas.text('4', y=450, x=430)
    
        my_canvas.text('6', y=450, x=590)
    
        my_canvas.text('7', y=450, x=670)
    
        my_canvas.text('8', y=450, x=750)
    
        my_canvas.text('9', y=450, x=830)
    
        my_canvas.text('10', y=450, x=910)
    
        my_canvas.line(pointer, 320, pointer, 350, "white", 3)
    
        my_canvas.show()
    
    elif response == 'right':
    
        correct = 0
    
        self.set_response(response=response, correct=correct)
    
        pointer +=80
    
        my_canvas = canvas(exp)
    
        my_canvas.line(110, 400, 910, 400, "white", 2)
    
        my_canvas.text('How bored are you?', y=200)
    
        my_canvas.text('not at all bored', y=500, x=110)
    
        my_canvas.text('moderately bored', y=500)
    
        my_canvas.text('extremely bored', y=500, x=910)
    
        my_canvas.text('5', y=450, x=510)
    
        my_canvas.text('0', y=450, x=110)
    
        my_canvas.text('1', y=450, x=190)
    
        my_canvas.text('2', y=450, x=270)
    
        my_canvas.text('3', y=450, x=350)
    
        my_canvas.text('4', y=450, x=430)
    
        my_canvas.text('6', y=450, x=590)
    
        my_canvas.text('7', y=450, x=670)
    
        my_canvas.text('8', y=450, x=750)
    
        my_canvas.text('9', y=450, x=830)
    
        my_canvas.text('10', y=450, x=910)
    
        my_canvas.line(pointer, 320, pointer, 350, "white", 3)
    
        my_canvas.show()
    
    elif response == 'down':
    
        correct = 1
    
        self.set_response(response=response, correct=correct)
    
        my_canvas.clear()
    
        my_canvas_3.show()
    
        self.sleep(2000)
    
        my_canvas_3.clear()
    
        my_canvas_2.show()
    
        while 'response_2' != 'down':
    
            from openexp.keyboard import keyboard
    
            my_keyboard = keyboard(exp)
    
            response_2, timestamp = my_keyboard.get_key()
    
            if response_2 == 'left':
    
                correct_2 = 0
    
                self.set_response(response=response_2, correct_2=correct_2)
    
                pointer_2 -= 80
    
                my_canvas_2 = canvas(exp)
    
                my_canvas_2.line(110, 400, 910, 400, "white", 2)
    
                my_canvas_2.text('Please rate your current level of arousal', y=200)
    
                my_canvas_2.text('calm and relaxed', y=500, x=110)
    
                my_canvas_2.text('moderately aroused', y=500)
    
                my_canvas_2.text('extremely aroused', y=500, x=910)
    
                my_canvas_2.text('5', y=450, x=510)
    
                my_canvas_2.text('0', y=450, x=110)
    
                my_canvas_2.text('1', y=450, x=190)
    
                my_canvas_2.text('2', y=450, x=270)
    
                my_canvas_2.text('3', y=450, x=350)
    
                my_canvas_2.text('4', y=450, x=430)
    
                my_canvas_2.text('6', y=450, x=590)
    
                my_canvas_2.text('7', y=450, x=670)
    
                my_canvas_2.text('8', y=450, x=750)
    
                my_canvas_2.text('9', y=450, x=830)
    
                my_canvas_2.text('10', y=450, x=910)
    
                my_canvas_2.line(pointer_2, 320, pointer_2, 350, "white", 3)
    
                my_canvas_2.show()
    
            elif response_2 == 'right':
    
                correct_2 = 0
    
                self.set_response(response=response_2, correct_2=correct_2)
    
                pointer_2 +=80
    
                my_canvas_2 = canvas(exp)
    
                my_canvas_2.line(110, 400, 910, 400, "white", 2)
    
                my_canvas_2.text('Please rate your current level of arousal', y=200)
    
                my_canvas_2.text('calm and relaxed', y=500, x=110)
    
                my_canvas_2.text('moderately aroused', y=500)
    
                my_canvas_2.text('extremely aroused', y=500, x=910)
    
                my_canvas_2.text('5', y=450, x=510)
    
                my_canvas_2.text('0', y=450, x=110)
    
                my_canvas_2.text('1', y=450, x=190)
    
                my_canvas_2.text('2', y=450, x=270)
    
                my_canvas_2.text('3', y=450, x=350)
    
                my_canvas_2.text('4', y=450, x=430)
    
                my_canvas_2.text('6', y=450, x=590)
    
                my_canvas_2.text('7', y=450, x=670)
    
                my_canvas_2.text('8', y=450, x=750)
    
                my_canvas_2.text('9', y=450, x=830)
    
                my_canvas_2.text('10', y=450, x=910)
    
                my_canvas_2.line(pointer_2, 320, pointer_2, 350, "white", 3)
    
                my_canvas_2.show()
    
            elif response_2 == 'down':
    
                correct_2 = 1
    
                self.set_response(response=response_2, correct_2=correct_2)
    
                my_canvas_2.clear('black')
    
                my_canvas_3.show()
    
                self.sleep(2000)
    
                my_canvas_3.clear()
    

    Thanks thanks thanks,
    Manuela

  • edited 11:57PM

    Hi Manu,

    Without having read your entire discussion with Josh, let me reply to your last question:

    I actually don't know how to log responses.

    Basically, you have to options. Either you store those variables that you want to log in the instance of the experiment and let the logger item do the collecting job for you, or you send directly messages to the logging file ( do this with exp.log).

    I recommend using the first option, if it is possible. To do so, you should find a point in your script that will always be executed after the while loop was broken. Naturally, just after the while loop would be a perfect spot for that. There you only have to set your variables do be part of the experiment like so:

    exp.set('var_name',var_value).

    Now, if your logger item is put somewhere in the sequence following your inline_script, it should pick up all the responses and store them in the logfile.

    I hope this helped.

    Eduard

    Buy Me A Coffee

  • edited 11:57PM

    Thanks to all, it now nicely works.

  • ZoeZoe
    edited 11:57PM

    Hi Manuela
    I would like to build an experiment similar to yours which records a rating on a scale. In my case a scale of communicative adequacy (1 unsuccessful, 7 very successful) and a scale of accentedness (1 no accent, 9 very strong accent). I've found this thread really useful, but I have not worked with canvases before and only have limited experience of using inline scripts, which was a while ago. I was therefore wondering whether you would be willing to share your full EPrime script with me so that I can see how the whole thing fits together and then modify the output, in my case speech samples, and the scale to fit my experiment. Any help that you can provide would of course be acknowledged in any publications or presentations.
    Thanks
    Zoe Handley, Department of Education, University of York

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