-
Notifications
You must be signed in to change notification settings - Fork 0
/
Experiment_Paired_Comparison.html
346 lines (319 loc) · 15.9 KB
/
Experiment_Paired_Comparison.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
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script src="http://code.jquery.com/jquery-1.12.4.min.js"</script>
<script src="plotly/plotly-latest.min.js"></script>
<script src="jquery-csv-master/src/jquery.csv.js"></script>
<script src="http://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<link rel="stylesheet" type="text/css" href="Experiment1.css">
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
</head>
<body>
<table style="margin-bottom:0pt" width = "1000" border = "0">
<td>
<div id="instruction">
<h2 style="margin-bottom:0pt" align="center">Material Matching Task<br></h2>
<p id = "intro.part1"><font size="3" face="verdana" color="#347235">
The soap in the images are made with different materials. Which image contains the object that appear to be more translucent? Click on the image to make your choices.
</p>
</div>
</td>
</table>
<div id="images" style="text-align: center">
<table id="mainTable" border="0" width="780" cellpadding="0">
<tr>
<td id="target" style="text-align: center"><span id="label_left"><b>Left</b></span></td>
<td id="match" style="text-align: center"><span id="label_right"><b>Right</b></span></td>
</tr>
<tr>
<div class="bothimages" id="thumbnail_1">
<td align="left" >
<img id="sample" class='leftright' src="jpg/soap_map_b0.4_s0.01_sidelit_d100_q4096.jpg" width="570" height="350">
</td>
<td align = "right" >
<img id="match" class='leftright' src="jpg/soap_map_b0.4_s0.01_sidelit_d131_q4096.jpg" width="570" height="350">
</td>
</div>
</tr>
</table>
<img id="loading_icon" src="loading-icon.gif" alt="loading" style="margin: 0 auto 0 auto; display:none">
<div id='Nexttrial'>
Progress: Trial <span id="curTrial">0</span>/70<br>
<button type="button" id="Next" value="Start" class="NextButton" >Back</button>
</div>
<br>
<div id="results">
Your responses are: <span id="finalresult"></span>
</div>
</div>
<div id="dataplot" class="plot">
</div>
<img id="jpg-export">
<script type="text/javascript">
$(window).load(function(){
"use strict";
var subject = 'test';
var blocknumber = 1;
var heights = ["0.01", "0.02", "0.03", "0.04", "0.05"];
// var originaldensities = ["74", "76", "79", "82", "84", "87", "90", "93", "97", "100", "103", "107", "111", "114", "118", "122", "127", "131", "136", "140", "145", "150", "155", "160", "166", "172", "178", "184", "190", "197", "203", "210", "218", "225", "233", "241", "249", "258", "266", "276", "285", "295"];
var originaldensities = ["74", "79", "84", "90", "97", "103", "111", "118", "122", "131", "136", "145", "150", "160", "172", "184","197", "210", "225", "233", "241", "258", "266", "276", "285", "295"];
var densities = ["74","82","90","100","111","122","136","150","166","184","203","225","249","276","295"];
var blurs = ["0.2", "0.4", "0.6", "0.8", "1.0", "1.2", "1.4", "1.6", "1.8", "2.0", "2.2", "2.4", "2.6", "2.8", "3.0"];
var illuminations = ["sidelit","backlit"];
var db_path = 'jpg';
var numHeights = heights.length;
var numDensities = densities.length;
var numBlurs = blurs.length;
var numIlluminations = illuminations.length;
//densities and blurs are the values that differ between match and target.
var matchblurindex = 5; //match blur is always at a fixed value.
//var targetdensities = ["114","140","178","218"];
var targetdensities = ["90","111","136","150","184","225"];
var targetblurs = ["0.4","1.0","1.4", "2.0","2.8"];
var targetheights = heights;
var t_blurs = [];
var t_densities = [];
var t_heights = [];
var t_illuminations = [];
var ready = false, loaded = 0;
var img = new Array(2);
// // generate randomized conditions.
// for (var k=0;k<numIlluminations;k++) {
// for (var n=0;n<numHeights;n++){
// for(var i=0;i<targetdensities.length;i++){
// for(var j=0;j<targetblurs.length;j++){
// t_blurs.push(targetblurs[j]);
// t_densities.push(targetdensities[i]);
// t_heights.push(heights[n]);
// t_illuminations.push(illuminations[k]);
// }
// }
// }
// }
// var currentHeight = 0;
// var currentBlur = matchblurindex;
// var currentDensity = 1;
// var currentIllumination = 0;
// var matchdensityindex = 1;
// var targetheightindex = 0;
var curTrial = 0;
var result = [];
var editing = false;
var chosen = "";
//shuffle an array
/* Array.prototype.shuffle = function() {
var tmp, rand;
for(var i =0; i < this.length; i++){
rand = Math.floor(Math.random() * this.length);
tmp = this[i];
this[i] = this[rand];
this[rand] = tmp;
}
}
*/
var indices = [];
function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if(pair[0] == variable) return pair[1];
}
return false;
}
// read the condition file from server
$(function() {
subject = prompt("Please enter your initials");
var bn = getQueryVariable("blocknumber");
blocknumber = bn ? bn : 1;
var base = "conditions/block", filetype = '.csv';
var conditionfile = base.concat(blocknumber, filetype);
$.ajax({
type: "Get",
url: conditionfile,
async: false,
dataType: "text",
success: function(data) {processData(data);}
});
});
var condition_index;
var left_indices;
var right_indices;
var height_index;
var blur_index;
var lighting_index;
function processData(thedata) {
"use strict";
condition_index = [];
left_indices = [];
right_indices = [];
height_index = [];
blur_index = [];
lighting_index = [];
var condition_data = $.csv.toArrays(thedata);
for (var i=1;i<condition_data.length;i++) {
condition_index.push(condition_data[i][0]);
left_indices.push(condition_data[i][2]);
right_indices.push(condition_data[i][3]);
height_index.push(condition_data[i][4]);
blur_index.push(condition_data[i][5]);
lighting_index.push(condition_data[i][6]);
}
}
//alert(blur_index);
//alert(left_indices.length);
//indices for left and right images, this should be reading from a file.
//var left_indices =[95,9,4,5,12,15,8,24,41,83];
//var right_indices =[87,2,10,11,6,7,13,17,49,88];
var totalconditions = 70;
//console.log("Block number = " + blocknumber);
// final result object.
var data = {
subject:subject,
blocknumber:blocknumber,
trialnumber:[],
choices:[],
targetblurvalues:[],
targetilluminations:[],
targetvalue:[], //target densities
targetheightsvalues:[],
matchblurvalues:[],
matchilluminations:[],
matchvalue:[], //match densities
matchheightsvalues:[]
};
// this is for the user to go to the Next trial, where it updates both match and target.
var generateWebpage = function(){
//setTimeout(addBorder,500);
setTimeout(function(){
//$(this).addClass('highlight');
$("#mainTable").css("display", "none");
$("#Nexttrial").css("display", "none");
$("#selection").css("display", "none");
$("#loading_icon").css("display", "block");
// if trial number is less than the total trial number,start a new pair.
if (curTrial <= totalconditions){
if(curTrial<totalconditions){
$('#curTrial').text(curTrial);
}
//this is the image index of the target image.
var left_index = left_indices[curTrial-1];
var right_index = right_indices[curTrial-1];
var fnames = [];
var a = Math.random();
if (a>0.5){
var leftdensity = originaldensities[left_index];
var rightdensity = originaldensities[right_index];
}
else{
var leftdensity = originaldensities[right_index];
var rightdensity = originaldensities[left_index];
}
// randimize left or right order
fnames.push('jpg/soap_map_b' + blurs[blur_index[curTrial-1]] + '_s' + heights[height_index[curTrial-1]] + '_'
+ illuminations[lighting_index[curTrial-1]] + '_d' + leftdensity + '_q4096.jpg');
fnames.push('jpg/soap_map_b' + blurs[blur_index[curTrial-1]] + '_s' + heights[height_index[curTrial-1]] + '_'
+ illuminations[lighting_index[curTrial-1]] + '_d' + rightdensity + '_q4096.jpg');
//console.log(fnames);
//console.log(t_blurs[image_index] + ' <=> ' + blurs[matchblurindex]);
ready = false; loaded = 0;
var img = new Array(2);
for ( var i = 0; i < 2; ++i ) {
img[i] = new Image();
img[i].onload = function() {
if ( ++loaded == fnames.length ) {
setTimeout(function(){
$("img#sample").attr("src", fnames[0]);
$("img#sample").removeClass('highlight');
$("img#match").attr("src", fnames[1]);
$("img#match").removeClass('highlight');
$("#mainTable").css("display", "block");
$("#Nexttrial").css("display", "block");
$("#selection").css("display", "block");
$("#loading_icon").css("display", "none");
//$('#label_left').html(leftdensity);
//$('#label_right').html(rightdensity);
$("#finalresult").html(data.choices);
ready = true;
}, 250);
}
};
img[i].src = fnames[i];
}
// save the user's responses of previous trials.
if (curTrial<=totalconditions){
data.trialnumber.push(curTrial-1);
data.choices.push(chosen);
data.targetvalue.push(leftdensity);
data.matchvalue.push(rightdensity);
data.targetilluminations.push(illuminations[lighting_index[curTrial-1]]);
data.targetblurvalues.push(blurs[blur_index[curTrial-1]]);
data.targetheightsvalues.push(heights[height_index[curTrial-1]]);
data.matchilluminations.push(illuminations[lighting_index[curTrial-1]]);
data.matchblurvalues.push(blurs[blur_index[curTrial-1]]);
data.matchheightsvalues.push(heights[height_index[curTrial-1]]);
}
if (curTrial>=totalconditions){
// push in the last response
data.choices.push(chosen);
$("img").hide();
$("#Next").hide();
$("#instruction").hide();
$("#selection").hide();
//$("#curTrial").text('62');
$('#label_left').hide();
$('#label_right').hide();
//if (button.text() === "Back") {
//$("buttons").text("You are done!");
//}
//alert(data.choices);
document.getElementById("finalresult").innerHTML = data.choices;
//////Generate the plot after experiment is done.
$.ajax({
type: "POST",
dataType : 'json',
async: false,
url: 'paired_comparison_result/saveresults.php',
data: { data: JSON.stringify(data) },
success: function () {alert("Thanks!"); },
failure: function() {alert("Error!");}
});
}//here is end of plotting, saving data, etc.
}
// if the experiment is over, plot the results and save plot.
}, 500);
}
$('.leftright').click(function() {
curTrial = curTrial + 1;
$('img.highlight').removeClass('highlight');
$(this).toggleClass('highlight');
var id = $(this).attr("id");
//alert(id);
if (id === "sample") {
chosen = 'left';}
else {
chosen = 'right';
}
generateWebpage();
});
$("#Next").click(function() {
curTrial = curTrial - 1;
generateWebpage();
})
//radio button
// $('input:radio[name="radioSelection"]').change(function() {
// if ($(this).val() == 'Left') {
// if (ready){
// chosen = $(this).val();
// }
// }
// if ($(this).val() == 'Right') {
// if (ready){
// chosen = $(this).val();
// }
// }
// });
});
</script>
</body>
</html>