-
Notifications
You must be signed in to change notification settings - Fork 0
/
Demo_Main.html
230 lines (188 loc) · 8.18 KB
/
Demo_Main.html
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
220
221
222
223
224
225
226
227
228
229
230
<!DOCTYPE html>
<html>
<head>
<title>Main</title>
<script src="Demo_Decoy.js" type="text/javascript"></script>
<script src="jspsych-6.1.0/jspsych.js" type="text/javascript"></script>
<script src="jspsych-6.1.0/plugins/jspsych-html-keyboard-response.js" type="text/javascript"></script>
<script src="jspsych-6.1.0/plugins/jspsych-html-button-response.js" type="text/javascript"></script>
<link href="jspsych-6.1.0/css/jspsych.css" rel="stylesheet" type="text/css"></link>
</head>
<body></body>
<script>
var timeline = [];
var urlParams = new URLSearchParams(window.location.search);
// Check function...
// If 'userid' === 000000000, then proceed as demo
if (atob(urlParams.get('userid')) === "00000000"){
btrialcountmax = 5;
btrialcount = btrialcountmax;
demo = 1;
}
allTrialsJson = {"Trials": [] };
var newForm = document.createElement("form");
newForm.action="RecordResultsDemo.cgi";
newForm.method="POST";
newForm.id="FResponses";
newForm.name="FResponses";
newForm.style="display:hidden;position:absolute;top:-12rem;";
newForm.innerHTML = '<input type="text" id="Responses" name="Responses" maxlength="1000000"><input type="text" id="userid" name="userid" maxlength="1000"><input type="text" id="sc" name="sc" maxlength="1000">';
// Determine coupling condition (0 = low coupling; 1 = high coupling)
var coupling_condition = Math.floor(Math.random() * 2);
if(coupling_condition > 0) {
coupling = "Low coupling";
} else {
coupling = "High coupling";
}
var phantom_condition = Math.floor(Math.random() * 3);
if(phantom_condition == 0) {
phantom_condition = "Highly_desirable";
} else if (phantom_condition == 1) {
phantom_condition = "Weakly_desirable";
} else {
phantom_condition = "Undesirable";
}
var welcome = {
type: "html-keyboard-response",
stimulus: "<h2>Welcome to the experiment!</h2>" +
"<div style='position:absolute;top:85%;width:100%;display:table;left:0;'><h3 style='display:table-cell;'>"+
"Press any key to continue</h3></div>",
choices: jsPsych.ALL_KEYS,
trial_duration: 5000,
on_finish: function(){
console.log("coupling condition: " + coupling)
// Capture participants demographic data
// and send it to 'allTrialsJson' file.
document.body.appendChild(newForm);
var urlParams = new URLSearchParams(window.location.search);
document.getElementById("userid").value = atob(urlParams.get('userid'));
document.getElementById("sc").value = urlParams.get('sc');
var today = new Date();
var dd = String(today.getDate()).padStart(2, '0');
var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
var yyyy = today.getFullYear();
newTrialJson = {
"Age": atob(urlParams.get('ua')),
"Gender": atob(urlParams.get('ug')),
"Ethnicity": atob(urlParams.get('ue')),
"Race": atob(urlParams.get('ur')),
"Date": mm + '/' + dd + '/' + yyyy,
"User_PID": atob(urlParams.get('userid')),
"Survey_ID": urlParams.get('sc'),
"User_email": atob(urlParams.get('uem')),
"Coupling": coupling,
"Phantom_condition": phantom_condition
//"Task_Order": exp_order //String.fromCharCode(taskOrder[0] + 65) + String.fromCharCode(taskOrder[2] + 65) //+ String.fromCharCode(taskOrder[1] + 65)
};
allTrialsJson['Trials'].push(newTrialJson);
// Check function...
document.body.classList.add('bodyOClass');
// Add decoy file to timeline.
ZDecoy_demo(timeline);
}
};
function PostJSON() {
document.getElementById("Responses").value = JSON.stringify(allTrialsJson);
document.getElementById("FResponses").submit();
}
var TerminateExp = {
type: 'html-keyboard-response',
stimulus: '<h3>Loading... <br><br></h3>',
choices: jsPsych.ALL_KEYS,
trial_duration: 2500,
on_finish: function(data){
//var data = JSON.stringify(allTrialsJson);
//console.log(data);
//jsPsych.pauseExperiment();
PostJSON();
//jsPsych.pauseExperiment();
//var data = expCSV(template, allTrialsJson['Trials']);
//document.getElementById("Responses").value = JSON.stringify(data);
//document.getElementById("FResponses").submit();
//jsPsych.resumeExperiment();
//jsPsych.pauseExperiment();
//var fileTitle = atob(urlParams.get('userid'));
//exportCSVFile(template, allTrialsJson['Trials'], fileTitle);
//jsPsych.resumeExperiment();
}
};
var template = {
"Decoy": "",
"Item": "",
"Option_1": "",
"Option_2": "",
"Option_3": "",
"Choice": ""
};
/*Description
*/
function convertToCSV(objArray) {
var array = typeof objArray != 'object' ? JSON.parse(objArray) : objArray;
var str = "Decoy,Item,Option_1,Option_2,Option_3,Choice,CatchTrials,Deliberation_RT,Choice_RT,Too_Slow";
for (var i = 0; i < array.length; i++) {
var line = '';
for (var index in array[i]) {
if (line != '') line += ','
line += array[i][index];
}
str += line + '\r\n';
}
return str;
};
function expCSV(headers, items){
if (headers) {
items.unshift(headers);
}
// Convert Object to JSON
var jsonObject = JSON.stringify(items);
var csv = this.convertToCSV(jsonObject);
return csv;
}
function exportCSVFile(headers, items, fileTitle) {
if (headers) {
items.unshift(headers);
}
// Convert Object to JSON
var jsonObject = JSON.stringify(items);
var csv = this.convertToCSV(jsonObject);
var exportedFilenmae = "Demo_" + fileTitle + '.csv' || 'export.csv';
var blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
if (navigator.msSaveBlob) { // IE 10+
navigator.msSaveBlob(blob, exportedFilenmae);
} else {
var link = document.createElement("a");
if (link.download !== undefined) { // feature detection
// Browsers that support HTML5 download attribute
var url = URL.createObjectURL(blob);
link.setAttribute("href", url);
link.setAttribute("download", exportedFilenmae);
link.style.visibility = 'hidden';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
}
};
// Adding files/events to experiment timeline.
timeline.push(welcome);
//timeline.push(taskOrderScreen());
jsPsych.init({
timeline: timeline,
default_iti: 0,
on_finish: function() {
//jsPsych.data.displayData();
}
});
</script>
</html>
<!--
Notes:
- Set up catch system (numbers) (4 + 3 =?). -> Done.
- Set up complementary filler catch system. -> Done.
- Work out how to randomize position of (option A, B, and C). -> Done
- Same product can't be shown twice in the same block. -> Done.
- Constrain possible options if phantom trial. -> Done.
- Let's say participant is often missing trials (no selecting any choice in the 'choice' event)
should I add a slide/warning or something, if participants misses more than # trials?
- Fix catch decoys for (decimals).
-->