Howdy, Stranger!

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

Supported by

[Solved] Mouse : how to collect plural mouse response in one sequence

edited May 2014 in OpenSesame

Hello,

Well, I'll try my best to be clear as possible. I'm sorry for the english that will follow !
So, we -our team on the project- want to make an plural modal-sensoriel experiment. We have 6 round items display in a circle like this :

image

where color are display (here black) randomly on the 6 items, one by one each 300ms, 5 times for the first sequence, 6 times the second to 10 times for the fifth sequence.
So what we want to do is, after the first sequence display, people can click on the items who have been colored and they have to do it in the right order. When they clicked on 5 items, it goes to the second sequence. Then for the second they'll have to click on 6 items to go on the third etc.
For the display of color that's ok, but I don't know how to do with mouse_responses.

I want to do something like this :
After the color displayed, it's time to the people to click on the right order of each item who colored. So when they click on an item, a counter save the click (if people click somewhere else, that doens't count), so that when it requires 5 click the counter will compare to it and let the experiment goes to the second sequence.
But I don't know how can click can be count when it click on a item or not.

Here was my first try, where I wanted button_cliked to dis-increment after clicks.


from openexp.mouse import mouse from openexp.canvas import canvas button_cliked=5 #(click available) my_mouse = mouse(exp, visible=True) my_canvas = canvas(exp) while True: button, position, timestamp = my_mouse.get_click() if button != None and button_cliked==0: break pos, time = my_mouse.get_pos() my_canvas.fixdot(pos[0], pos[1]) x, y = pos my_canvas.clear() if my_mouse.get_click()== True: button_cliked=-1 my_canvas.text(button_cliked, y=50) my_canvas.text('The cursor was at (%d, %d)' % (x, y), y=60) my_canvas.show()

So if I want to do what I told before my first try, in order to calcul if the click is on an item or not, should I use canvas? "draw circle"? or widget but just after presentation, when asking people to click?
Here is the experiment; I put the code you saw on the ___inline_script.

image

Is there a way to do this?

Thanks a lot,

Sincerely

Zalian

