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 pathCheck-Codes.rb
More file actions
86 lines (76 loc) · 2.35 KB
/
Copy pathCheck-Codes.rb
File metadata and controls
86 lines (76 loc) · 2.35 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# Check codes in a spreadsheet. Written for multi-column support using associative array.
# 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 = {
# Columns
'id' => {
# Code names # Acceptable values
'sex_mf' => ['m','f']
},
'task' => {
'condition_xyz' => ['x','y','z']
},
'trial' => {
'result_yn' => ['y','n']
}
}
verbose = 1 # zero will be useless until writing out to file is implemented
##############################################
############## MAIN ROUTINE ################
begin
varList = getVariableList() # Fetch list of columns from spreadsheet
# Remove columns in myMap that don't exist in the spreadsheet
# Also prune out mappings that don't have any codes defined.
myMap.delete_if{
|colname,codemap|
if (not varList.include?(colname))
puts "#{colname} does not exist in spreadsheet. Skipping it." if verbose > 0
true
elsif codemap.empty?
puts "#{colname} contains no codes. Skipping it." if verbose > 0
true
else
false
end
}
# Map column names to column objects from the database
cols = {}
myMap.keys.each{
|x|
cols[x] = getVariable(x)
}
myMap.each_pair{
|colname,codemap|
col = cols[colname]
puts "Checking column: #{colname}" if verbose > 0
# Get the list of cell objects
cells = col.cells
# Get the list of existing codes (column arglist)
arglist = col.arglist
# For each cell, check the specified codes against the list of valid codes
for cell in cells
codemap.each_pair{
|codename,legalValues|
# Check the column's arglist against the codemap.
# Remove args which don't exist in the arglist from our codemap.
# NOT IMPLEMENTED. HANDLE USING NIL RETURN VALUES FROM GET_ARG.
#if not arglist.include?(codename)
# puts "WARNING: column #{colname} does not have an argument"
#end
v = cell.get_arg(codename)
if v.nil? or not legalValues.include?(v)
puts "\tInvalid code for cell\##{cell.ordinal}, code #{codename} : #{v}" if verbose > 0
end
}
end
}
rescue StandardError => e
puts e.message
puts e.backtrace
end