-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExperiment_Server_Blocks_withoutpreloading.html
519 lines (492 loc) · 19.1 KB
/
Experiment_Server_Blocks_withoutpreloading.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
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="jquery/jquery-1.9.1.js"></script>
<script src="plotly/plotly-latest.min.js"></script>
<script
src="http://code.jquery.com/ui/1.12.1/jquery-ui.min.js"
integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU="
crossorigin="anonymous"></script>
<link rel="stylesheet" type="text/css" href="Experiment.css">
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script type="text/javascript">//<![CDATA[
$(window).load(function(){
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 densities = ["74", "79", "84", "90", "97", "103", "111", "118", "127", "136", "145", "155", "166", "178", "190", "203", "218", "233", "249", "266", "285", "295"];
// every fourth.
//var densities = ["74", "84", "97", "111", "127", "145","166", "190", "218", "249", "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 = ["111","150","184","225"];
var targetblurs = ["0.4","1.0","2.0","2.8"];
var targetheights = heights;
var t_blurs = [];
var t_densities = [];
var t_heights = [];
var t_illuminations = [];
// slider values
$("#densityVal").slider();
$("#densityVal").slider("option", "min", 0);
$("#densityVal").slider("option", "max", numDensities - 1);
$("#densityVal").slider("option", "value", 0);
///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]);
}
}
;}
}
//target densities
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_densities.push(targetdensities[i]);
}
}
;}
}
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_heights.push(heights[n]);
}
}
;}
}
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_illuminations.push(illuminations[k]);
}
}
;}
}
var currentHeight = 0;
var currentBlur = matchblurindex ;
var currentDensity = 1;
var currentIllumination = 0;
var matchdensityindex = 1;
var targetheightindex = 0;
var totalconditions = 40;
var curTrial = 0;
var result = [];
var editing = false;
//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);
}
var my_json_new = [];
$(function(){
subject = prompt("Please enter your initials");
//blocknumber = prompt("Please enter the block number");
blocknumber = getQueryVariable("blocknumber");
base = "conditions/block";
filetype = '.json';
var conditionfile = base.concat(blocknumber, filetype);
$.ajax({
url: conditionfile ,
async: false,
dataType: 'json',
success: function(json){
for (var i = 0, len = json.length; i < len; i++) {
my_json_new.push(json[i]);
}
}
});
});
indices = my_json_new;
// final result object.
var data = {
subject:subject,
blocknumber:blocknumber,
matchblurindex: matchblurindex,
conditionOrder: indices,
trialnumber:[],
response:[],
targetblurvalues:[],
targetvalueindex:[],
targetheightindex:[],
targetilluminations:[],
targetblurindex:[],
targetvalue:[], //target densities
targetheightsvalues:[]
};
//alert(targetdensities);
// User clicks on a cell
$('td').click(function() {
currCell = $(this);
edit();
});
// Show edit box
function edit() {
editing = true;
currCell.toggleClass("editing");
$('#edit').show();
$('#edit #text').val(currCell.html());
$('#edit #text').select();
}
// User saves edits
$('#edit form').submit(function(e) {
editing = false;
e.preventDefault();
// Ajax to update value in database
$.get('#', '', function() {
$('#edit').hide();
currCell.toggleClass("editing");
currCell.html($('#edit #text').val());
currCell.focus();
});
});
// this is for the user to go to the Next trial, where it updates both match and target.
$("#Next").click(function(){
var button = $(this);
if (button.text() === "Start") {
button.text("Next");
}
// if trial number is less than the total trial number,start a new pair.
if (curTrial <= totalconditions){
curTrial = curTrial + 1;
if(curTrial<=totalconditions){
$('#curTrial').text(curTrial);
}
// generate indices for each parameter from the condition array.
// if (curTrial>125){
// currentIllumination = 1;
// }
// set the currentDensity of the next image to a random value.
//currentDensity = matchdensityindex;
// targetdensityindex = Math.floor(((curTrial-1)%(targetdensities.length*targetblurs.length))/numHeights);
// targetblurindex = (curTrial-1)%targetdensities.length;
// targetheightindex = Math.floor((curTrial-1)/(targetdensities.length*targetblurs.length));
// current trial target densities.
//$('span#targetdensity').text(t_densities[indices[curTrial-1]]);
// $('span#targetblur').text(t_blurs[curTrial-1]);
//$('span#targetheight').text(t_heights[curTrial-1]);
// // match and target has the same relief height and illumination. Match has a fixed blur value that is different the target. Observer adjust densities of match.
var image_index = indices[curTrial-1];
if (t_densities[image_index]>160){
matchdensityindex = 0;
}
else if(t_densities[image_index]<160){
matchdensityindex = numDensities-1;
}
//$("#densityVal").slider("value", $("#densityVal").slider("option", "min"));
$("#densityVal").slider("option", "value", matchdensityindex);
$('img#match').attr('src', 'jpg/soap_map_b' + blurs[matchblurindex] + '_s' + t_heights[image_index] + '_' + t_illuminations[image_index ] + '_d' + densities[matchdensityindex] + '_q4096.jpg');
$('img#sample').attr('src', 'jpg/soap_map_b' + t_blurs[image_index] + '_s' + t_heights[image_index] + '_' + t_illuminations[image_index] + '_d' + t_densities[image_index] + '_q4096.jpg');
// save the user's responses of previous trials.
if (curTrial<=totalconditions){
data.trialnumber.push(curTrial-1);
data.targetilluminations.push(t_illuminations[image_index])
data.targetvalue.push(t_densities[image_index]);
data.targetblurvalues.push(t_blurs[image_index]);
data.targetheightsvalues.push(t_heights[image_index]);
data.targetvalueindex.push((t_densities[image_index]/10));
data.targetblurindex.push(t_blurs[image_index]*10+10);
data.targetheightindex.push(t_heights[image_index]*200+10);
}
if (curTrial>1){
data.response.push(densities[currentDensity])
}
currentDensity = matchdensityindex;
if (curTrial>totalconditions){
$("img").hide();
$( "#buttons" ).hide();
$( "#instruction" ).hide();
if (button.text() === "Next") {
button.text("You are done!");
}
document.getElementById("finalresult").innerHTML = data.response;
document.getElementById("finalresulttarget").innerHTML = data.targetvalue;
//////Generate the plot after experiment is done.
$.ajax
({
type: "POST",
dataType : 'json',
async: false,
url: 'phpcode/saveresults.php',
data: { data: JSON.stringify(data) },
success: function () {alert("Thanks!"); },
failure: function() {alert("Error!");}
});
// TESTER = document.getElementById('dataplot');
// var trace1 = {
// x: data.targetvalue,
// y: data.response,
// mode: 'markers',
// marker:{
// size:data.targetheightindex,
// color:data.targetblurindex
// }
// };
// var trace2 = {
// x: numeric.linspace(60,260),
// y: numeric.linspace(60,260),
// mode: 'scatter',
// marker: {
// color: 'rgb(122, 142, 142)',
// size: 12
// },
// };
// var datamatrix = [ trace1,trace2 ];
// var layout = {
// title:'Scatter Plot: darker color has higher blur',
// showlegend: false,
// xaxis: {
// range: [60, 260],
// title: 'Target density',
// zeroline: true
// },
// yaxis: {
// range: [60, 260],
// title: 'Match density',
// zeroline: true
// }
// };
// var trace3 = {
// x: data.targetheightindex,
// y: data.response,
// mode: 'markers',
// marker:{
// size:data.targetvalueindex,
// color:data.targetblurindex
// }
// };
// datamatrix2 = [trace3];
// var layout2 = {
// title:'Match density versus Height',
// showlegend: false,
// xaxis: {
// range: [10, 24],
// title: 'Target heights',
// zeroline: true
// },
// yaxis: {
// range: [60, 260],
// title: 'Match density',
// zeroline: true
// }
// };
// //Plotly.newPlot(TESTER, datamatrix, layout);
// Plotly.newPlot(TESTER, datamatrix2, layout2);
//starting the sever side communication.
//save the data to the file evoking serverside code.
// save data object as JSON.
// end the communicaiton with server.
}//here is end of plotting, saving data, etc.
}
// if the experiment is over, plot the results and save plot.
});
// user click on button to change images
// slider
$(function () {
$("#densityVal").on("slide", function(event, ui) {
$('img#match').attr('src', 'jpg/soap_map_b' + blurs[matchblurindex] + '_s' + t_heights[indices[curTrial-1]] + '_' + t_illuminations[indices[curTrial-1]] + '_d' + densities[$(this).slider("option", "value")] + '_q4096.jpg');
// update the currentDensity with the slider value.
currentDensity = $(this).slider("option", "value");
});
});
// $(function() {
// var changed = false;
// $('#densityUp, #densityDown').click(function () {
// //alert(currentDensity);
// if (this.id == 'densityDown') {
// if (currentDensity + 1 < numDensities) {
// $('#densityUp').css('background', '#768d87');
// currentDensity = currentDensity + 1;
// changed = true;
// }
// else if (currentDensity+1 == numDensities){
// $(this).css('background', '#D3D3D3');
// }
// }
// else if (this.id == 'densityUp') {
// if (currentDensity - 1 > -1) {
// $('#densityDown').css('background', '#768d87');
// currentDensity = currentDensity - 1;
// changed = true;
// }
// else if (currentDensity == 0){
// $(this).css('background', '#D3D3D3');
// }
// }
// // If we didn't hit a boundary, update the current cell
// if (changed) {
// //$('span#height').text(targetheights[targetheightindex]);
// //$('span#blur').text(blurs[4]);
// //$('span#density').text(densities[currentDensity]);
// //$('span#illumination').text(illuminations[currentIllumination])
// $('img#match').attr('src', 'jpg/soap_map_b' + blurs[matchblurindex] + '_s' + t_heights[indices[curTrial-1]] + '_' + t_illuminations[indices[curTrial-1]] + '_d' + densities[currentDensity] + '_q4096.jpg');
// }
// });
// });
// User navigates table using keyboard
$(document).keydown(function(e) {
var c = "";
var changed = false;
if (e.which == 38) {
// Right Arrow
if (currentBlur + 1 < numBlurs) {
//currentBlur = currentBlur + 1;
//changed = true;
}
} else if (e.which == 40) {
// Left Arrow
if (currentBlur - 1 > -1) {
//currentBlur = currentBlur - 1;
//changed = true;
}
} else if (e.which == 39) {
// Right Arrow
if (currentDensity + 1 < numDensities) {
//$('#densityUp').css('background', '#768d87');
currentDensity = currentDensity + 1;
$("#densityVal").slider("value", currentDensity);
changed = true;
}
else if (currentDensity+1 == numDensities){
$('#densityDown').css('background', '#D3D3D3');
}
} else if (e.which == 37) {
// left Arrow
if (currentDensity - 1 > -1) {
//$('#densityDown').css('background', '#768d87');
currentDensity = currentDensity - 1;
$("#densityVal").slider("value", currentDensity);
changed = true;
}
else if (currentDensity == 0){
$('#densityUp').css('background', '#D3D3D3');
}
// } else if (e.which == 50) {
// // Key 2
// if (currentHeight + 1 < numHeights) {
// currentHeight = currentHeight + 1;
// changed = true;
// }
// } else if (e.which == 49) {
// // Key 1
// if (currentHeight - 1 > -1) {
// currentHeight = currentHeight - 1;
// changed = true;
// }
} else if (e.which == 69) {
// Key e
if (currentIllumination == 0) {
currentIllumination = 1;
} else {
currentIllumination = 0;
}
changed = true;
}
// If we didn't hit a boundary, update the current cell
if (changed) {
// $('span#height').text(targetheights[targetheightindex]);
// $('span#blur').text(blurs[4]);
//$('span#density').text(densities[currentDensity]);
// $('span#illumination').text(illuminations[currentIllumination]);
$('img#match').attr('src', 'jpg/soap_map_b' + blurs[matchblurindex] + '_s' + t_heights[indices[curTrial-1]] + '_' + t_illuminations[indices[curTrial-1]] + '_d' + densities[currentDensity] + '_q4096.jpg');
}
});//]]>
});
</script>
</head>
<body>
<!-- <div>press 1/2 to change height. Current: <span id="height">0.05</span></div>
<div>press left/right to change blur. Current: <span id="blur">0.00</span></div> -->
<!-- <div>press up/down to change density. Current: <span id="density">79</span></div> -->
<!-- <div>press e to switch illumination. Current: <span id="illumination">sidelit</span></div> -->
<!--
<img id="sample" src="png/soap_map_b0.0_s0.05_d100_q4096.png" /> -->
<table style="margin-bottom:20pt" width = "800" border = "0">
<td>
<div id="instruction">
<h2 style="margin-bottom:10pt" align = "center">Material Matching Task<br /></h2>
<p id = "intro.part1"><font size = "3" face = "verdana" font color = #347235>The soap in the images are made with different materials. Your task is to match the material properties of the soap in the right image to the left. To do so, you adjust the "opacity" of the object in the right image (match) to match the perceived translucency to the object on the left (target). Notice that from trial to trial, the lighting direction can change (either side-lit or back-lit).
</br>
</br>
You can use either the left and right arrow keys or the slider to adjust the match image.
PLEADE don't use both within the same trial. The left arrow key makes the object appear less opaque and the right key makes the object appear more opaque. Please examine the images carefully before you hit "Next" button when your match will be recorded. Notice, there will be four blocks of the experiment. Please press "start" button to start the trials.</p>
</div>
</td>
</table>
<!-- <div><td><center><input id="btntest" type="button" class="StartButton" value="Start the experiment"
onclick="return btntest_onclick()"/></center></td></div> -->
<div id="images">
<center>
<table border="0", width="804" cellpadding="0">
<tr>
<td id = "target"><center><b>Target</b><!-- <div>Target density: <span id="targetdensity">97</span></div><div>Target blur: <span id="targetblur">0.4</span></div>
<div>Target height: <span id="targetheight">0.01</span></div> -->
</center></td>
<td id = "match"><center> <b>Match</b></center></td>
</tr>
<tr>
<td align = "left" >
<img id = "sample" src="jpg/soap_map_b0.4_s0.01_sidelit_d100_q4096.jpg" width = "590" height = "350"/>
</td>
<td align = "right" >
<img id = "match" src="jpg/soap_map_b1.2_s0.02_sidelit_d131_q4096.jpg" width = "590" height = "350"/>
</td>
</table>
<!-- <div id='buttons'>
<input type = "button" id = "densityUp" class = 'myButton' value="LessOpaque" onClick="changeMatchValues('densityUp')">
<input type = "button" id = "densityDown" class = 'myButton' value="More Opaque" onClick="changeMatchValues('densityDown')">
</div> -->
<div id="density" style="margin-bottom: 10px">
Density control:
<!--<input id="densityVal" type="range">-->
<div id="densityVal" style="width:400px; margin: 10px"></div>
</div>
<div id='Nexttrial'>
<TABLE>
Progress: Trial <span id="curTrial">0</span>/40</div>
<button type="button" id = "Next" onClick="GotoNextTrial()" value ="Start" class="NextButton" >Start</button>
</TABLE>
</div>
</br>
<div>Your final matched densities: <span id="finalresult"></span>
Your target densities: <span id="finalresulttarget"></span></div
</center>
</div>
<div id="dataplot" class="plot"></div>
</div>
<img id="jpg-export"></img>
</form>
</body>
</html>