Comments

  • edited 1:24PM

    Hi Zalian,

    Thanks for taking the time to explain your problem clearly and in detail! That's really helpful, for me as well as for other people who may be facing the same problem.

    Below you see a script that collects 5 mouse clicks, while checking whether these clicks are sufficiently close to a list of target positions. Although you'll probably want to tweak some aspects of the script, this is essentially what you need, right?

    I have added code comments to explain what the script does, so please take a good look at those and try to figure out the logic of the script. Looking at your script above, you already know a bit of Python, so this shouldn't be too difficult.

    Cheers!
    Sebastiaan

    from openexp.mouse import mouse
    from math import sqrt
    # Create a mouse object
    my_mouse = mouse(exp, visible=True)
    # Define all valid target positions as a list of (x, y) coordinates. These
    # coordinates are relative to the top-left of the screen, just like the
    # coordinates returned by `mouse.get_click()`.
    target_positions = [
        (512, 384),
        (576, 384),
        (640, 384),
        (704, 384),
        (768, 384)
        ]
    # The maximum distance in pixels that a click can be from a target position
    max_err = 10
    # The number of clicks to collect
    max_click = 5
    # Loop until we have collected all clicks
    n_click = 0
    while n_click < max_click:
        # Get a click and extract the position
        button, position, timestamp = my_mouse.get_click()
        cursor_x, cursor_y = position
        # Walk through all target positions to check if the click was on a target
        hit = False
        for target_x, target_y in target_positions:
            err = sqrt((target_x-cursor_x)**2+(target_y-cursor_y)**2)
            if err <= max_err:
                # If the click was on a target, set the click coordinates and
                # decrease the number of clicks that we still need to collect
                exp.set('click_%d_x' % n_click, target_x)
                exp.set('click_%d_y' % n_click, target_y)
                n_click += 1
                hit = True
        if not hit:
            # Optionally do something if a click was not on a target.
            pass
    
  • edited February 2014

    Dear Sebastian,

    Sorry for answer so lately, but better late than never !
    Thanks a LOT for your help. I understood everything and the code works properly.

    We have now an other problem. We want sound to be play in same time a circle is colored, but I don't really know how to make the architecture...

    I tried like this image

    So I change the sequence repeat to 1 and manually attribute color on one circle in each sketchpad like black grey grey grey grey grey for the first sketchpad and grey blue grey grey grey grey for the second etc.
    But the sound is not sync with the displaying of a color...

    How can I do it? I heard about PyAudio but that's sound difficult...
    I'm sorry, I'd maybe rather made an other topic?

    Thanks a lot again Sebastian !

    Zalian

  • edited 1:24PM

    Hi Zalian,

    In principle, this should work. If you find that sound is lagging, which is indeed a known problem, then you can try tweaking the sampler-back-end settings (General tab → Back-end settings → Sampler). Notably, reducing the buffer size, sampling frequency, and sampling size should reduce temporal jitter, although it also increases the risk of sound distortions. (It's a trade-off.)

    What kind of temporal accuracy are you aiming for? If a jitter of something around 30 ms is acceptable, then you should probably be fine.

    Cheers,
    Sebastiaan

  • edited February 2014

    Hi Sebsatiaan,

    Thanks for your help again !
    We find a solution much better : the parallel function that can execute plural item in one time !

    A new problem appear, with the inline_script.
    We would like to save the order people clicked on each circle. So here what I did :

    from openexp.mouse import mouse
    from math import sqrt
    
    my_mouse = mouse(exp, visible=True)
    
    target_positions = [
        (512, 168),
        (701, 274),
        (701, 490),
        (512, 601),
        (323, 490),
        (324, 272)
        ]
    target_order = [6,3,2,3,5] #the good answer of order
    target_user_order = [] #wait for user's answer
    
    max_err = 29
    
    max_click = 5
    
    n_click = 0
    
    while n_click < max_click:
    
        button, position, timestamp = my_mouse.get_click()
        cursor_x, cursor_y = position
        position, timestamp = my_mouse.get_pos()
    
        hit = False
        for target_x, target_y in target_positions:
            err = sqrt((target_x-cursor_x)**2+(target_y-cursor_y)**2)
            if err <= max_err:
                if target_x == target_positions[0][0] and target_y == target_positions[0][1]:
                    target_user_order.append(1) #So if user clicked on the first item, we store it on the target_user_order list.
                elif target_x == target_positions[1][0] and target_y == target_positions[1][1]:
                    target_user_order.append(2) #or on the second item etc.
                elif target_x == target_positions[2][0] and target_y == target_positions[2][1]:
                    target_user_order.append(3)
                elif target_x == target_positions[3][0] and target_y == target_positions[3][1]:
                    target_user_order.append(4)
                elif target_x == target_positions[4][0] and target_y == target_positions[4][1]:
                    target_user_order.append(5)
                elif target_x == target_positions[5][0] and target_y == target_positions[5][1]:
                    target_user_order.append(6)
                            #after the fifth click, a comparison (that I didn't write for now) to the target_order to see if he's true or not
                exp.set('click_%d_x' % n_click, target_x)
                exp.set('click_%d_y' % n_click, target_y)
                n_click += 1
                hit = True
        if not hit:
            # Optionally do something if a click was not on a target.
        pass
    

    But I don't know why, I can't execute the code !!! The blue dotted line appear like this and make my code bug....... How can I fix it??

    image
    image

    Thanks again :)

  • edited 1:24PM

    Well I'm back. I tried with the new version 2.8.0 but it wasn't working either...
    So I just re-write all my code without copy/paste and it's now working. But that's very tiresome anyway !

    PS : I saw somewhere that they were indent problem with MAC. I'm on windows 7, just to say.

  • edited 1:24PM

    Hi Zalian,

    You cannot mix and match tab-based indentation and space-based indentation in Python. If you do, for example by pasting a script from a webpage, you'll get a syntax error like the one you're seeing.

    This is inherent to Python and not a bug in OpenSesame. It is a bit annoying though, but what you can do, for example, is replace all occurrences of four spaces with a single tab using the search-replace function in OpenSesame (or another editor).

    Cheers!
    Sebastiaan

  • edited March 2014

    Hello !

    My bad Sebastiaan. I had tried to use the replace function as you say but still didn't work.

    Our program is now working but there's still one problem which is actually pretty annoying.

    I put logger at each end of modalite (you can see below the first modalite), but it didn't write any count time.

    image

    I also upload the .cvs that you can see how the log have worked.

    http://demo.ovh.eu/fr/09b0cb047a07edcc81f309e1d98d0108/

    I tried only with the 1ere_modalite and put other in "never", but I can see that the logger save everything, also others who are "never" launch..

    I guess the problem is because of the "architecture" of our program?

    How can I do for this? Do I need to use inline_script again with some times functions or something?

    Edit : I forgot to explain exactly what we would like: we would like the time people do when they have to click on the items (during each whole inline_script), and time between each click if it's possible.

    Thanks again for your answer Sebastiaan !

  • edited 1:24PM

    Hi Zalian,

    Do I understand correctly that you want to log the timestamps of the mouse clicks that you're collecting in the inline_script? To do so, you have to save timestamp explicitly as an experimental variables using exp.set() (just like you did with the click_[n]_x variables), like so:

    # (...)
    # Snippet from the full script in the post above
    exp.set('timestamp_%d' % n_click, timestamp) # Set the timestamp
    exp.set('click_%d_x' % n_click, target_x)
    exp.set('click_%d_y' % n_click, target_y)
    n_click += 1
    hit = True
    # (...)
    

    Does that make sense?

    Note that the timestamp is the absolute timestamp, usually measured from the beginning of the experiment (but that depends on the back-end).

    Cheers,
    Sebastuaab

  • edited March 2014

    Hi,

    Ok, I think I get it. But, I still don't understand something which may be easy.. How do I use this timestamp?! How do I convert it to real time? How do I know "the beginning of the experiment?"

    I hope this is the last time, I don't want to bother you anymore :p Thanks a lot anyway !!

    Edit : I did read the doc on timing, search on the forum, I've tried to understand the values of timestamp, to convert it, but I still not get it. How do I read and use this timestamp?

  • edited 1:24PM

    How do I use this timestamp?! How do I convert it to real time? How do I know "the beginning of the experiment?"

    Every event has a timestamp (always in ms). So, for example, if you want to know the interval between two clicks, you simply subtract the timestamp of the first click from the timestamp of the second click. And if you want to know the time between the presentation of a sketchpad and the moment that the user clicked, you subtract the timestamp of the sketchpad (i.e. the time_[item name] variable) from the timestamp of the mouseclick. Etcetera. You can do this either on-line, in the experiment, or afterwards when analyzing the data.

    Does that make sense? The absolute time is usually not important, you're just interested in the time difference between two events, which you can get by subtracting timestamps.

  • edited 1:24PM

    Hello !

    Here I am again, 2 month later lol
    Just to say thank you, you helped us a lot. We had a nice working experiment thanks to you !
    I just give you 5€ for your software and for your help =)

    Bye !

  • edited 1:24PM

    Thank you for your donation, and glad to hear you got things working! :-)

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