-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport_EasyDIAg.rb
More file actions
58 lines (47 loc) · 1.65 KB
/
export_EasyDIAg.rb
File metadata and controls
58 lines (47 loc) · 1.65 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
## Parameters
pri_col_name = 'pri_col'
# rel column has multiple coders
rel_col_name_list = %w[rel_col]
block_col_name = 'relblocks'
codes_to_check = %w(code1 code2)
input_folder = '~/Desktop/input'
output_folder = File.expand_path('~/Desktop')
time_buffer = 500
pri_suffix = '_R1'
rel_suffix = '_R2'
delimiter = "\t"
## Body
require 'Datavyu_API.rb'
input_path = File.expand_path(input_folder)
infiles = Dir.chdir(input_path) { Dir.glob('*.opf') }
codes_to_check.each do |code|
outfilename = code + '.txt'
output_file = File.join(File.expand_path(output_folder),outfilename)
outfile = File.new(output_file,'w')
data = []
infiles.each do |infile|
$db, $pj = load_db(File.join(input_path,infile))
# get the rel column name in the current spreadsheet
rel_col_name = get_column_list.select{ |col_name|
rel_col_name_list.include?(col_name)}.first
pri_col = get_column(pri_col_name)
rel_col = get_column(rel_col_name)
block_col = get_column(block_col_name)
pri_col.cells.each do |pc|
next unless block_col.cells.map{ |bc| bc.contains(pc) }.any?
data_row = code + pri_suffix + delimiter + (pc.onset - time_buffer).to_s + delimiter +
(pc.offset + time_buffer).to_s + delimiter + pc.get_code(code) + delimiter +
infile
data << data_row
end
rel_col.cells.each do |rc|
next unless block_col.cells.map{ |bc| bc.contains(rc) }.any?
data_row = code + rel_suffix + delimiter + (rc.onset - time_buffer).to_s + delimiter +
(rc.offset + time_buffer).to_s + delimiter + rc.get_code(code) + delimiter +
infile
data << data_row
end
end
outfile.puts data
outfile.close
end