Announcing the new Datavyu v1.3.6 with enhanced features and transcription support!

Hello. We have received a script that collects and prints raw data from our openSHAPA coding spreadsheet. Following running the script, a message shows up that says "Printed to ~/Desktop/PLPStimLook.txt" (with no error message) however nothing saves on the desktop. Even when trying to direct it elsewhere it does not save anywhere on the computer. I have attached the parts of the script below that mention the directory which is where we've been changing the names to find the documents. We'd appreciate any suggestions as to why this is not being saved onto our computer. Thank you.

begin # Define directory where all of the files you want to export are. # Usually copy them to this location rather than run on original directory in case of problems. filedir = "/Users/lakustal/Desktop/" # Define Ruby variable for each opf file. filenames = Dir.new(filedir).entries

-------------------------(Later in script)--------------------------------------------------------

Define directory where we want to export txt file to.

  printdir = File.expand_path("~/Desktop")
  # Name file we want to export data to.
  # The "a+" means every run of this script will add more data to bottom of txt file.
  out_file = File.new(printdir + "/PLPStimLook.txt", "a+")

asked 31 Jul '13, 15:00

Lakusta%20Lab's gravatar image

Lakusta Lab
71121214
accept rate: 0%

edited 31 Jul '13, 18:46

Jesse's gravatar image

Jesse ♦
11181015


Ok, I have an idea what might be going on here. I think what's happening is that there are no .opf files in the directory where you're telling it to look for them. Since the part where you create the output file to be written to is after the if statement that checks that each file is a .opf, it never gets far enough to create the file. It checks each thing on the desktop, each fails that if statement in turn, then it finishes. There are no errors, it just never gets past that if statement. I'm thinking that's it since the script is written to tell you when it loads each file, and it sounds like you're never seeing that message. Check that the first file path, the one set to be "filedir" is complete - if your files are actually in a subfolder, add that to the file path definition.

One other thing I noticed: You don't have to convert arguments like subjnum into strings to print them. Onsets, offsets, and ordinals are all stored as numbers. Anything typed into an argument ruby will consider to be a string, even if it's a number. This is important to keep in mind if you ever want to do math on something in an argument, or compare numbers in an argument. For example, the following won't work properly, because ruby will treat it like a string (even though you typed a numeral in).

if idcell.weight < 50

Instead you need to convert it to be a number like this:

if idcell.weight.to_f < 50.

permanent link

answered 31 Jul '13, 19:48

WhitneyCole's gravatar image

WhitneyCole ♦
417239
accept rate: 21%

Hm. At first glance, I don't see a problem in the sections you've posted. Can you post the whole script for us to look at? And can you post it as code instead of text (highlight it and click the "code sample" button in the bar along the top of the text box)? That would make it a little easier to read.

permanent link

answered 31 Jul '13, 17:03

WhitneyCole's gravatar image

WhitneyCole ♦
417239
accept rate: 21%

Thank you very much for your response (to both questions). Below I have copied the full script.

begin
      # Define directory where all of the files you want to export are.
      # Usually copy them to this location rather than run on original directory in case of problems.
      filedir = "/Users/lakustal/Desktop/"
      # Define Ruby variable for each opf file.
      filenames = Dir.new(filedir).entries

  # Loop over all files in the directory
  for file in filenames
    # Only pull opf files and no others
    if file.include?(".opf")

  # Load files one at a time
  puts "LOADING DATABASE: " + filedir+file
  $db,proj = load_db(filedir+file)
  puts "SUCCESSFULLY LOADED"

  # Define Ruby variables for each of the variables/columns we want to get data from to export
  sub = getVariable("SubInfo")
  stim = getVariable("Stim")
  look = getVariable("Look")

  # Define directory where we want to export txt file to.
  printdir = File.expand_path("~/Desktop")
  # Name file we want to export data to.
  # The "a+" means every run of this script will add more data to bottom of txt file.
  out_file = File.new(printdir + "/PLPStimLook.txt", "a+")

  # Loop over all cells in subinfo
  for subcell in sub.cells
    # Loop over all cells in stim
    for stimcell in stim.cells
        # Bind each stim cell to each subinfo cell using onsets and offsets  
        # All stim cells will have onsets greater than subinfo cell onset, and offsets less than subinfo cell offset.
        if stimcell.onset >= subcell.onset and stimcell.offset <= subcell.offset
          # Loop over all look cells.
          for lookcell in look.cells
            # Bind each look cell to each stim cell using onsets and offsets  
            # All look cells will have onsets greater than or equal to their matching stim cell onset,
            # and offsets less than or equal to their matching stum cell offset.
            if lookcell.onset >= stimcell.onset and lookcell.offset <= stimcell.offset
               # Write to the outfile each of the arguments we want, separated by tab, and ending with a new line
               # Any output that would be a numeral needs to be converted to a string using .to_s
               # Onset and offset are exported as ms counts, so need to be subtracted in SPSS/Excel for durations.
               # Remove all punctuation and capitals from arguments.
               # If argument name starts with a numeral need to append underscore to front
               # So 1/2/3/4 becomes _1234, Goal/source becomes goalsource.
               out_file.syswrite (subcell.subnum.to_s + "\\t" + subcell.age.to_s + "\\t" + subcell.sex + "\\t" + subcell.cond + "\\t" + subcell.goalsource  + "\\t" + stimcell.trial.to_s +  "\\t" + stimcell.aud + "\\t" + stimcell.prep + "\\t" + lookcell.ordinal.to_s + "\\t" + lookcell.onset.to_s + "\\t" + lookcell.offset.to_s + "\\t" + lookcell._12ac + "\\n" )
            # Now count up each FOR or IF in loop through cells part and match it with an END
            end
          end
        end
    end
  end
# Now count up each FOR or IF in loop through files part and match it with an END
end

end

# Change to remind you of name and location of file you specified above. puts "Printed to ~/Desktop/PLPStimLook.txt"

Ends Ruby script

end

permanent link

answered 31 Jul '13, 17:24

Lakusta%20Lab's gravatar image

Lakusta Lab
71121214
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×46
×2

question asked: 31 Jul '13, 15:00

question was seen: 3,890 times

last updated: 31 Jul '13, 19:48

powered by OSQA