This repository has been archived by the owner on Jul 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stroop.rb
executable file
·45 lines (32 loc) · 1.69 KB
/
stroop.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
#!/usr/bin/env ruby
#print ARGV[0]
# loop across this to append to csv to get all the stroop files, but for now, one file
workingfile = ARGV[0]
# only if this is a real file, do the needful
if File.file?(workingfile)
# Search the files for 'subject or session' then grab the first result, then split that result down the last word (the number)
subject = File.open(workingfile).grep(/Subject:/).first.split.last
session = File.open(workingfile).grep(/Session:/).first.split.last
# set the subject/session info at the beginning of the row
datarecord = "#{subject},#{session},"
# search through the file for any possible values we may want and create an array of all of it
bigpull = File.open(workingfile).grep(/TrialProc|RTTime|ACC|DesignList.Cycle/)
# loop to clean whitespace from ALL the strings in the array (even strings we don't want)
bigpull.each do |x|
x = x.strip! # the ! permanently writes back to the array instead of the temporary values
end
# grab the first instance of the TrialProcMain line, which is the start of the REAL data
first_idx = bigpull.index('Procedure: TrialProcMain')
# remove the first chunk of the array before the pieces of info that matter -- this drops all the test data
bigpull.shift(first_idx)
bigpull.each do |x|
# skip the entries that say "TrialProc" etc, because they don't actually contain data
unless x =~ /TrialProc/
# append data to the end of this record, separated by commas
datarecord += "#{x.split.last},"
end
end
# add a newline at the end of this record, so the next won't have to know to do it
datarecord += "\n"
File.open('stroop_ruby_out.csv', 'a') {|f| f.write(datarecord) }
end