forked from iLanguage/OPrime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsrt2touchdatadir.sh
92 lines (77 loc) · 2.67 KB
/
srt2touchdatadir.sh
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
#!/bin/bash
# usage bash ../src/srt2touchdata.sh *.srt
cd ../backup
#subExperiment = ""
#participantCode =""
#reactionTime = ""
#stimuliNumber = ""
#touchx = ""
#touchy = ""
echo "----- Removing old files---- "
rm en*.csv
rm fr*.csv
rm en*.json
rm fr*.json
rm particpants.csv
rm touch-responses.json
echo "----- Extracting data into csv ------"
jsonfile="touch-responses.json"
echo '{"responses":[{"id":0,"x":0,"y":0,"userid":"0000","reactionTime":0,"subexperiment":"00","stimulus":0,"color":"#000000","r":3}' >> $jsonfile
FILES=../backup/*.srt
for i in $FILES
do
file=$i
#1318026828633_ET1AM8RB_en28_Reading_Comprehension_for_Words.srt
stem=${i%.srt} # Strip off the suffix.
#1318026828633_ET1AM8RB_en28_Reading_Comprehension_for_Words
IFS=$'_'
set $stem
starttime=$1
participantcode=$2
subexperimentcode=$3
subexperimenttitle=${stem##*_$3_} #everythign after $3
echo "Starttime $starttime, participant $participantcode, experimentcode $subexperimentcode, experimenttitle $subexperimenttitle"
csvfile="$3_$subexperimentcode_$subexperimenttitle.csv"
#Starttime 1318026828633, participant ET1AM8RB, experimentcode en28, experimenttitle Reading_Comprehension_for_Words
unset IFS
grep "ParticipantID" $file >tempheader
#grep "ParticipantID" $file
#cat $file
HEADER=`cat tempheader`
grep "ReactionTimes" $file >tempreactions
grep "TouchResponses" $file >temptouches
participantinfo=${HEADER##*:::===}
echo $participantcode,$participantinfo,$starttime,$subexperimentcode >>particpants.csv
REACTIONS=`cat tempreactions`
reactiontimes=${REACTIONS//ReactionTimes [/$participantcode,$starttime,reaction,};
reactiontimes=${reactiontimes// /};
echo ${reactiontimes/]/} >> $csvfile
reactionarr=${REACTIONS//ReactionTimes [/};
reactionarr=${reactionarr//]/};
#echo $reactionarr
TOUCHES=`cat temptouches`
touchesdata=${TOUCHES//TouchResponses [/};
touchesdata=${touchesdata//]/};
IFS=$', '
arrreac=($reactionarr)
counter=0;
set $touchesdata
ys=""
xs=""
for t in $touchesdata
do
echo " ,{\"id\":0,\"x\":${t%%:::*},\"y\":${t#*:::},\"userid\":\"$participantcode\",\"reactionTime\":${arrreac[$counter]},\"subexperiment\":\"$subexperimentcode\",\"stimulus\":$counter,\"color\":\"#00ff00\",\"r\":10}" >> $jsonfile
counter=`expr $counter + 1`;
xs=$xs,${t%%:::*}
ys=$ys,${t#*:::}
done
unset IFS
echo $participantcode,$starttime,x${xs// /} >>$csvfile
echo $participantcode,$starttime,y$ys >> $csvfile
rm tempheader
rm tempreactions
rm temptouches
done
echo "]}" >> $jsonfile
cp $jsonfile ../src/public/bilingualaphasiatest/touch-responses.json
echo "==============================================================="