Please use our GitHub Issues page for all new support inquiries. If you need to contact us directly, please e-mail [email protected]

How can I import data from another application (say, a motion tracker, a gait carpet, or any text file) into OpenSHAPA?

asked 16 Jan '12, 16:05

Jesse's gravatar image

Jesse ♦
accept rate: 53%

This script shows how to autofill data in multiple openSHAPA files from a single csv file (contains one row per subject). The I'm matching a subject identifier from the row in the csv file to the filename, and then writing the data. I'm happy to answer questions about this or give more examples if anyone needs them.

  dir = File.expand_path("~/Desktop")
  opsfiledir = "/OpenSHAPA/"
  opsfiles = + opsfiledir).entries

    #read in data, split into rows
    f = ""
    infile = + "/IDDATA.csv", "r")   
      infile.each_line() do |row|
        f += row
    infile = f.split(/[\r\n]/)

  #iterate through openshapa files
  for file in opsfiles
    if file.include?(".opf") and file[0].chr != '.'
      $db,proj = load_db(dir + opsfiledir + file)
      puts "SUCCESSFULLY LOADED SUBJECT " + file[9..10]
      id = getVariable("id")
          #find row to match subject 
          for row in infile
            row = row[1..-2]
             #split each row into columns 
            columns = row.split("\",\"")      
              if file[9..10].to_i == columns[9].to_i #matches openshapa file to subject's data
                    puts "Writing Data"
                    idcell = id.make_new_cell()
                    idcell.change_arg("calibration", columns[0]) #set each argument
                    idcell.change_arg("firstaction", columns[1])
                    idcell.change_arg("firstdec", columns[2])
                    idcell.change_arg("heightap", columns[3])
                    idcell.change_arg("heightstad", columns[4])
                    idcell.change_arg("id", columns[9])
                    idcell.change_arg("shoulders", columns[10])
                    idcell.change_arg("tdate", columns[11])
                    idcell.change_arg("weight", columns[16])
                    idcell.change_arg("bdate", columns[17])
                    idcell.change_arg("sex", columns[18])
        setVariable("id",id) #save id to database
        save_db(dir + opsfiledir + file) #save database
        puts "Successfully saved database for S# " + file[9..10]
permanent link

answered 02 Mar '12, 07:07

JohnFranchak's gravatar image

JohnFranchak ♦
accept rate: 17%

Your answer
toggle preview

Follow this question

By Email:

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



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "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:


question asked: 16 Jan '12, 16:05

question was seen: 4,518 times

last updated: 02 Mar '12, 07:07

powered by OSQA