Howdy, Stranger!

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

Supported by

merge files

Dear all,

in my experiment participants take part in a training task: they have to exercise a specific task 4 times in 2 weeks. This means that each participant has 4 datafiles (for each training) and this could get quite chaotic. Is it possible to merge all datafiles into one single file?
The difficulty of the task varies according to their performance. It would be great if I could use their last value of the previous session and use it as starting point for the next session (e.g. the speed of the stimulus onset varies according to their performance; let's say the last value of the previous session was 400ms then I would like to use this value - i.e. 400ms - as the starting point for the next session). I guess this problem goes hand in hand with my question above..

Thank you for your help! If you need more information please do ask!
Cheers,
Erwin

Comments

  • edited June 2017

    For merging data files there is a nice program available by Daniel Schreij:
    http://forum.cogsci.nl/index.php?p=/discussion/697/open-how-to-merge-my-csv-files-with-data-merger

    The program can be found at the bottom of this page:
    http://osdoc.cogsci.nl/3.1/manual/logging/

    Regarding the reuse of a variable on separate days: this seems a bit more difficult, there are three ways I can see:
    1 read the data out of the original log file at the start of the experiment
    2 read the data out of a specially created csv file
    3 display the value at the end of the experiment + write it down on a piece of paper.

    Option 3 is by far the quickest and simplest, but not a lot of fun.
    Option 1 is very similar to option 2, but a bit more complex, so I'll elaborate on option 2.

    At the end of your experiment you could insert an inline script which logs the variable of interest:
    log_path ='C:\etc etc \some folder'
    variable_of_interest = 'some_value'
    f = open('%s\value_file_%s.csv' %(log_path, var.subject_nr), 'w')
    f.write(variable_of_interest)
    f.close()

    Then at the start of your experiment you read in the correct file:

    log_path ='C:\etc etc \\some folder'
    F = 'default'
    if var.subject_nr%10 !=1:
        name = var.subject_nr-1
        f = open('%s\\value_file_%s.csv' %(log_path,name),'r+')
        for row in f:
            F = row
    

    'F' is now the variable you had logged in the last session_ if current session number is not 1._ Note that
    obtaining the correct file depends on how you code the subject numbers, the current idea that is used is:
    011, 012, 013, 014, 021, 022, etc, ...
    The subject number is placed at the beginning and the session number at the end.

    If you decide on option 3; you can use a 'form_text _input' at the start, and here you could enter the value of the previous session.
    http://osdoc.cogsci.nl/3.1/manual/forms/readymade/

    Hope this helps

  • Dear Roelof,

    thank you so much for your help! I implemented your code in my experiment and it saves the new csv file (\value_file_11) in the defined folder. So this works just fine! My only problem is the variable of interest. I'm not quite sure what I have to insert into this command

    variable_of_interest = 'some_value'

    The variable I'm using is a stop signal delay (SSD) which changes acoording to the performance of the participant (increases when the answer is correct, decreases when the answer is incorrect). If I'm not mistaken I have to enter the variable in quotation marks. But wouldn't that just save the variable I entered (e.g. if I enter 200ms, than it would save 200ms no matter what)? I'm sorry if this question is somewhat silly, but I'm still at the beginning of understanding python :)

    Cheers,
    Erwin

  • This depends a little bit on how where/how your variable is initiated, usually the name of the variable (I guess SSD) in combination with '.var' should work.
    See if you can print the variable to the debug window by entering:

    print var.SSD

    in an inline script, if this prints the correct value then you can also use var.SSD as the 'variable_of_interest':
    variable_of_interest = var.SSD

    If this doesn't work let me know, good luck

  • Dear Roelof,

    thanks again for your help! The SSD (var.SSD) is initiated at the beginning of my experiment. I tried using var.SSD as the 'variable_of_interest': variable_of_interest = var.SSD but unfortunately I get this error message:

    "exception message: expected a string or other character buffer object"

    Cheers,
    Erwin

  • Ah, yes, apologies, the write function apparently only likes string objects, you will have to transform SSD to a string:
    str(variable_of_interest)

    when reading it back in also make sure to tranform it back to a number
    by using either:
    int(F) for integer values or
    float(F) for precise numbers

  • You guys could also check out pickles

    @erwinewirne: Don't forget to define the Variable var.SSD in the beginning of your code in such a way, that it won't overwrite the value that you load into Opensesame.

    Just my 2 cents....

    Buy Me A Coffee

  • Dear Roelof, dear Eduard

    Thank you both so much, you really helped me alot! Sorry for the late answer, I wanted to check if everything works so I could give you feedback :)

    @Roelof: the transformation to a string str(variable_of_interest) solved the problem, thanks!

    @eduard: thanks for your input! I use an adaptive SSD (the intervall changes, depending on the answers the participants give) and I defined the code in a seperate inline script
    I added an if statement so the var.SSD won't overwrite the value of the csv-file:

    if var.subject_nr%10 !=1:
        var.SSD = F

    I don't know if this is the best solution but it seems to work..

    Cheers,
    Erwin

Sign In or Register to comment.