Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
219 changes: 219 additions & 0 deletions Export/Export - Batch Variables CSV.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,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
97 changes: 97 additions & 0 deletions Export/Export - Cell Length Durations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,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)
Loading