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

How do I write a script to add cells to a column in places based off cells in another column? For example, I want to add cells in column 2. I want cells to only be added in places corresponding to when cells in column 1 had "s" for the code. Could anyone help with this?

asked 19 Mar '15, 16:06

user390's gravatar image

user390
16112
accept rate: 0%


I tried pasting the code here, but it isn't getting formatted neatly. I've got a side project going on to collect Datavyu scripts into a GitHub repo here: DatavyuScripts The two scripts of interest are Insert-SecondaryColumn.rb and Insert-TestColumn.rb. Play around with the parameters in the first script to tweak it to your needs. The second script can help you test run the script. It might be useful to set the clobber parameter in the first script to true while you are testing. That way you won't have to remove columns before re-running the script.

permanent link

answered 23 Mar '15, 16:53

Shohan%20Hasan's gravatar image

Shohan Hasan ♦♦
381126
accept rate: 11%

edited 23 Mar '15, 18:52

Oh, and in case you want a script without all the bells and whistles:


# Insert cells into a secondary column using selection criteria applied to cells of a primary column.
# Shohan Hasan
# March 23, 2015

require 'Datavyu_API.rb'
######################### MAIN ROUTINE ####################
begin
    pricol = getVariable('primary')
    pricells = pricol.cells.select{ |c| c.code01 == 's' }       # replace code01 with the actual code you want
    seccol = getVariable('secondary')
    for cell in pricells
        ncell = seccol.make_new_cell
        ncell.change_arg('onset',cell.onset)
        ncell.change_arg('offset',cell.offset)
    end
    setVariable(seccol)
end

To write your own scripts, please check out the Ruby API reference: http://datavyu.org/user-guide/api/reference.html and the associated guides. The key functions for this task are the API functions: getVariable, make_new_cell, change_arg, and setVariable. To filter out cells, I prefer to use the select function but you could also use a for loop like so:


for cell in pricol.cells
    if cell.code01=='s'
        ncell = seccol.make_new_cell
        ncell.change_arg('onset',cell.onset)
        ncell.change_arg('offset',cell.offset)
    end
end

Again, you will want to replace code01 with the actual code you want.

permanent link

answered 23 Mar '15, 18:19

Shohan%20Hasan's gravatar image

Shohan Hasan ♦♦
381126
accept rate: 11%

edited 24 Mar '15, 00:00

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
×7

question asked: 19 Mar '15, 16:06

question was seen: 4,169 times

last updated: 24 Mar '15, 00:00

powered by OSQA