This repository was archived by the owner on Feb 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdd-Columns.rb
More file actions
46 lines (42 loc) · 1.46 KB
/
Copy pathAdd-Columns.rb
File metadata and controls
46 lines (42 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Add column/arg mappings. Default behavior for existing columns is to append additional args.
# Shohan Hasan
# NYU Infant Action Lab
require 'Datavyu_API.rb'
########################################
############## PARAMS ################
# Column-arg mappings. This is an associative array that pairs the name of the column
# to a list of codes to add to that column. All codes on the righthand side of each mapping should
# be inside the brackets [] and separated by commas.
myMap = {
'id' => ['id_number','exp_date','birth_date','sex_mf'],
'task' => ['condition_xyz'],
'trial' => ['trial_num','result_yn']
}
# If replace is set to true, any existing columns with the same names will be replaced
# with a blank new column. YOU CAN NOT UNDO THIS. When false, only appends argnames
# that are new.
replace = false
verbose = 1
############## MAIN ROUTINE ################
begin
varList = getVariableList()
columnsAdded = 0
myMap.each_pair{
|colname,argnames|
if not replace and varList.include?(colname)
puts "#{colname} already exists. Checking for codes to add." if verbose > 0
col = getVariable(colname)
newargs = argnames - col.arglist
newargs.each{ |narg| col.add_arg(narg) }
else
puts "Adding column #{colname}" if verbose > 0
columnsAdded+=1
col = createVariable(colname,*argnames)
end
setVariable(col)
}
puts "Finished. Added #{columnsAdded} new column(s)." if verbose > 0
rescue StandardError => e
puts e.message
puts e.backtrace
end