-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExperiment_Server_Blocks.html
More file actions
349 lines (314 loc) · 15.3 KB
/
Experiment_Server_Blocks.html
File metadata and controls
349 lines (314 loc) · 15.3 KB
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
<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="http://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></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">
</head>
<body>
<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" 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.
PLEASE 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 id="images" style="text-align: center">
<table id="mainTable" border="0" width="804" cellpadding="0">
<tr>
<td id="target"><center><b>Target</b></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>
</tr>
</table>
<img id="loading_icon" src="loading-icon.gif" alt="loading" style="margin: 0 auto 0 auto; display:none">
<div id="density" style="margin-bottom: 10px; display: none">
Density control:
<!--<input id="densityVal" type="range">-->
<div id="densityVal" style="width:400px; margin: 10px"></div>
</div>
<div id='Nexttrial'>
Progress: Trial <span id="curTrial">0</span>/40<br>
<button type="button" id="Next" value="Start" class="NextButton" >Start</button>
</div>
<br>
<div>
Your final matched densities: <span id="finalresult"></span>
Your target densities: <span id="finalresulttarget"></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 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 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 = [];
var ready = false, loaded = 0;
var images = new Array(numDensities + 1);
// 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]);
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 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");
var bn = getQueryVariable("blocknumber");
blocknumber = bn ? bn : 1;
var 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;
console.log("Block number = " + blocknumber);
// 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");
}
$("#mainTable").css("display", "none");
$("#density").css("display", "none");
$("#Nexttrial").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){
curTrial = curTrial + 1;
if(curTrial<=totalconditions){
$('#curTrial').text(curTrial);
}
var image_index = indices[curTrial-1];
matchdensityindex = t_densities[image_index]>160 ? 0 : numDensities - 1;
$("#densityVal").slider("option", "value", matchdensityindex);
var fnames = [];
fnames.push('jpg/soap_map_b' + t_blurs[image_index] + '_s' + t_heights[image_index] + '_'
+ t_illuminations[image_index] + '_d' + t_densities[image_index] + '_q4096.jpg?p=' + Date.now());
for ( var i = 0; i < numDensities; ++i )
fnames.push('jpg/soap_map_b' + blurs[matchblurindex] + '_s' + t_heights[image_index] + '_'
+ t_illuminations[image_index] + '_d' + densities[i] + '_q4096.jpg?p=' + Date.now());
//console.log(fnames);
console.log(t_blurs[image_index] + ' <=> ' + blurs[matchblurindex]);
ready = false; loaded = 0;
for ( var i = 0; i <= numDensities; ++i ) {
images[i] = new Image();
images[i].onload = function() {
if ( ++loaded == numDensities + 1 ) {
$("img#sample").attr("src", fnames[0]);
$("img#match").attr("src", fnames[matchdensityindex + 1]);
$("#mainTable").css("display", "block");
$("#density").css("display", "inline-block");
$("#Nexttrial").css("display", "block");
$("#loading_icon").css("display", "none");
ready = true;
}
};
images[i].src = fnames[i];
}
// 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!");}
});
}//here is end of plotting, saving data, etc.
}
// if the experiment is over, plot the results and save plot.
});
// Slider
$(function () {
$("#densityVal").on("slide", function(event, ui) {
if ( ready ) {
currentDensity = $(this).slider("option", "value");
$('img#match').attr('src', images[currentDensity + 1].src);
}
});
});
// User navigates table using keyboard
$(document).keydown(function(e) {
if ( ready ) {
var changed = false;
switch ( e.which ) {
case 39: // Right Arrow
if (currentDensity + 1 < numDensities) {
++currentDensity;
$("#densityVal").slider("value", currentDensity);
changed = true;
}
break;
case 37: // Left Arrow
if (currentDensity > 0) {
--currentDensity;
$("#densityVal").slider("value", currentDensity);
changed = true;
}
break;
}
if (changed) {
$('img#match').attr('src', images[currentDensity + 1].src);
}
}
});
});
</script>
</body>
</html>