-
Notifications
You must be signed in to change notification settings - Fork 1
/
batch_run_all.rb
439 lines (384 loc) · 14.8 KB
/
batch_run_all.rb
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
require 'Datavyu_API.rb'
require 'rbconfig'
include Config
begin
$out_file = File.expand_path("~/code/work/babylab/datavyu_scripts/batch_run_all.txt")
$failed_check_path = File.expand_path("~/code/work/babylab/datavyu_scripts/failed_check.csv")
$passed_check_path = File.expand_path("~/code/work/babylab/datavyu_scripts/passed_check.csv")
# this is the path you need to set:
batch_filedir = File.expand_path("~/code/work/babylab/datavyu_scripts/opffiles")
filenames = Dir.new(batch_filedir).entries
# pinfo_dir = File.expand_path("~/code/work/babylab/opffiles/personal_info_files")
# no_persinfo_file_path = File.expand_path("~/code/work/babylab/opffiles/personal_info_files/batch_no_personal_info.csv")
$valid_utt_type = Array["q", "d", "i", "u", "r", "s", "n", "NA"]
$valid_obj_pres = Array["y", "n", "u", "NA"]
$failed_check = Array.new
$file_errors = Array.new
$file_passed_check = true
$passed_check = Array.new
def checkCodes(cell, proj_name)
if not $valid_utt_type.include?(cell.utterance_type.to_s)
error = "["+proj_name+"]: " + "Cell# "+cell.ordinal.to_s+": \""+cell.utterance_type.to_s+"\" is not a valid utterance_type code\n"
#$output.puts(error)
$file_errors.push(error)
$file_passed_check = false
add_to_failed_check(proj_name)
end
if not $valid_obj_pres.include?(cell.object_present.to_s)
error = "["+proj_name+"]: " + "Cell# "+cell.ordinal.to_s+": \""+cell.object_present.to_s+"\" is not a valid object_present code\n"
#$output.puts(error)
$file_errors.push(error)
$file_passed_check = false
add_to_failed_check(proj_name)
end
end
def is_uppercase(some_string)
return some_string == some_string.upcase
end
def check_mwu(cell, proj_name)
if cell.object_present.to_s != "NA"
error = "["+proj_name+"]: " + "Cell# " + cell.ordinal.to_s + ": object_present must be NA in \"%com: mwu\" cell"
#$output.puts(error)
$file_errors.push(error)
$file_passed_check = false
add_to_failed_check(proj_name)
end
if cell.speaker.to_s != "NA"
error = "["+proj_name+"]: " + "Cell# " + cell.ordinal.to_s + ": speaker must be NA in \"%com: mwu\" cell"
#$output.puts(error)
$file_errors.push(error)
$file_passed_check = false
add_to_failed_check(proj_name)
end
end
def add_to_failed_check(proj_name)
if !$failed_check.include?(proj_name)
$failed_check.push(proj_name)
end
end
def output_failed_check()
failed_check_file = File.new($failed_check_path, "w")
for file in $failed_check
failed_check_file.puts(file)
end
end
def output_passed_check()
passed_check_file = File.new($passed_check_path, "w")
for file in $passed_check
passed_check_file.puts(file)
end
end
def output_errors()
output = File.new($out_file, 'w')
for error in $file_errors
output.puts(error)
end
end
for file in filenames
$file_passed_check = true
if file.include?(".opf")
puts "LOADING DATABASE: " + batch_filedir+File::SEPARATOR+file
$db, $pj = load_db(batch_filedir+File::SEPARATOR+file)
proj_name = $pj.getProjectName()
columns = getColumnList()
# Check Codes
#
# checkValidCodes() makes sure that all the codes found in each cell of
# the selected column are valid codes for that specific element. The
# function is called with the value of the "column" variable defined above.
# You need to change this by hand every time you run it on a different column.
# for column in columns
# checkValidCodes(column, "",
# "utterance_type", ["q", "d", "i", "u", "r", "s", "n", "NA"],
# "object_present", ["y", "n", "u", "NA"])
# end
puts
for column in columns
col = getColumn(column)
# Make sure that all the speaker codes are exactly 3 letters long
# and check the case
for cell in col.cells
if cell.object.to_s.start_with?("%com: mwu")
check_mwu(cell, proj_name)
next
end
checkCodes(cell, proj_name)
if cell.speaker.to_s.length != 3 && cell.speaker.to_s != "NA"
error = "["+proj_name+"]: " + "check codes: (3 letter code required): [Column]: "+column+" [Variable]: speaker\t[Cell]# : "+\
cell.ordinal.to_s + " [Current Value]: " + cell.speaker
#$output.puts(error)
$file_errors.push(error)
$file_passed_check = false
add_to_failed_check(proj_name)
end
# Speaker code has to be all uppercase
if !is_uppercase(cell.speaker.to_s) && !cell.object.to_s.start_with?("%com:")
error = "["+proj_name+"]: " + "check codes: speaker code must be uppercase: [Column]: " + column + " [Cell]# : "+\
cell.ordinal.to_s
#$output.puts(error)
$file_errors.push(error)
$file_passed_check = false
add_to_failed_check(proj_name)
end
# object_present needs to be single character and lowercase
if (cell.object_present.to_s.length != 1) && !cell.object.to_s.start_with?("%com:")
error = "["+proj_name+"]: " + "check codes: object_present needs to be a single character: [Column]: " + column + " [Cell]# : "+\
cell.ordinal.to_s
#$output.puts(error)
$file_errors.push(error)
$file_passed_check = false
add_to_failed_check(proj_name)
end
if is_uppercase(cell.object_present.to_s) && !cell.object.to_s.start_with?("%com:")
error = "["+proj_name+"]: " + "check codes: object_present needs to be lower case: [Column]: " + column + " [Cell]# : "+\
cell.ordinal.to_s
#$output.puts(error)
$file_errors.push(error)
$file_passed_check = false
add_to_failed_check(proj_name)
end
# utterance_type needs to be single character and lowercase
if (cell.utterance_type.to_s.length != 1) && !cell.object.to_s.start_with?("%com:")
error = "["+proj_name+"]: " + "check codes: utterance_type needs to be a single character: [Column]: " + column + " [Cell]# : "+\
cell.ordinal.to_s
#$output.puts(error)
$file_errors.push(error)
$file_passed_check = false
add_to_failed_check(proj_name)
end
if is_uppercase(cell.utterance_type.to_s) && !cell.object.to_s.start_with?("%com:")
error = "["+proj_name+"]: " + "check codes: utterance_type needs to be lower case: [Column]: " + column + " [Cell]# : "+\
cell.ordinal.to_s
#$output.puts(error)
$file_errors.push(error)
$file_passed_check = false
add_to_failed_check(proj_name)
end
split_object = cell.object.to_s.split("+")
if split_object.length > 1
for word in split_object[1..-1]
if is_uppercase(word[0].chr)
error = "["+proj_name+"]: " + "check codes: only the first word in a multi-word object can be uppercase: [Cell]# : "+ cell.ordinal.to_s
#$output.puts(error)
$file_errors.push(error)
$file_passed_check = false
add_to_failed_check(proj_name)
end
end
end
cell.argvals.each_with_index { |code, i|
# codes can't be empty
if code == ""
error = "["+proj_name+"]: " + "check_codes (Found empty code): [Column]: " + column+\
" [Variable]: " + cell.arglist[i].to_s + " [Cell#]: " + cell.ordinal.to_s
#$output.puts(error)
$file_errors.push(error)
$file_passed_check = false
add_to_failed_check(proj_name)
end
# "NA" needs to be all uppercase
if code == "na" || code =="nA" || code == "Na"
error = "["+proj_name+"]: " + "check_codes: NA needs to be uppercase: [Column]: " + column+\
" [Variable]: " + cell.arglist[i].to_s + " [Cell#]: " + cell.ordinal.to_s
#$output.puts(error)
$file_errors.push(error)
$file_passed_check = false
add_to_failed_check(proj_name)
end
# codes cannot contain space, unless it's inside comment
if !code.start_with?("%com:") and code.match(/\s/)
error = "["+proj_name+"]: " + "check_codes: code cannot contain space: [Column]: " + column+\
" [Variable]: " + cell.arglist[i].to_s + " [Cell#]: " + cell.ordinal.to_s
#$output.puts(error)
$file_errors.push(error)
$file_passed_check = false
add_to_failed_check(proj_name)
end
}
end
end
# Check Comments
#
# Make sure that comment cells don't have any content for
# the non-comment codes. Everything except the comment itself
# should be "NA". Also makes sure that onset/offset times for
# comments are equal.
for column in columns
col = getColumn(column)
for cell in col.cells
if (cell.object.to_s.start_with?("%com:") &&
((cell.utterance_type.to_s != "NA") ||
(cell.object_present.to_s != "NA") ||
(cell.speaker.to_s != "NA")))
if cell.object.to_s.start_with?("%com: mwu")
next
end
error = "["+proj_name+"]: " + "comments ERROR: one of the values is not \"NA\": [Column] " + column + "[Cell#]: " + cell.ordinal.to_s
#$output.puts(error)
$file_errors.push(error)
$file_passed_check = false
add_to_failed_check(proj_name)
if (cell.onset != cell.offset) && !(cell.object.to_s.include?("personal information"))
diff = cell.offset - cell.onset
if diff.abs <= 1
next
end
error = "["+proj_name+"]: " + "comments ERROR: onset and offset are not equal: [Column] " + column + " [Cell#]: " + cell.ordinal.to_s
#$output.puts(error)
$file_errors.push(error)
$file_passed_check = false
add_to_failed_check(proj_name)
end
elsif (cell.object.to_s.start_with?("%com:") &&
(cell.onset != cell.offset) && !(cell.object.to_s.include?("personal information")))
error = "["+proj_name+"]: " + "comments ERROR: onset and offset are not equal: [Column] " + column + " [Cell#]: " + cell.ordinal.to_s
#$output.puts(error)
$file_errors.push(error)
$file_passed_check = false
add_to_failed_check(proj_name)
end
end
end
# Check Intervals
#
# this makes sure all onsets are < offsets
# scan_for_bad_cells(col)
for column in columns
col = getColumn(column)
for cell in col.cells
if cell.onset > cell.offset
error = "["+proj_name+"]: " + "intervals ERROR: onset is greater than offset: [Column] " + column + " [Cell#]: " + cell.ordinal.to_s
#$output.puts(error)
$file_errors.push(error)
$file_passed_check = false
add_to_failed_check(proj_name)
end
if !cell.object.to_s.start_with?("%com") && (cell.onset == cell.offset)
error = "["+proj_name+"]: " + "intervals ERROR: onset and offset are equal in non-comment cell: [Column] " + column + " [Cell#]: " + cell.ordinal.to_s
#$output.puts(error)
$file_errors.push(error)
$file_passed_check = false
add_to_failed_check(proj_name)
end
end
end
puts "\n\n\n"
# Personal Info
#
# This part runs through the datavyu file
# and pulls out all the personal info comments.
# It then writes out a file containing the
# timestamps of those regions. That output file
# should then be fed into the program that actually
# does the silencing.
#
#
# These comments should take the form:
#
# %com: personal information [audio]: credit card number
#
# or
#
# %com: personal information [video]: butt
#
#
# You need to set the output path of the .csv file that
# will be generated. This is the first line after this comment
# output_path = $pj.getProjectDirectory() + File::SEPARATOR + $pj.getProjectName() + "_personal_info.csv"
# output_path.gsub!('\\', '/')
#
# split_path = output_path.split(File::SEPARATOR)
#
# case CONFIG['host_os']
# when /mswin|windows/i
# no_persinfo_file_path = File.join(split_path[0], "Scripts_and_Apps/no_personal_info.txt")
# else
# no_persinfo_file_path = "/Volumes/seedlings/Scripts_and_Apps/no_personal_info.txt"
# end
# #puts output_path
# #output = File.expand_path(output_path)
#
# no_pi = IO.readlines(no_persinfo_file_path)
# already_in_nopi = false
# for element in no_pi
# if element.include? $pj.getProjectName()
# already_in_nopi = true
# end
# end
# for column in columns
#
# col = getColumn(column)
# if col.cells.length == 0
# puts "\nPlease delete the empty extra column....\n"
# next
# end
# # arrays containing millisecond onset/offsets for personal information
# audio_regions = Array.new
# video_regions = Array.new
#
# entry = nil
# for cell in col.cells
#
# entry = cell.object.to_s
# if (entry.start_with?("%com: personal info"))
# if (entry.include?("[audio]"))
# audio_regions.push([cell.onset, cell.offset])
# elsif (entry.include?("[video]"))
# video_regions.push([cell.onset, cell.offset])
# else
# puts "Malformed personal information comment: cell#: " + cell.ordinal.to_s
# end
# end
# end
#
# used_to_be_nopi = false
# if already_in_nopi && (!audio_regions.empty? || !video_regions.empty?)
# used_to_be_nopi = true
# no_pi.delete($pj.getProjectName())
# no_pi.delete($pj.getProjectName()+"\n")
#
# File.open(no_persinfo_file_path, 'w') do |f|
# f.truncate(0)
# f.puts(no_pi)
# end
# puts $pj.getProjectName() + " used to have no personal info. It has been removed from the no_personal_info list\n\n"
# end
#
# # if there are no personal info regions, add the name of the file
# # to the no_personal_info.txt manifest in /seedlings/Scripts_and_Apps/
# if (audio_regions.empty? && video_regions.empty? && !already_in_nopi)
# open(no_persinfo_file_path, "a") do |f|
# f.puts $pj.getProjectName()
# end
# puts "There were no personal info regions"
# exit
# end
# if already_in_nopi && !used_to_be_nopi
# exit
# end
# output_file = File.open(output_path, "w")
#
# for region in audio_regions
# output_file.puts("audio,#{region[0]},#{region[1]}")
# end
#
# for region in video_regions
# output_file.puts("video,#{region[0]},#{region[1]}")
# end
#
# output_file.close()
#
# puts "personal info timestamps written to: " + output_path + "\n\n"
# end
end
if $file_passed_check
$passed_check.push(proj_name)
end
end
output_errors()
output_failed_check()
output_passed_check()
puts "Errors written to: " + $out_file
puts "List of files failing check: " + $failed_check_path
puts "List of files passing check: " + $passed_check_path
end