forked from OpenSHAPA/OpenSHAPA-Example-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathExport - Batch Variables CSV.rb
More file actions
219 lines (159 loc) · 10.2 KB
/
Export - Batch Variables CSV.rb
File metadata and controls
219 lines (159 loc) · 10.2 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
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
# Updated 4.24.20
require "Datavyu_API.rb"
require "csv"
# Batch operation: Analyses on multiple files, outputs to csv file called "Batch Analyses"
begin
# Begin Function Definitions ------------------------------------------------------------------------------------------------------------------------
def createCellArray(column, list)
for cell in column.cells
list << [cell.onset, cell.offset]
end
end
def sumCellsColumn(column)
sum = 0.0
for cell in column.cells
sum = sum + (cell.offset - cell.onset)
end
return sum
end
def sumCellsArray(list)
sum = 0.0
for cell in list
sum = sum + (cell[1] - cell[0])
end
return sum
end
# End Function Definitions --------------------------------------------------------------------------------------------------------------------------
# File Loading --------------------------------------------------------------------------------------------------------------------------------------
relPathString = "~/Desktop/BatchFolder"
filedir = File.expand_path(relPathString)
filenames = Dir.new(filedir).entries
csvString = "~/Desktop/AnalysesOutput.csv"
csvFile = File.expand_path(csvString)
for file in filenames
if (file.include?(".opf")) and file[0].chr != '.'
$db,$pj = load_db(filedir+"/"+file)
# Begin Column Collection ---------------------------------------------------------------------------------------------------------------------------
slCol = getColumn("speaker_listener")
peerCol = getColumn("peer")
partCol = getColumn("participant")
ecCol = getColumn("eye_contact")
greetingColumn = getColumn("greeting")
if (greetingColumn == nil)
greetingColumn = getColumn("greeting_goodbye")
end
# End Column Collection -----------------------------------------------------------------------------------------------------------------------------
# Begin Conversation Duration -----------------------------------------------------------------------------------------------------------------------
offsets = Array.new
cols = get_column_list()
for col in cols
curr = getColumn(col)
if curr.cells.last == nil
next
end
offsets << curr.cells.last.offset
end
convoDur = offsets.max
# End Conversation Duration ------------------------------------------------------------------------------------------------------------------------
# Begin Sum of Participant and Peer Durations ------------------------------------------------------------------------------------------------------
peerTimes = Array.new
partTimes = Array.new
peerDur = 0.0
partDur = 0.0
createCellArray(peerCol, peerTimes)
createCellArray(partCol, partTimes)
peerDur = sumCellsArray(peerTimes)
partDur = sumCellsArray(partTimes)
totalSpeakingDur = peerDur + partDur
# End Sum of Peer and Participant Speaking Durations ------------------------------------------------------------------------------------------------
# Begin Amount of time participant is on-topic relative to their own speaking duration --------------------------------------------------------------
slOTtimes = Array.new
slOFFTtimes = Array.new
for cell in slCol.cells
if (cell.argvals[1] == "OT")
slOTtimes << [cell.onset, cell.offset]
end
if (cell.argvals[1] == "OFFT")
slOFFTtimes << [cell.onset, cell.offset]
end
end
participantOT = 0.0
participantOFFT = 0.0
for times in partTimes
for range in slOTtimes
if (times[0] >= range[0]) and (times[1] <= range[1])
participantOT = participantOT + (times[1] - times[0])
end
end
for range in slOFFTtimes
if (times[0] >= range[0]) and (times[1] <= range[1])
participantOFFT = participantOFFT + (times[1] - times[0])
end
end
end
# End Amount of time participant is on-topic relative to their own speaking duration ----------------------------------------------------------------
# Begin Questions and Responses ---------------------------------------------------------------------------------------------------------------------
total_qs = 0
ot_qs = 0
offt_qs = 0
total_rs = 0
ot_rs = 0
offt_rs = 0
for cell in slCol.cells
if (cell.argvals[1] == "OT" and cell.argvals[2] == "Q")
ot_qs = ot_qs + 1
total_qs = total_qs + 1
end
if (cell.argvals[1] == "OFFT" and cell.argvals[2] == "Q")
offt_qs = offt_qs + 1
total_qs = total_qs + 1
end
if (cell.argvals[1] == "OT" and cell.argvals[2] == "R")
ot_rs = ot_rs + 1
total_rs = total_rs + 1
end
if (cell.argvals[1] == "OFFT" and cell.argvals[2] == "R")
offt_rs = offt_rs + 1
total_rs = total_rs + 1
end
end
# End Questions and Responses -----------------------------------------------------------------------------------------------------------------------
# Begin eye_contact durations -----------------------------------------------------------------------------------------------------------------------
ecDur = sumCellsColumn(ecCol)
# End eye_contact durations -------------------------------------------------------------------------------------------------------------------------
# Begin Participant Listening -----------------------------------------------------------------------------------------------------------------------
part_listening = 0.0
count_listen = 0
for cell in slCol.cells
if (cell.argvals[0] == "L" or cell.argvals[0] == "l")
part_listening = part_listening + (cell.offset - cell.onset)
count_listen = count_listen + 1
end
end
# End Participant Listening -------------------------------------------------------------------------------------------------------------------------
# Begin Fillers Count -------------------------------------------------------------------------------------------------------------------------------
countFiller = 0
for cell in slCol.cells
if (cell.argvals[2] == "F")
countFiller = countFiller + 1
end
end
# End Fillers Count ---------------------------------------------------------------------------------------------------------------------------------
# Begin Greeting Boolean ----------------------------------------------------------------------------------------------------------------------------
# Exclude goodbyes
greetingBoolean = 0
for cell in greetingColumn.cells
if (cell.argvals[0] == "G") and (cell.onset < 60000)
greetingBoolean = 1
end
end
# End Greeting Boolean ------------------------------------------------------------------------------------------------------------------------------
# Excel File Output ---------------------------------------------------------------------------------------------------------------------------------
puts file.to_s + ", " + (convoDur/1000.0).to_s + ", " + (totalSpeakingDur/1000.0).to_s + ", " + (peerDur/1000.0).to_s + ", " + (partDur/1000.0).to_s + ", " + (partDur/totalSpeakingDur).to_s + ", " + (peerDur/totalSpeakingDur).to_s + ", " + (participantOT/partDur).to_s + ", " + (participantOT/(participantOT + participantOFFT)).to_s + ", " + (participantOFFT/partDur).to_s + ", " + ot_qs.to_s + ", " + offt_qs.to_s + ", " + (ot_qs/total_qs.to_f).to_s + ", " + (offt_qs/total_qs.to_f).to_s + ", " + ot_rs.to_s + ", " + offt_rs.to_s + ", " + (ot_rs/total_rs.to_f).to_s + ", " + (offt_rs.to_f/total_rs.to_f).to_s + ", " + (part_listening/1000).to_s + ", " + (ecDur/1000).to_s + ", " + (ecDur/convoDur).to_s + ", " + count_listen.to_s + ", " + (part_listening/peerDur).to_s + ", " + countFiller.to_s + ", " + greetingBoolean.to_s + "\n\n"
# CSV Output ----------------------------------------------------------------------------------------------------------------------------------------
CSV.open(csvFile, "a+") do |csv|
csv << [file.to_s + ", " + (convoDur/1000.0).to_s + ", " + (totalSpeakingDur/1000.0).to_s + ", " + (peerDur/1000.0).to_s + ", " + (partDur/1000.0).to_s + ", " + (partDur/totalSpeakingDur).to_s + ", " + (peerDur/totalSpeakingDur).to_s + ", " + (participantOT/partDur).to_s + ", " + (participantOT/(participantOT + participantOFFT)).to_s + ", " + (participantOFFT/partDur).to_s + ", " + ot_qs.to_s + ", " + offt_qs.to_s + ", " + (ot_qs/total_qs.to_f).to_s + ", " + (offt_qs/total_qs.to_f).to_s + ", " + ot_rs.to_s + ", " + offt_rs.to_s + ", " + (ot_rs/total_rs.to_f).to_s + ", " + (offt_rs.to_f/total_rs.to_f).to_s + ", " + (part_listening/1000).to_s + ", " + (ecDur/1000).to_s + ", " + (ecDur/convoDur).to_s + ", " + count_listen.to_s + ", " + (part_listening/peerDur).to_s + ", " + countFiller.to_s + ", " + greetingBoolean.to_s]
end
end
end
end