Howdy, Stranger!

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

Supported by

[solved] Inline Python Script Capabilities

edited July 2015 in OpenSesame

I feel that OpenSesame primitives don't expose the functionality I am looking for in the experiment I am developing. However, being able to drop into Python should resolve that, providing the following are possible:

  1. Time logging at various points within an item: I want to show an item with multiple states, which the user advances through by mouse clicks, where I want to record the time spent on each state. (AFAIK, I can't do this with an OpenSesame loop because the number of states available, each time this item is shown, will be variable.) Is it possible to programatically log a time on-demand?

  2. When I have progressed through all the states in said item, I want to then proceed to the next item (which will just be a regular OpenSesame item); again by mouse click. What command is used to advance to the next item?

  3. Will I be able to open a SQLite database from the OpenSesame file pool? I feel like experiment.get_file should do the job -- and import sqlite3 appears to work -- but I'm interested to know if anyone has tried this.

I'm sure I'll have more questions (sorry!)...

Many thanks;
Christopher

Comments

  • edited 1:55AM

    Hi Christopher,

    Time logging at various points within an item: I want to show an item with multiple states, which the user advances through by mouse clicks, where I want to record the time spent on each state. (AFAIK, I can't do this with an OpenSesame loop because the number of states available, each time this item is shown, will be variable.) Is it possible to programatically log a time on-demand?

    The specific solution would depend on what exactly you want to do, but in general it is very easy to log a timestamp using an inline_script object. For example:

    exp.set('my_custom_timestamp', self.time())
    

    This will create an experimental variable my_custom_timestamp which holds the current time.

    When I have progressed through all the states in said item, I want to then proceed to the next item (which will just be a regular OpenSesame item); again by mouse click. What command is used to advance to the next item?

    Again, the question is a bit too generic for a specific answer. In general, the way to pause an experiment until a mouse click is to insert a mouse_response item at the point that you want to pause.

    Will I be able to open a SQLite database from the OpenSesame file pool? I feel like experiment.get_file should do the job -- and import sqlite3 appears to work -- but I'm interested to know if anyone has tried this.

    Sure. OpenSesame uses a regular Python interpreter, so you can use sqlite3 in an inline_script item in the same way as you would in any normal Python script.

    Good luck with your experiment. As a tip: If you have further questions, please try to be as specific as possible, that way it's easier to give a useful answer!

    Cheers,
    Sebastiaan

  • edited 1:55AM

    Thanks, Sebastiaan

    My first two queries are related, so let me try to be a bit more specific.

    I'm trying to create a self-paced reading task. The way I can see this working is to have a single item that displays successive words, controlled by mouse click. The reason for a single item (rather than multiple; one for each word) is that the sentences will be different lengths and (AFAIK) I can't dynamically create items or control loop variables, on-the-fly. (There are other considerations, such as positioning and various counterbalancing measures, hence preferring to use SQLite to store the data.)

    So, let's say the item gets the sentence data as this| is| my| sentence, where the | delimit the word boundaries. I can easily split this out into a list and then I'd like to show each element, one at a time, then proceed to the next OpenSesame item after the last element is shown. Like so:

    //== ITEM 1 =================\\
    ||                           ||
    ||  +---------------------+  ||
    ||  |                     |  ||
    ||  | this                |  ||
    ||  |                     |  ||
    ||  +---------------------+  ||
    ||             | click       ||
    ||             V             ||
    ||  +---------------------+  ||
    ||  |                     |  ||
    ||  |      is             |  ||
    ||  |                     |  ||
    ||  +---------------------+  ||
    ||             | click       ||
    ||             V             ||
    ||  +---------------------+  ||
    ||  |                     |  ||
    ||  |         my          |  ||
    ||  |                     |  ||
    ||  +---------------------+  ||
    ||             | click       ||
    ||             V             ||
    ||  +---------------------+  ||
    ||  |                     |  ||
    ||  |            sentence |  ||
    ||  |                     |  ||
    ||  +---------------------+  ||
    ||             | click       ||
    \\============ | ============//
                   |
    //== ITEM 2 == | ============\\
    ||             V             ||
    ||  +---------------------+  ||
    ||  |                     |  ||
    ||  |  [Some other item]  |  ||
    ||  |                     |  ||
    ||  +---------------------+  ||
    ||                           ||
    \\===========================//
    

    Where the "double-lined boxes" represent OpenSesame items and the "single-lined boxes" represent screen state.

    With regard to the timing, if I use exp.set('my_custom_timestamp', self.time()) on each state change, then that will override the variable. As such, I'd need a different variable for each screen state (presumably I can't create a list here). Would it be possible to instead trigger a logger event programmatically, so that I can store the timestamp into a single variable, but each screen state gets its own line in the output CSV? (Otherwise, my solution would be to "fake" a list by concatenating the time into the same variable and then postprocessing the CSV to deserialise it.)

    I hope that's more clear. Let me know if I can clarify anything further.

    Thanks again :)
    Chris

  • edited 1:55AM

    Hi Chris,

    Like you said - each trial you create a list with all the words of a given sentence (e.g. sentence_list = ["this", "is", "an", "example"]). Now, we can run the trial by using a for-loop (in the run-phase of an inline script), where the logic would be something like this:

       from openexp.mouse import mouse
       my_mouse = mouse(exp)
    
       sentence_responsetimes = []
       mouse_clicked = False
       starting_coordinate = 50 # (or something)
       for word in range(0, len(sentence_list)):
               canvas.clear()
               canvas.text(sentence_list[word]), x=starting_coordinate)
               starting_coordinate += canvas.text_size(sentence_list[word]+" ") 
               canvas.show()
               start_time = self.time()
               while mouse_clicked == False:
                     if my_mouse.flush() == True:
                           responsetime = self.time() - start_time
                           sentence_responsetimes.append(responsetime)
                           mouse_clicked = True
    

    Hope this helps.

    Cheers,

    Josh

  • edited 1:55AM

    Thank you, Josh: That's very very helpful :)

    Would I then just call exp.set('someResponseVar', sentence_responsetimes) after the for-loop? That is, will the list be serialised to a string automatically by the logger, so I get a CSV that looks like (for example):

    var1  var2  var3  someResponseVar
    ----- ----- ----- ----------------
    foo   bar   quux  [10,12,9,14]
    

    (i.e., the CSV row looks like "foo","bar","quux","[10,12,9,14]")

    Thanks;
    Chris

  • edited 1:55AM

    No problem :)

    And exactly; you'll have to use exp.set after the for-loop to have the list logged. Of course you could also divide the list into separate columns for each word, by setting separate variables (e.g. word1 word2) instead of the list - but yeah you get the idea.

    Good luck and have fun!

    Josh

  • edited 1:55AM

    I just tried your code out, Josh and, modulo a few typos, it worked a charm :) Thank you again!

    For others' sake, the diff on the typos is as follows:

    ---        canvas.text(sentence_list[word]), x=starting_coordinate)
    +++        canvas.text(sentence_list[word], x=starting_coordinate)
    
    ---        starting_coordinate += canvas.text_size(sentence_list[word]+" ")
    +++        starting_coordinate += canvas.text_size(sentence_list[word]+" ")[0]
    

    Also, the mouse_clicked=False statement needs to appear inside the for-loop (e.g., as the first statement), otherwise it doesn't get reset after the first click and cycles through the remaining words in the list instantaneously.

    Anyway, this is great :) Cheers!

  • edited 1:55AM

    Great that you were able to filter out the typo's yourself! I just wrote up something quickly, but should've double-checked at least, I admit :)

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