Repository navigation
Expand file tree
/
Copy pathExport - Cell Length Durations.rb
More file actions
97 lines (76 loc) · 2.91 KB
/
Copy pathExport - Cell Length Durations.rb
File metadata and controls
97 lines (76 loc) · 2.91 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
87
88
89
90
91
92
93
94
95
96
97
# Updated 4.24.20
require 'Datavyu_API.rb'
require "csv"
def format_ec_icc(directory, outFile)
tot_pri_icc = Array.new
tot_rel_icc = Array.new
filenames = Dir.new(directory).entries
for file in filenames
if (file.include?(".opf")) and file[0].chr != '.'
$db,pj = load_db(directory + "/" + file)
puts "\nLoading " + file.to_s + "...\n"
pri = getColumn("eye_contact")
rel = getColumn("eye_contact_2")
pri_arr = Array.new
rel_arr = Array.new
pri_icc = Array.new
rel_icc = Array.new
for pri_cell in pri.cells
pri_arr << [pri_cell.onset, pri_cell.offset]
end
for rel_cell in rel.cells
rel_arr << [rel_cell.onset, rel_cell.offset]
end
if (pri_arr.length >= rel_arr.length)
for pri_times in pri_arr
i = false
pri_icc << ((pri_times[1] - pri_times[0])/1000.0)
for rel_times in rel_arr
if ((pri_times[0] - rel_times[0]).abs <= 5000) and ((pri_times[1] - rel_times[1]).abs <= 5000)
rel_icc << ((rel_times[1] - rel_times[0])/1000.0)
rel_arr = rel_arr - [rel_times]
i = true
break
end
end
if (i == false)
rel_icc << 0
end
end
end
if (pri_arr.length < rel_arr.length)
for rel_times in rel_arr
i = false
rel_icc << ((rel_times[1] - rel_times[0])/1000.0)
for pri_times in pri_arr
if ((rel_times[0] - pri_times[0]).abs <= 5000) and ((rel_times[1] - rel_times[0]).abs <= 5000)
pri_icc << ((pri_times[1] - pri_times[0])/1000.0)
i = true
break
end
end
if (i == false)
pri_icc << 0
end
end
end
if (pri_icc.length != rel_icc.length)
raise "Error"
end
for dur in pri_icc
tot_pri_icc << dur
end
for dur in rel_icc
tot_rel_icc << dur
end
end
CSV.open(outFile, "w") do |csv|
csv << tot_pri_icc
csv << tot_rel_icc
end
end
end
filedir = File.expand_path("~/Desktop/BatchFolder/")
csvString = "~/Desktop/ecICC.csv"
csvFile = File.expand_path(csvString)
format_ec_icc(filedir, csvFile)