-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctionSpec.js
More file actions
executable file
·152 lines (140 loc) · 4.43 KB
/
FunctionSpec.js
File metadata and controls
executable file
·152 lines (140 loc) · 4.43 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
async function GetAssignment() {
// If no Subject ID is provided, we must be testing...
if (!Boolean(SubjectId)) {
var Assignment = {};
Assignment.GroupId = 'Ani';
Assignment.ImgPerm = {};
for (iI = 0; iI < 6; iI++) {
var LocId = String.fromCharCode(65 + iI);
Assignment.ImgPerm[LocId] = Assignment.GroupId + iI.toString();
}
return Assignment;
}
// Otherwise, request the Assignment from the server...
var Data = {};
Data.SubjectId = SubjectId;
var P1 = await fetch('./GetAssignment.php', {
method: 'post',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(Data)
});
var Assignment = await P1.json();
// Assignment contains the following fields: GroupId, ImgPerm
return Assignment;
}
function GetImgsToPreload() {
var Imgs = [];
for (iI = 0; iI < 6; iI++) {
Imgs.push('./Imgs/' + TaskIO.GroupId + iI.toString() + '.png');
}
return Imgs;
}
async function GetTimelineVars(Pairs) {
var nReps;
var UnshuffledOrder;
var Timeline = [];
if (Pairs.length == 5) {
nReps = 25;
UnshuffledOrder = [0, 1, 2, 3, 4];
} else {
nReps = 2;
UnshuffledOrder = [0, 1, 2, 3, 4, 5, 6, 7];
}
for (iRep = 0; iRep < nReps; iRep++) {
var Order = UnshuffledOrder;
Shuffle(Order);
for (iOrder = 0; iOrder < Order.length; iOrder++) {
var cPairId = Pairs[Order[iOrder]].PairId;
var cPos = './Imgs/' + Pairs[Order[iOrder]].Pos + '.png';
var cNeg = './Imgs/' + Pairs[Order[iOrder]].Neg + '.png';
var cP1 = await fetch('./Assets/RandBit.php');
var cBit = await cP1.json();
cBit = cBit == 1;
Timeline.push({
PairId: cPairId,
Pos: cPos,
Neg: cNeg,
PosOnRight: cBit
});
}
}
return Timeline;
}
function Shuffle(array) {
let currentIndex = array.length, randomIndex;
while (currentIndex != 0) {
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex--;
[array[currentIndex], array[randomIndex]] =
[array[randomIndex], array[currentIndex]];
}
return array;
}
function ImgClicked(Id) {
if (ResponseMade) {
return;
}
// If no response was made previously (i.e., this is the first)...
RT = jsPsych.getTotalTime() - StartTimeOfTrial;
// Set SelectedRight
if (Id == "ImgLeft") {
SelectedRight = false;
} else {
SelectedRight = true;
}
// Combine PosOnRight and SelectedRight to set Correct
Correct = !(PosOnRight ^ SelectedRight);
// Change the appearance of the stimuli
document.getElementById(Id).style =
`vertical-align: middle;
margin: 0px 60px;
border: ${BorderWidth}px solid #0000ff;
width: ${ImgWidth1}px;`;
if (Id == 'ImgLeft') {
document.getElementById('ImgRight').style =
`vertical-align: middle;
margin: 0px 60px;
border: ${BorderWidth}px solid #808080;
width: ${ImgWidth1}px;`;
} else {
document.getElementById('ImgLeft').style =
`vertical-align:middle;
margin: 0px 60px;
border: ${BorderWidth}px solid #808080;
width: ${ImgWidth1}px;`;
}
// Set ResponseMade to be true
ResponseMade = true;
}
async function WriteTaskIO() {
var Data = {};
Data.SubjectId = SubjectId;
Data.ClientTimeZone = ClientTimeZone;
if (window.location.href.includes("TIprobe")) {
Data.TIprobeIO = JSON.stringify(TaskIO);
} else {
Data.TItrainIO = JSON.stringify(TaskIO);
}
var P1 = await fetch('./WriteXIO.php', {
method: 'post',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(Data)
});
var Result = await P1.json();
return Result;
}
async function OnFinishTask() {
try {
var Result = await WriteTaskIO();
window.location.replace(Result.TargetUrl);
} catch (Err) {
window.location.replace(
"./Error.html?SubjectId=" + SubjectId + '&ErrorCode=XXX#');
}
}