-
Notifications
You must be signed in to change notification settings - Fork 0
/
survey.html
658 lines (473 loc) · 19.3 KB
/
survey.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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
<head>
<script language="javascript" src="res/jquery-2.0.0.js"></script>
</head>
<style>
img{
max-width : 100%;
height : 400px;
}
</style>
<body>
<h1>
<b>
Select the image that seems the MOST realistic to you.
</b>
</h1>
<div id="Images">
<span id="instructions">
<div style="margin:10px; width:1000px">
<pre style="word-wrap: break-word; white-space: pre-wrap; font-size:11">
In this HIT, you will be shown pairs of images. Your task is to choose the image that appears the MOST realistic to you by selecting the appropriate button. There are 16 pairs of images in total, and the task concludes with a very brief yes/no questionnaire.
</pre>
<br>
<br>
<input type="button" value="Proceed" onClick="initializeSurvey()" id="startButton">
</div>
</span>
<span id="images">
</span>
</div>
<form id="formex">
</form>
</body>
<script>
var files;
var allFiles;
var filesObvious;
var imageIdx;
var firstIsReal;
var imagesObject;
var imagesToDisplay;
var randValue;
var orderOfAppearance = "";
var htmlReal_1 = "<td><img src=\"res/jpgpics/";
var htmlFalse_1 = "<td><img src=\"res/jpgpics/";
var htmlReal_2 = "\"/></td>";
var htmlFalse_2 = "\"/></td>";
var radZero = "<tr><td><input type=\"radio\" name=\"rad\" id=\"rad_0\"/>This image</td>";
var radOne = "<td><input type=\"radio\" name=\"rad\" id=\"rad_1\"/>This image</td></tr>";
var myId = 0;
//Initial settings (visual)
document.getElementById("Images").setAttribute("style","margin:10px; width:" + ($(window).width() - 50) + "px");
$(window).resize(function() {
document.getElementById("Images").setAttribute("style","margin:10px; width:" + ($(window).width() - 50) + "px");
});
//Tests whether the assignmentId variable is not available (in that case, the user has not yet accepted the HIT, and we must avoid letting the counter variable to be updated).
if(getURLParameter("assignmentId") == "ASSIGNMENT_ID_NOT_AVAILABLE"){
document.getElementById("startButton").disabled = true;
}
//Functions...
function createNextButton(){
document.getElementById("formex").innerHTML = "<input type=\"button\" value=\"Next\" onClick=\"getNext()\" id=\"next_button\"></input>";
}
function initializeSurvey(){
$.get("counter.php") //Using jQuery, run counter script (it runs on server side, increments the counter variable and returns that value, which is assigned to counter_val)
.done(function(counter_val){
$.get("read_control.php") //Gets the list of control image file paths
.done(function(obvious_files){
filesObvious = obvious_files.split("\n");
myId = parseInt(counter_val);
document.getElementById("instructions").innerHTML = ""; //Clears the instructions
createNextButton();
$.get("read.php") //Gets the list of images
.done(function(data){
allFiles = data.split("\n"); //Get an array of
var myIndex = myId%9; //There are '9' possibilities of groups of images
if(myIndex >= 3){
myIndex++;
if(myIndex >= 7)
myIndex++;
}
var fileIdx = 0;
files = new Object();
for(var i = 0; i < 12; i++){
files[fileIdx] = allFiles[(i*12+myIndex)%144];
fileIdx++;
if(myIndex < 3)
files[fileIdx] = allFiles[i*12+3];
else{
if(myIndex < 7)
files[fileIdx] = allFiles[i*12+7];
else
files[fileIdx] = allFiles[i*12+11];
}
//Calculating the next index...
myIndex = (myIndex + 4)%12;
fileIdx++;
}
files["length"] = Object.size(files);
randomizeArrayOfImagesPlusObvious();
imageIdx = 0;
var content = "";
var image_1 = buildReal(0);
var image_2 = buildFalse(0);
randValue = Math.random();
if(randValue > 0.5){
content = "<tr>" + image_1 + image_2 + "</tr>" + radZero + radOne;
}
else{
content = "<tr>" + image_2 + image_1 + "</tr>" + radZero + radOne;
}
document.getElementById("images").innerHTML = "<table>" + content + "</table>";
if(randValue > 0.5){
document.getElementById("rad_0").setAttribute("image",imagesToDisplay[0].urlReal);
document.getElementById("rad_1").setAttribute("image",imagesToDisplay[0].urlFalse);
}
else{
document.getElementById("rad_0").setAttribute("image",imagesToDisplay[0].urlFalse);
document.getElementById("rad_1").setAttribute("image",imagesToDisplay[0].urlReal);
}
if(getURLParameter("assignmentId") == "ASSIGNMENT_ID_NOT_AVAILABLE"){
//Disabling the radio buttons.
document.getElementById("rad_0").disabled = true;
document.getElementById("rad_1").disabled = true;
//Disabling the "Next" button.
document.getElementById("next_button").disabled = true;
}
imagesObject = new Object();
initializeImagesObject();
})})
});
}
//Functions that return the image paths ("real" and "unreal" images of the pair - or, in the case of this study, our method's image and another method's image)
function buildReal(idx){
return htmlReal_1 + getPath(imagesToDisplay[idx].urlReal) + htmlReal_2;
}
function buildFalse(idx){
return htmlFalse_1 + getPath(imagesToDisplay[idx].urlFalse) + htmlFalse_2;
}
function getPath(fileStr){
var str_tk = fileStr.split('-');
return str_tk[0] + "-" + str_tk[1] + "/" + fileStr;
}
function initializeImagesObject(){
for(var i = 0; i < allFiles.length; i++){
imagesObject[allFiles[i]] = "unassigned";
}
}
//Gets URL parameter passed when fetching the web page. It allows the Mechanical Turk platform to pass us arguments.
function getURLParameter(sParam)
{
var sPageURL = window.location.search.substring(1);
var sURLVariables = sPageURL.split('&');
for (var i = 0; i < sURLVariables.length; i++)
{
var sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] == sParam)
{
return sParameterName[1];
}
}
}
function hasChecked(){
if(document.getElementById("rad_0").checked == true || document.getElementById("rad_1").checked == true)
return true;
else
return false;
}
function getVal(){ //Can be simplified with a boolean expression...
if(document.getElementById("rad_0").checked == true){
if(firstIsReal)
return true;
else
return false;
}
else{
if(firstIsReal)
return false;
else
return true;
}
}
//Returns a random integer between min and max.
function getRandInt(min,max){
return Math.round((Math.random())*(max - min) + min);
}
//Gets position to put next random image in array.
function getIdx(array,val){
var size = array.length;
if(array[val].isTaken == false){
return val;
}
else{
for(var i = 0; i < size; i++){
if(array[i].isTaken == false){
return i;
}
}
}
return null;
}
//Randomizes the order in which the pairs of images will be displayed to the worker.
function randomizeArrayOfImages(){
var arrSize = files.length/2;
imagesToDisplay = new Object();
for(var i = 0; i < arrSize; i++){
imagesToDisplay[i] = new Object();
imagesToDisplay[i].isTaken = false;
imagesToDisplay[i].urlReal = "";
imagesToDisplay[i].urlFalse = "";
}
imagesToDisplay["length"] = arrSize;
var idx;
var val;
for(var k = 0; k < arrSize; k++){
val = getRandInt(0,arrSize - 1);
idx = getIdx(imagesToDisplay,val);
imagesToDisplay[idx].isTaken = true;
imagesToDisplay[idx].urlReal = files[k*2];
imagesToDisplay[idx].urlFalse = files[k*2 + 1];
}
}
var control;
//Adds control images to the array of images to display.
function randomizeArrayOfImagesPlusObvious(){
var sizeObvious = filesObvious.length/2;
var arrSize = files.length/2 + sizeObvious;
imagesToDisplay = new Object();
for(var i = 0; i < arrSize; i++){
imagesToDisplay[i] = new Object();
imagesToDisplay[i].isTaken = false;
imagesToDisplay[i].urlReal = "";
imagesToDisplay[i].urlFalse = "";
}
imagesToDisplay["length"] = arrSize;
var idx;
var val;
//Initialize with "obvious" (control) images
var division = arrSize/sizeObvious;
control = new Object();
control["length"] = sizeObvious;
for(var k = 0; k < sizeObvious; k++){
control[k] = new Object();
control[k].isTaken = false;
control[k].urlReal = "";
control[k].urlFalse = "";
}
for(var k = 0; k < sizeObvious; k++){
val = getRandInt(0,sizeObvious- 1);
idx = getIdx(control,val);
control[idx].isTaken = true;
control[idx].urlReal = filesObvious[k*2];
control[idx].urlFalse = filesObvious[k*2 + 1];
}
for(var k = 0; k < sizeObvious; k++){
val = getRandInt(0,division - 1);
idx = k*division + val;
imagesToDisplay[idx].isTaken = true;
imagesToDisplay[idx].urlReal = control[k].urlReal;
imagesToDisplay[idx].urlFalse = control[k].urlFalse;
}
for(var k = 0; k < arrSize - sizeObvious; k++){
val = getRandInt(0,arrSize - 1);
idx = getIdx(imagesToDisplay,val);
imagesToDisplay[idx].isTaken = true;
imagesToDisplay[idx].urlReal = files[k*2];
imagesToDisplay[idx].urlFalse = files[k*2 + 1];
}
}
//Fetches the next pair of images.
function getNext(){
if(hasChecked()){
var content = "";
if(imageIdx + 1 <= imagesToDisplay.length - 1){ //Tests whether we've reached the end of the main survey.
imageIdx += 1;
updateImagesObject();
var image_1 = buildReal(imageIdx);
var image_2 = buildFalse(imageIdx);
randValue = Math.random();
if(randValue > 0.5){
content = "<tr>" + image_1 + image_2 + "</tr>" + radZero + radOne;
}
else{
content = "<tr>" + image_2 + image_1 + "</tr>" + radZero + radOne;
}
document.getElementById("images").innerHTML = "<table>" + content + "</table>";
if(randValue > 0.5){
document.getElementById("rad_0").setAttribute("image",imagesToDisplay[imageIdx].urlReal);
document.getElementById("rad_1").setAttribute("image",imagesToDisplay[imageIdx].urlFalse);
}
else{
document.getElementById("rad_0").setAttribute("image",imagesToDisplay[imageIdx].urlFalse);
document.getElementById("rad_1").setAttribute("image",imagesToDisplay[imageIdx].urlReal);
}
}
else{ //Displays the "image abilities" survey
updateImagesObject();
var form = document.getElementById("formex");
form.innerHTML = "<input type=\"button\" id=\"submit_button\" onClick=\"sendData()\" value=\"Submit\"></input>"
var span = document.getElementById("images");
var extra_questions = "<h3>1) Do you often paint, draw, or use 3D modeling software (or do you consider your a \"visual\" person)?</h3>";
extra_questions = extra_questions + "<input type=\"radio\" name=\"is_visual\" id=\"is_visual_yes\">Yes.</input><br><br><input type=\"radio\" name=\"is_visual\" id=\"is_visual_no\">No.</input>";
extra_questions = extra_questions + "<br><br>";
extra_questions = extra_questions + "<h3>2) Do you have normal color vision?</h3>";
extra_questions = extra_questions + "<input type=\"radio\" name=\"has_color_vision\" id=\"has_color_vision_yes\">Yes.</input><br><br><input type=\"radio\" name=\"has_color_vision\" id=\"has_color_vision_no\">No.</input>";
extra_questions = extra_questions + "<br><br>";
extra_questions = extra_questions + "<h3>3) Gender:</h3>";
extra_questions = extra_questions + "<input type=\"radio\" name=\"gender\" id=\"gender_male\">Male.</input><br><br><input type=\"radio\" name=\"gender\" id=\"gender_female\">Female.</input><br><br><input type=\"radio\" name=\"gender\" id=\"gender_no_answer\">I do not wish to state.</input>";
extra_questions = extra_questions + "<br><br>";
extra_questions = extra_questions + "<h3>4) Age:</h3>";
extra_questions = extra_questions + "<input type=\"radio\" name=\"age\" id=\"age_zero\">Less than 25.</input><br><br><input type=\"radio\" name=\"age\" id=\"age_one\">Between 25 and 50.</input><br><br><input type=\"radio\" name=\"age\" id=\"age_two\">Between 50 and 75.</input><br><br><input type=\"radio\" name=\"age\" id=\"age_three\">More than 75.</input>";
extra_questions = extra_questions + "<br><br>";
extra_questions = extra_questions + "<h3>5) Which of these images looks more realistic to you?</h3>";
extra_questions = extra_questions + "<br><br><table><tbody><tr><td>";
var result_coin = flipACoin();
if(result_coin){
extra_questions = extra_questions + "<img src=\"res/lines-correct.png\"></img></td>";
extra_questions = extra_questions + "<td><img src=\"res/lines-incorrect.png\"></img></td></tr>";
extra_questions = extra_questions + "<tr><td><input type=\"radio\" name=\"test_perspective\" id=\"test_perspective_correct\">This image.</input></td><td><input type=\"radio\"name=\"test_perspective\" id=\"test_perspective_incorrect\">This image.</input></td></tr></tbody></table>"
}
else{
extra_questions = extra_questions + "<img src=\"res/lines-incorrect.png\"></img></td>";
extra_questions = extra_questions + "<td><img src=\"res/lines-correct.png\"></img></td></tr>";
extra_questions = extra_questions + "<tr><td><input type=\"radio\" name=\"test_perspective\" id=\"test_perspective_incorrect\">This image.</input></td><td><input type=\"radio\"name=\"test_perspective\" id=\"test_perspective_correct\">This image.</input></td></tr></tbody></table>";
}
extra_questions = extra_questions + "<br><br>";
extra_questions = extra_questions + "<h3>6) Assuming the following images are spheres, which looks most realistic?</h3>";
extra_questions = extra_questions + "<br><br><table><tbody><tr><td>";
result_coin = flipACoin();
if(result_coin){
extra_questions = extra_questions + "<img src=\"res/sphere.png\"></img></td>";
extra_questions = extra_questions + "<td><img src=\"res/lingrad.png\"></img></td></tr>";
extra_questions = extra_questions + "<tr><td><input type=\"radio\" name=\"test_grad\" id=\"test_grad_sphere\">This image.</input></td><td><input type=\"radio\"name=\"test_grad\" id=\"test_grad_lin_grad\">This image.</input></td></tr></tbody></table>";
}
else{
extra_questions = extra_questions + "<img src=\"res/lingrad.png\"></img></td>";
extra_questions = extra_questions + "<td><img src=\"res/sphere.png\"></img></td></tr>";
extra_questions = extra_questions + "<tr><td><input type=\"radio\" name=\"test_grad\" id=\"test_grad_lin_grad\">This image.</input></td><td><input type=\"radio\"name=\"test_grad\" id=\"test_grad_sphere\">This image.</input></td></tr></tbody></table>";
}
extra_questions = extra_questions + "<br><br>";
extra_questions = extra_questions + "<h3>7)(Optional) Please, share any comments you'd like, preferrably about the cues that helped in you pick the images:<br><br>";
extra_questions = extra_questions + "<textarea id=\"comment_area\" rows=\"4\" cols=\"50\"></textarea>";
extra_questions = extra_questions + "<br><br>";
span.innerHTML = extra_questions;
}
}
else{
alert("Please, check an image before moving to the next...");
}
}
function flipACoin(){
return Math.random() >= 0.5;
}
function updateImagesObject(){//Updates the results array with the user's selection for a pair.
var firstRad = document.getElementById("rad_0");
var secondRad = document.getElementById("rad_1");
imagesObject[firstRad.getAttribute("image")] = firstRad.checked;
imagesObject[secondRad.getAttribute("image")] = secondRad.checked;
orderOfAppearance = orderOfAppearance + firstRad.getAttribute("image") + ";" + secondRad.getAttribute("image") + ";";
}
//Bundles up all the information to be submitted to Turk and sends it.
function sendData(){
if(completed_form()){
update_submission_data();
imagesObject["assignmentId"] = getURLParameter("assignmentId");
imagesObject["orderOfAppearance"] = orderOfAppearance;
imagesObject["comments"] = document.getElementById("comment_area").value;
//TODO: Select the right URL depending of the situation!!!
//Submission to mechanical turk:
submitAnswer("https://www.mturk.com/mturk/externalSubmit",imagesObject);
//Submission to sandbox:
//submitAnswer("https://workersandbox.mturk.com/mturk/externalSubmit",imagesObject);
}
else{
alert("Please, complete all the form questions.")
}
}
function completed_form(){
var question_one = document.getElementById("is_visual_yes").checked || document.getElementById("is_visual_no").checked;
if(!question_one)
return false;
var question_two = document.getElementById("has_color_vision_yes").checked || document.getElementById("has_color_vision_no").checked;
if(!question_two)
return false;
var question_three = document.getElementById("gender_male").checked || document.getElementById("gender_female").checked || document.getElementById("gender_no_answer").checked;
if(!question_three)
return false;
var question_four = document.getElementById("age_zero").checked || document.getElementById("age_one").checked || document.getElementById("age_two").checked || document.getElementById("age_three").checked;
if(!question_four)
return false;
var question_five = document.getElementById("test_perspective_correct").checked || document.getElementById("test_perspective_incorrect").checked;
if(!question_five)
return false;
var question_six = document.getElementById("test_grad_sphere").checked || document.getElementById("test_grad_lin_grad").checked;
return question_six;
}
function update_submission_data(){
if(document.getElementById("is_visual_yes").checked == true){
imagesObject["is_visual_person"] = true;
}
else{
imagesObject["is_visual_person"] = false;
}
if(document.getElementById("has_color_vision_yes").checked == true){
imagesObject["has_normal_color_vision"] = true;
}
else{
imagesObject["has_normal_color_vision"] = false;
}
if(document.getElementById("gender_male").checked == true){
imagesObject["gender"] = "male";
}
else{
if(document.getElementById("gender_female").checked == true){
imagesObject["gender"] = "female";
}
else{
imagesObject["gender"] = "no_answer";
}
}
if(document.getElementById("age_zero").checked == true){
imagesObject["age"] = "less_25";
}
else{
if(document.getElementById("age_one").checked == true){
imagesObject["age"] = "between_25_50";
}
else{
if(document.getElementById("age_two").checked == true){
imagesObject["age"] = "between_50_75";
}
else{
imagesObject["age"] = "more_75";
}
}
}
if(document.getElementById("test_perspective_correct").checked == true){
imagesObject["got_correct_perspective"] = true;
}
else{
imagesObject["got_correct_perspective"] = false;
}
if(document.getElementById("test_grad_sphere").checked == true){
imagesObject["got_correct_sphere"] = true;
}
else{
imagesObject["got_correct_sphere"] = false;
}
}
function submitAnswer(path, params, method){
method = method || "post"; // Set method to post by default if not specified.
var form = document.createElement("form");
form.setAttribute("method", method);
form.setAttribute("action", path);
for(var key in params) {
if(params.hasOwnProperty(key)) {
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", key);
hiddenField.setAttribute("value", params[key]);
form.appendChild(hiddenField);
}
}
document.body.appendChild(form);
form.submit();
}
Object.size = function(obj) {
var size = 0, key;
for (key in obj) {
if (obj.hasOwnProperty(key)) size++;
}
return size;
};
</script>