-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexperiment.html
217 lines (189 loc) · 7.22 KB
/
experiment.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
<!DOCTYPE html>
<html>
<head>
<title>Alien language game</title>
<script src="jspsych-6.1.0/jspsych.js"></script>
<script src="jspsych-6.1.0/plugins/jspsych-html-button-response.js"></script>
<script src="jspsych-6.1.0/plugins/jspsych-survey-text.js"></script>
<script src="jspsych-6.1.0/plugins/jspsych-external-html.js"></script>
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
<script src="consent/consent.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="data-anonymizer.js"></script>
<link rel="stylesheet" href="jspsych-6.1.0/css/jspsych.css"></link>
<script src="mmturkey-0.6.js"></script>
</head>
<body></body>
<script>
/* get info from turk */
var turkInfo = jsPsych.turk.turkInfo();
// anonymizer for worker IDs
var a = new DataAnonymizer();
/* create timeline */
var timeline = [];
// boxes
var num_boxes = ['num_objects/box_1', 'num_objects/box_2']
var type_boxes = ['num_types/box_1', 'num_types/box_2']
var all_boxes = [num_boxes, type_boxes];
var box_type = jsPsych.randomization.sampleWithoutReplacement(all_boxes, 1)
var boxes = jsPsych.randomization.repeat(box_type[0], 1)
var box_1 = boxes[0]
var box_2 = boxes[1]
var utts = jsPsych.randomization.repeat(["complex_utt", "simple_utt"], 1)
var utt_1 = utts[0]
var utt_2 = utts[1]
console.log(utts)
box_type = box_type[0][0].substr(0, box_type[0][0].indexOf('/'))
function get_utt(utt_type) {
if (utt_type == "simple_utt") {
return("<i>\"Bado mep.\"</i>")
} else {
return("<i>\"Toba zem zorp bidaku midu osh gipu.\"</i>")
}
}
// reCAPTCHA object
var recaptcha = {
type: "external-html",
url: "recaptcha.html",
cont_btn: "submit_button",
execute_script: true
};
timeline.push(recaptcha);
var consent = {
type:'external-html',
url: "consent/consent.html",
cont_btn: "start"
};
timeline.push(consent);
/* define instructions trial */
var instructions = {
type: "html-button-response",
stimulus: "<p>In this experiment, you will see some aliens talk " +
"and make judgments about what they are talking about.",
choices: ['Start'],
data: {test_part: 'setup'},
post_trial_gap: 2000
};
timeline.push(instructions);
var hi_alien = {
type: 'html-button-response',
stimulus: "<p>This is Dax the alien. He speaks an alien language." +
'<br><br>He says, <i> "Difu Dax midaku."</i><br>' +
'That means "Hello, my name is Dax."</p><br>' +
"<div style='width: 700px;'>"+
"<div style='float: center;'><img src='img/alien1.png' width='250' height='300'></img></div>" +
"</div><br>",
choices: ['Continue'],
data: {test_part: 'setup'},
post_trial_gap: 500
}
var show_box_1 = {
type: 'html-button-response',
stimulus: function() { return "<p>Dax has two boxes. <br>" +
" He opens one box and looks inside. <br><br>" +
"Then, Dax says, " + get_utt(utt_1) + "</p>" +
"<div style='width: 700px;'>" +
"<div style='float: center;'><img src='img/alien1.png' width='250' height='300'></img></div>" +
"<div style='float: center;'><img src='img/grey_box.png'></img><img src='img/grey_box.png'></img></div>"+
"</div><br>";
},
choices: ['Continue'],
data: {test_part: 'setup', utt: utt_1},
post_trial_gap: 500
}
var show_box_2 = {
type: 'html-button-response',
stimulus: function() { return "<p>" +
"Then, Dax opens the other box and looks inside. <br><br>" +
"He says, " + get_utt(utt_2) + "</p>" +
"<div style='width: 700px;'>" +
"<div style='float: center;'><img src='img/alien1.png' width='250' height='300'></img></div>" +
"<div style='float: center;'><img src='img/grey_box.png'></img><img src='img/grey_box.png'></img></div>"+
"</div><br>";
},
choices: ['Continue'],
data: {test_part: 'setup', utt: utt_2},
post_trial_gap: 500
}
var show_boxes = {
type: 'html-button-response',
stimulus: function(){ return "<p>Here are Dax's boxes.<br></p>" +
"<div style='width: 700px;'>"+
"<div style='float: center;'><img width = '250px' src='img/" + box_1 + ".png'></img>" +
"<img width = '250px' src='img/" + box_2 + ".png'></img></div>"+
"</div>";
},
choices: ['Continue'],
post_trial_gap: 500
}
var test_box_1 = {
type: 'html-button-response',
stimulus: function(){ return "<p>Remember, Dax looked in one box and said " + get_utt(utt_1) + "</p>" +
"<p>Then Dax looked in the other box and said " + get_utt(utt_2) + "</p>" +
"<p>Which box do you think Dax was " +
"looking in when he said<br>" + get_utt(utt_1) + "?</p>" +
"<div style='width: 700px;'>"+
"</div>";
},
choices: [box_1, box_2],
post_trial_gap: 500,
data: {utt: utt_1, boxes_type: box_type, box_1: box_1, box_2: box_2, test_part: "box_selection"},
button_html: '<button style="border:none; background-color:#ffffff"> <img width="250px" src = "img/%choice%.png"> </img> </button>'
}
var test_box_2 = {
type: 'html-button-response',
stimulus: function(){ return "<p>Remember, Dax looked in one box and said " + get_utt(utt_1) + "</p>" +
"<p>Then Dax looked in the other box and said " + get_utt(utt_2) + "</p>" +
"<p>Which box do you think Dax was " +
"looking in when he said<br>" + get_utt(utt_2) + "?</p>" +
"<div style='width: 700px;'>"+
"</div>";
},
choices: [box_1, box_2],
post_trial_gap: 500,
data: {utt: utt_2, boxes_type: box_type, box_1: box_1, box_2: box_2, test_part: "box_selection"},
button_html: '<button style="border:none; background-color:#ffffff"> <img width="250px" src = "img/%choice%.png"> </img> </button>'
}
var test_procedure = {
timeline: [hi_alien, show_box_1, show_box_2, show_boxes, test_box_1, test_box_2],
sample: {
type: 'without-replacement',
size: 1
}
}
timeline.push(test_procedure);
var comment_trial = {
type: 'survey-text',
questions: [
{prompt: "Briefly, why did you choose the boxes you chose?"}
],
data: {test_part: 'comment'}
}
timeline.push(comment_trial);
function saveData(name, data) {
var xhr = new XMLHttpRequest();
xhr.open('POST', 'write_data.php');
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(JSON.stringify({filename: name, filedata: data}));
}
var endscreen = {
type: 'html-button-response',
stimulus: "<p>This is the end of the study. Thank you for participating!</p>",
choices: ['Finish']
};
timeline.push(endscreen);
/* start the experiment */
jsPsych.init({
timeline: timeline,
on_finish: function() {
if (turkInfo.outsideTurk) {
var file_name = a.anonymize("test_data")
} else {
var file_name = a.anonymize("data_data_data")
}
saveData(file_name, jsPsych.data.get().csv());
turk.submit(jsPsych.data.get().csv());
}
});
</script>
</html>