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

Hey all,

Happy New Year. I'm having some trouble figuring out how to export my nested datavyu files. Is there any advice or sample script that I can see? Thanks for all the help!

asked 06 Jan '14, 16:17

behavior_scientist's gravatar image

behavior_sci...
0113
accept rate: 0%


Here is a script that I've used to export nested data. I've added explanations to facilitate you in making it applicable for your data.

begin

#This specifies where the files that I want to export are

filedir = "/Volumes/OpenSHAPA/EXPORT/"
filenames = Dir.new(filedir).entries

 #This makes sure that the script only works on openshapa/datavyu files
  for file in filenames
  if file.include?(".opf") and file[0].chr != '.'

  #This loads the database (file) and writes to the scripting console
  puts "LOADING DATABASE: " + filedir+file
  $db,proj = load_db(filedir+file)
  puts "SUCCESSFULLY LOADED"

  #This grabs and defines the names of the variables that you want to print/export
  id = getVariable("ID")
  trial = getVariable("Trial")
  cond = getVariable("Condition")
  explore = getVariable("Explore")

  #This defines where the exported data (in text form) will end up
  dir = File.expand_path("~/Desktop")
  out_file = File.new(dir + "/LocApTrialData.txt", "a")

  #These will loop through each cell in a given column so that it's contents 
  #for this dataset we always only had 1 id cell, 2 condition cells, and a variable number of trial and explore cells     (there was always an explore cell for each trial cell and vice versa)
  for idcell in id.cells
     for ccell in cond.cells
      for trialcell in trial.cells
        for ecell in explore.cells

          #This line checks that the cells are nested within each so that only the related cells are printed 
          #Otherwise the script would print every explore cell every time it encountered a new trial cell
          if trialcell.onset >= ccell.onset and trialcell.offset <= ccell.offset and ecell.onset == trialcell.onset

          #This specifies which arguments I want to export/print, there order, and it puts it in a tab delimited list
          out_file.syswrite (idcell.studyname + "\\t" + idcell.id + "\\t" + idcell.group + "\\t" + idcell.sex + "\\t" + idcell.order  + "\\t" + idcell.tdate  + "\\t" + idcell.bdate  + "\\t" + idcell.height  + "\\t" + idcell.weight + "\\t" + idcell.doortouch  + "\\t" + idcell.doorsquish  + "\\t" + idcell.doorshoulders  + "\\t" + idcell.calibration  + "\\t" + idcell.wallthresh  + "\\t" + idcell.dropthresh + "\\t" + idcell.falls + "\\t" + idcell.medissue + "\\t" + condvalue + "\\t" + trialcell.onset.to_s + "\\t" + trialcell.offset.to_s + "\\t" + trialcell.trial + "\\t" + trialcell.apsize + "\\t" + trialcell.torso + "\\t" + trialcell.sfr + "\\t" + ecell.strategy +   "\\n" )


          end
        end
      end
    end
  end
 end
end

end

permanent link

answered 14 Jan '14, 11:32

david's gravatar image

david ♦
143235
accept rate: 4%

edited 14 Jan '14, 11:35

Hey David,

Thanks for the help. I just tried using this but I keep getting the following error:

** SCRIPT ERRROR ** @Line -1:'org.jruby.exceptions.RaiseException: <script>:46: , unexpected kEND

I know this has something to do with my "end" at the end of the code. But I still think I have the right amount. Any idea on what it could be?

This is how I have the script written:

code:

begin

This specifies where the files that I want to export are

filedir = "/Volumes/OpenSHAPA/EXPORT/" filenames = Dir.new(filedir).entries

#This makes sure that the script only works on openshapa/datavyu files for file in filenames if file.include?(".opf") and file[0].chr != '.'

#This loads the database (file) and writes to the scripting console puts "LOADING DATABASE: " + filedir+file $db,proj = load_db(filedir+file) puts "SUCCESSFULLY LOADED"

#This grabs and defines the names of the variables that you want to print/export id = getVariable("ID") trial = getVariable("Trial") # cond = getVariable("Condition") # explore = getVariable("Explore") comm = getVariable("Comments") notes = getVariable("Notes") relia = getVariable("RelTrial")

#This defines where the exported data (in text form) will end up dir = File.expand_path("~/Desktop") out_file = File.new(dir + "/LocApTrialData.txt", "a")

#These will loop through each cell in a given column so that it's contents #for this dataset we always only had 1 id cell, 2 condition cells, and a variable number of trial and explore cells (there was always an explore cell for each trial cell and vice versa) for idcell in id.cells for trialcell in trial.cells for commcell in comm.cells for notescell in notes.cells for reliacell in relia.cells

      #This line checks that the cells are nested within each so that only the related cells are printed 
      #Otherwise the script would print every explore cell every time it encountered a new trial cell
      if trialcell.onset >= ccell.onset and trialcell.offset <= ccell.offset and ecell.onset == trialcell.onset

      #This specifies which arguments I want to export/print, there order, and it puts it in a tab delimited list
      out_file.syswrite (idcell.studyname + "\\\\t" + idcell.id# + "\\\\t" + idcell.sex + "\\\\t" + idcell.birthday + "\\\\t" + idcell.testdate  + "\\\\t" + idcell.cond  + "\\\\t" + idcell.trial.coder  + "\\\\t" + idcell.reltrial.coder  + "\\\\n" )

end end end end end end end end

/code

permanent link

answered 13 Feb '14, 15:29

behavior_scientist's gravatar image

behavior_sci...
0113
accept rate: 0%

edited 13 Feb '14, 15:31

Your script is missing 1 end as is. However, that's because there is a line that is unnecessary to your script "if trialcell.onset >= ccell.onset and trialcell.offset <= ccell.offset and ecell.onset == trialcell.onset". I believe this was a carry over from the example script because it doesn't look like your files have condition or explore columns. Removing that line should get rid of that error message.

Depending on the layout of the files that you're trying to print from, you may still encounter problems (similar to the scenario described in the explanation of the line referenced in the above paragraph). If the script continues to be an issue, you can send me the updated script and an example file that you're trying to print data from.

permanent link

answered 15 Feb '14, 13:36

david's gravatar image

david ♦
143235
accept rate: 4%

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:

×24
×9
×1

question asked: 06 Jan '14, 16:17

question was seen: 3,757 times

last updated: 15 Feb '14, 13:36

powered by OSQA