annotate analyse.html @ 813:f452455b5977

Resolved #1394: Python returns same XML responses as the PHP server
author Nicholas Jillings <nicholas.jillings@eecs.qmul.ac.uk>
date Fri, 27 Nov 2015 12:09:49 +0000
parents
children babd5366db49 888292c88c33
rev   line source
nicholas@813 1 <!DOCTYPE html>
nicholas@813 2 <html lang="en">
nicholas@813 3 <head>
nicholas@813 4 <meta charset="utf-8">
nicholas@813 5
nicholas@813 6 <!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame
nicholas@813 7 Remove this if you use the .htaccess -->
nicholas@813 8 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
nicholas@813 9
nicholas@813 10 <title>Analysis</title>
nicholas@813 11 <meta name="description" content="Show results from subjective evaluation">
nicholas@813 12 <meta name="author" content="Brecht De Man">
nicholas@813 13
nicholas@813 14 <script type="text/javascript" src="https://www.google.com/jsapi"></script>
nicholas@813 15 <script type="text/javascript">
nicholas@813 16 // To aid 'one-page set-up' all scripts and CSS must be included directly in this file!
nicholas@813 17
nicholas@813 18 //google.load("visualization", "1", {packages:["corechart"]});
nicholas@813 19
nicholas@813 20 /*************
nicholas@813 21 * SETUP *
nicholas@813 22 *************/
nicholas@813 23 // folder where to find the XML files
nicholas@813 24 xmlFileFolder = "analysis_test";
nicholas@813 25 // array of XML files
nicholas@813 26 var xmlFiles = ['McG-A-2013-09.xml', 'McG-A-2014-03.xml', 'McG-A-2014-12.xml', 'McG-B-2013-09.xml',
nicholas@813 27 'McG-B-2014-03.xml', 'McG-B-2014-12.xml', 'McG-C-2013-09.xml', 'McG-C-2014-03.xml', 'McG-C-2014-12.xml',
nicholas@813 28 'McG-D-2013-09.xml', 'McG-D-2014-03.xml', 'McG-D-2014-12.xml', 'McG-E-2013-09.xml', 'McG-E-2014-03.xml',
nicholas@813 29 'McG-E-2014-12.xml', 'McG-F-2013-09.xml', 'McG-F-2014-03.xml', 'McG-F-2014-12.xml', 'McG-G-2014-03.xml',
nicholas@813 30 'McG-G-2014-12.xml', 'McG-H-2013-09.xml', 'McG-H-2014-03.xml', 'McG-H-2014-12.xml', 'McG-I-2013-09.xml',
nicholas@813 31 'McG-I-2014-03.xml', 'McG-J-2013-09.xml', 'McG-J-2014-03.xml', 'McG-K-2013-09.xml', 'McG-K-2014-03.xml',
nicholas@813 32 'McG-L-2013-09.xml', 'McG-L-2014-03.xml', 'McG-M-2013-09.xml', 'McG-M-2014-03.xml', 'McG-N-2013-09.xml',
nicholas@813 33 'McG-N-2014-03.xml', 'McG-O-2013-09.xml', 'McG-O-2014-03.xml', 'McG-P-2013-09.xml', 'McG-P-2014-03.xml',
nicholas@813 34 'McG-pro1-2013-09.xml', 'McG-pro1-2014-03.xml', 'McG-pro1-2014-12.xml', 'McG-pro2-2013-09.xml',
nicholas@813 35 'McG-pro2-2014-03.xml', 'McG-pro2-2014-12.xml', 'McG-Q-2014-12.xml', 'McG-R-2014-12.xml',
nicholas@813 36 'McG-S-2014-12.xml', 'McG-subA-2013-09.xml', 'McG-subA-2014-03.xml', 'McG-subB-2014-03.xml',
nicholas@813 37 'McG-subB-2014-12.xml', 'McG-subC-2013-09.xml', 'McG-subC-2014-03.xml', 'McG-subC-2014-12.xml',
nicholas@813 38 'McG-subD-2013-09.xml', 'McG-subD-2014-12.xml', 'McG-subE-2014-12.xml', 'McG-subG-2014-12.xml',
nicholas@813 39 'McG-subH-2013-09.xml', 'McG-T-2014-12.xml', 'McG-U-2014-12.xml', 'McG-V-2014-12.xml',
nicholas@813 40 'McG-W-2014-12.xml', 'McG-X-2014-12.xml', 'MG1-2013-09.xml', 'MG2-2013-09.xml', 'MG3-2013-09.xml',
nicholas@813 41 'MG4-2013-09.xml', 'MG5-2013-09.xml', 'MG6-2013-09.xml', 'MG7-2013-09.xml', 'MG8-2013-09.xml',
nicholas@813 42 'MG9-2013-09.xml', 'QM-1-1.xml', 'QM-1-2.xml', 'QM-10-1.xml', 'QM-11-1.xml', 'QM-11-2.xml', 'QM-12-1.xml', 'QM-12-2.xml',
nicholas@813 43 'QM-13-1.xml', 'QM-14-1.xml', 'QM-15-1.xml', 'QM-16-1.xml', 'QM-17-1.xml', 'QM-18-1.xml', 'QM-18-2.xml',
nicholas@813 44 'QM-18-3.xml', 'QM-19-1.xml', 'QM-2-1.xml', 'QM-2-2.xml', 'QM-2-3.xml', 'QM-20-1.xml', 'QM-20-2.xml',
nicholas@813 45 'QM-20-3.xml', 'QM-21-1.xml', 'QM-21-2.xml', 'QM-3-1.xml', 'QM-3-2.xml', 'QM-3-3.xml', 'QM-4-1.xml', 'QM-5-1.xml',
nicholas@813 46 'QM-5-2.xml', 'QM-6-1.xml', 'QM-6-2.xml', 'QM-7-1.xml', 'QM-7-2.xml', 'QM-8-1.xml', 'QM-9-1.xml',
nicholas@813 47 'PXL-L1.xml','PXL-L2.xml','PXL-L3.xml','PXL-L4.xml','PXL-L5.xml','PXL-S1.xml','PXL-S2.xml','PXL-S3.xml',
nicholas@813 48 'PXL-S4.xml','PXL-S5.xml','PXL-S6.xml','PXL-S7.xml','PXL-pro.xml','DU-A1.xml','DU-A2.xml','DU-B1.xml',
nicholas@813 49 'DU-B2.xml','DU-C1.xml','DU-C2.xml','DU-D1.xml','DU-D2.xml','DU-E1.xml','DU-F1.xml','DU-F2.xml','DU-G1.xml',
nicholas@813 50 'DU-G2.xml','DU-H1.xml','DU-H2.xml','DU-I2.xml','DU-J2.xml','DU-K1.xml','DU-K2.xml','DU-L1.xml','DU-L2.xml',
nicholas@813 51 'DU-M1.xml','DU-M2.xml','DU-N1.xml','DU-O1.xml','DU-O2.xml','DU-P1.xml','DU-P2.xml','DU-Q1.xml','DU-Q2.xml',
nicholas@813 52 'DU-R1.xml','DU-R2.xml','DU-S1.xml','DU-S2.xml','DU-T1.xml','DU-T2.xml','DU-U1.xml','DU-U2.xml','DU-U3.xml'];
nicholas@813 53 //['QM-1-1.xml','QM-2-1.xml','QM-2-2.xml','QM-2-3.xml','QM-3-1.xml','QM-3-2.xml','QM-4-1.xml','QM-5-1.xml','QM-5-2.xml','QM-6-1.xml','QM-6-2.xml','QM-7-1.xml','QM-7-2.xml','QM-8-1.xml','QM-9-1.xml','QM-10-1.xml','QM-11-1.xml','QM-12-1.xml','QM-12-2.xml','QM-13-1.xml','QM-14-1.xml','QM-15-1.xml','QM-16-1.xml','QM-17-1.xml','QM-18-1.xml','QM-18-2.xml','QM-18-3.xml','QM-19-1.xml','QM-20-1.xml','QM-20-2.xml','QM-20-3.xml','QM-21-1.xml','QM-21-2.xml'];
nicholas@813 54 //['McG-A-2014-03.xml','McG-B-2014-03.xml','McG-C-2014-03.xml','McG-D-2014-03.xml','McG-E-2014-03.xml','McG-F-2014-03.xml','McG-G-2014-03.xml','McG-H-2014-03.xml'];
nicholas@813 55
nicholas@813 56 //TODO: make retrieval of file names automatic / drag files on here
nicholas@813 57
nicholas@813 58 /****************
nicholas@813 59 * VARIABLES *
nicholas@813 60 ****************/
nicholas@813 61
nicholas@813 62 // Counters
nicholas@813 63 // How many files, audioholders, audioelementes and statements annotated (don't count current one)
nicholas@813 64 var numberOfFiles = -1;
nicholas@813 65 var numberOfaudioholders = -1;
nicholas@813 66 var numberOfaudioelementes = -1;
nicholas@813 67 var numberOfStatements = -1;
nicholas@813 68 var numberOfSkippedComments = 0;
nicholas@813 69
nicholas@813 70 // Object arrays
nicholas@813 71 var fileNameArray = [];
nicholas@813 72 var subjectArray = [];
nicholas@813 73 var audioholderArray = [];
nicholas@813 74 var audioelementArray = [];
nicholas@813 75
nicholas@813 76 // End of (file, audioholder, audioelement) flags
nicholas@813 77 var newFile = true;
nicholas@813 78 var newAudioHolder = true;
nicholas@813 79 var newAudioElement = true;
nicholas@813 80
nicholas@813 81 var fileCounter = 0; // file index
nicholas@813 82 var audioholderCounter=0; // audioholder index (current XML file)
nicholas@813 83 var audioelementCounter=0; // audioelement index (current audioholder)
nicholas@813 84 var statementNumber=0; // total number of statements
nicholas@813 85
nicholas@813 86 var root; // root of XML file
nicholas@813 87 var commentInFull = ''; // full comment
nicholas@813 88
nicholas@813 89 var playAudio = true; // whether corresponding audio should be played back
nicholas@813 90
nicholas@813 91 // // Measuring time
nicholas@813 92 // var lastTimeMeasured = -1; //
nicholas@813 93 // var durationLastAnnotation = -1; // duration of last annotation
nicholas@813 94 // var timeArray = [];
nicholas@813 95 // var MIN_TIME = 1.0; // minimum time counted as significant
nicholas@813 96 // var measurementPaused = false; // whether time measurement is paused
nicholas@813 97 // var timeInBuffer = 0; //
nicholas@813 98
nicholas@813 99 var topLevel;
nicholas@813 100 window.onload = function() {
nicholas@813 101 // Initialise page
nicholas@813 102 topLevel = document.getElementById('topLevelBody');
nicholas@813 103 var setup = document.createElement('div');
nicholas@813 104 setup.id = 'setupTagDiv';
nicholas@813 105 loadAllFiles();
nicholas@813 106 printSurveyData()
nicholas@813 107 //makePlots();
nicholas@813 108 // measure time at this point:
nicholas@813 109 lastTimeMeasured = new Date().getTime(); // in milliseconds
nicholas@813 110 };
nicholas@813 111
nicholas@813 112 // Assert function
nicholas@813 113 function assert(condition, message) {
nicholas@813 114 if (!condition) {
nicholas@813 115 message = message || "Assertion failed";
nicholas@813 116 if (typeof Error !== "undefined") {
nicholas@813 117 throw new Error(message);
nicholas@813 118 }
nicholas@813 119 throw message; // Fallback
nicholas@813 120 }
nicholas@813 121 }
nicholas@813 122
nicholas@813 123 function median(values) { // TODO: replace code by '50th percentile' - should be the same?
nicholas@813 124 values.sort( function(a,b) {return a - b;} );
nicholas@813 125 var half = Math.floor(values.length/2);
nicholas@813 126 if(values.length % 2)
nicholas@813 127 return values[half];
nicholas@813 128 else
nicholas@813 129 return (values[half-1] + values[half]) / 2.0;
nicholas@813 130 }
nicholas@813 131
nicholas@813 132 function percentile(values, n) {
nicholas@813 133 values.sort( function(a,b) {return a - b;} );
nicholas@813 134 // get ordinal rank
nicholas@813 135 var rank = Math.min(Math.floor(values.length*n/100), values.length-1);
nicholas@813 136 return values[rank];
nicholas@813 137 }
nicholas@813 138
nicholas@813 139 /***********************
nicholas@813 140 * TIME MEASUREMENT *
nicholas@813 141 ************************/
nicholas@813 142
nicholas@813 143 // measure time since last time this function was called
nicholas@813 144 function timeSinceLastCall() {
nicholas@813 145 // current time
nicholas@813 146 var currentTime = new Date().getTime();
nicholas@813 147 // calculate time difference
nicholas@813 148 var timeDifference = currentTime - lastTimeMeasured + timeInBuffer;
nicholas@813 149 // clear buffer (for pausing)
nicholas@813 150 timeInBuffer = 0;
nicholas@813 151 // remember last measured time
nicholas@813 152 lastTimeMeasured = currentTime;
nicholas@813 153 return timeDifference;
nicholas@813 154 }
nicholas@813 155
nicholas@813 156 // pause time measurement
nicholas@813 157 function pauseTimeMeasurement() {
nicholas@813 158 // UN-PAUSE
nicholas@813 159 if (measurementPaused) { // already paused
nicholas@813 160 // button shows 'pause' again
nicholas@813 161 document.getElementById('pauseButton').innerHTML = 'Pause';
nicholas@813 162 // toggle state
nicholas@813 163 measurementPaused = false;
nicholas@813 164 // resume time measurement
nicholas@813 165 lastTimeMeasured = new Date().getTime(); // reset time, discard time while paused
nicholas@813 166 } else { // PAUSE
nicholas@813 167 // button shows 'resume'
nicholas@813 168 document.getElementById('pauseButton').innerHTML = 'Resume';
nicholas@813 169 // toggle state
nicholas@813 170 measurementPaused = true;
nicholas@813 171 // pause time measurement
nicholas@813 172 timeInBuffer = timeSinceLastCall();
nicholas@813 173 }
nicholas@813 174 }
nicholas@813 175
nicholas@813 176 // show elapsed time on interface
nicholas@813 177 function showTimeElapsedInSeconds() {
nicholas@813 178 // if paused: un-pause
nicholas@813 179 if (measurementPaused) {
nicholas@813 180 pauseTimeMeasurement();
nicholas@813 181 }
nicholas@813 182
nicholas@813 183 // time of last annotation
nicholas@813 184 var lastAnnotationTime = timeSinceLastCall()/1000;
nicholas@813 185 document.getElementById('timeDisplay').innerHTML = lastAnnotationTime.toFixed(2);
nicholas@813 186 // average time over last ... annotations
nicholas@813 187 var avgAnnotationTime;
nicholas@813 188 var numberOfElementsToAverage =
nicholas@813 189 document.getElementById('numberOfTimeAverages').value;
nicholas@813 190 if (isPositiveInteger(numberOfElementsToAverage)) {
nicholas@813 191 avgAnnotationTime =
nicholas@813 192 calculateAverageTime(lastAnnotationTime,
nicholas@813 193 Number(numberOfElementsToAverage));
nicholas@813 194 } else {
nicholas@813 195 // change text field content to 'ALL'
nicholas@813 196 document.getElementById('numberOfTimeAverages').value = 'ALL';
nicholas@813 197 avgAnnotationTime = calculateAverageTime(lastAnnotationTime, -1);
nicholas@813 198 }
nicholas@813 199 document.getElementById('timeAverageDisplay').innerHTML = avgAnnotationTime.toFixed(2);
nicholas@813 200 }
nicholas@813 201
nicholas@813 202 // auxiliary function: is string a positive integer?
nicholas@813 203 // http://stackoverflow.com/questions/10834796/...
nicholas@813 204 // validate-that-a-string-is-a-positive-integer
nicholas@813 205 function isPositiveInteger(str) {
nicholas@813 206 var n = ~~Number(str);
nicholas@813 207 return String(n) === str && n >= 0;
nicholas@813 208 }
nicholas@813 209
nicholas@813 210 // calculate average time
nicholas@813 211 function calculateAverageTime(newTimeMeasurementInSeconds,numberOfPoints) {
nicholas@813 212 // append last measurement time to time array, if significant
nicholas@813 213 if (newTimeMeasurementInSeconds > MIN_TIME) {
nicholas@813 214 timeArray.push(newTimeMeasurementInSeconds);
nicholas@813 215 }
nicholas@813 216 // average over last N elements of this array
nicholas@813 217 if (numberOfPoints < 0 || numberOfPoints>=timeArray.length) { // calculate average over all
nicholas@813 218 var sum = 0;
nicholas@813 219 for (var i = 0; i < timeArray.length; i++) {
nicholas@813 220 sum += timeArray[i];
nicholas@813 221 }
nicholas@813 222 averageOfTimes = sum/timeArray.length;
nicholas@813 223 } else { // calculate average over specified number of times measured last
nicholas@813 224 var sum = 0;
nicholas@813 225 for (var i = timeArray.length-numberOfPoints; i < timeArray.length; i++) {
nicholas@813 226 sum += timeArray[i];
nicholas@813 227 }
nicholas@813 228 averageOfTimes = sum/numberOfPoints;
nicholas@813 229 }
nicholas@813 230 return averageOfTimes;
nicholas@813 231 }
nicholas@813 232
nicholas@813 233
nicholas@813 234 /********************************
nicholas@813 235 * PLAYBACK OF AUDIO *
nicholas@813 236 ********************************/
nicholas@813 237
nicholas@813 238 //PLAYaudioelement
nicholas@813 239 // Keep track of whether audio should be played
nicholas@813 240 function playFlagChanged(){
nicholas@813 241 playAudio = playFlag.checked; // global variable
nicholas@813 242
nicholas@813 243 if (!playAudio){ // if audio needs to stop
nicholas@813 244 audio.pause(); // stop audio - if anything is playing
nicholas@813 245 currently_playing = ''; // back to empty string so playaudioelement knows nothing's playing
nicholas@813 246 }
nicholas@813 247 }
nicholas@813 248
nicholas@813 249 // audioholder that's currently playing
nicholas@813 250 var currently_playing_audioholder = ''; // at first: empty string
nicholas@813 251 var currently_playing_audioelement = '';
nicholas@813 252 var audio;
nicholas@813 253
nicholas@813 254 // Play audioelement of audioholder if available, from start or from same position
nicholas@813 255 function playaudioelement(audioholderName, audioelementerName){
nicholas@813 256 if (playAudio) { // if enabled
nicholas@813 257 // get corresponding file from folder
nicholas@813 258 var file_location = 'audio/'+audioholderName + '/' + audioelementerName + '.mp3'; // fixed path and file name format
nicholas@813 259
nicholas@813 260 // if not available, show error/warning message
nicholas@813 261 //TODO ...
nicholas@813 262
nicholas@813 263 // if nothing playing yet, start playing
nicholas@813 264 if (currently_playing_audioholder == ''){ // signal that nothing is playing
nicholas@813 265 //playSound(audioBuffer);
nicholas@813 266 audio = new Audio(file_location);
nicholas@813 267 audio.loop = true; // loop when end is reached
nicholas@813 268 audio.play();
nicholas@813 269 currently_playing_audioholder = audioholderName;
nicholas@813 270 currently_playing_audioelement = audioelementerName;
nicholas@813 271 } else if (currently_playing_audioholder != audioholderName) {
nicholas@813 272 // if different audioholder playing, stop that and start playing
nicholas@813 273 audio.pause(); // stop audio
nicholas@813 274 audio = new Audio(file_location); // load new file
nicholas@813 275 audio.loop = true; // loop when end is reached
nicholas@813 276 audio.play(); // play audio from the start
nicholas@813 277 currently_playing_audioholder = audioholderName;
nicholas@813 278 currently_playing_audioelement = audioelementerName;
nicholas@813 279 } else if (currently_playing_audioelement != audioelementerName) {
nicholas@813 280 // if same audioholder playing, start playing from where it left off
nicholas@813 281 skipTime = audio.currentTime; // time to skip to
nicholas@813 282 audio.pause(); // stop audio
nicholas@813 283 audio = new Audio(file_location);
nicholas@813 284 audio.addEventListener('loadedmetadata', function() {
nicholas@813 285 this.currentTime = skipTime;
nicholas@813 286 console.log('Loaded '+audioholderName+'-'+audioelementerName+', playing from '+skipTime);
nicholas@813 287 }, false); // skip to same time when audio is loaded!
nicholas@813 288 audio.loop = true; // loop when end is reached
nicholas@813 289 audio.play(); // play from that time
nicholas@813 290 audio.currentTime = skipTime;
nicholas@813 291 currently_playing_audioholder = audioholderName;
nicholas@813 292 currently_playing_audioelement = audioelementerName;
nicholas@813 293 }
nicholas@813 294 // if same audioelement playing: keep on playing (i.e. do nothing)
nicholas@813 295 }
nicholas@813 296 }
nicholas@813 297
nicholas@813 298 /********************
nicholas@813 299 * READING FILES *
nicholas@813 300 ********************/
nicholas@813 301
nicholas@813 302 // Read necessary data from XML file
nicholas@813 303 function readXML(xmlFileName){
nicholas@813 304 if (window.XMLHttpRequest)
nicholas@813 305 {// code for IE7+, Firefox, Chrome, Opera, Safari
nicholas@813 306 xmlhttp=new XMLHttpRequest();
nicholas@813 307 }
nicholas@813 308 else
nicholas@813 309 {// code for IE6, IE5
nicholas@813 310 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
nicholas@813 311 }
nicholas@813 312 xmlhttp.open("GET",xmlFileName,false);
nicholas@813 313 xmlhttp.send();
nicholas@813 314 return xmlhttp.responseXML;
nicholas@813 315 }
nicholas@813 316
nicholas@813 317 // go over all files and compute relevant statistics
nicholas@813 318 function loadAllFiles() {
nicholas@813 319 // retrieve information from XMLs
nicholas@813 320
nicholas@813 321 for (fileIndex = 0; fileIndex < xmlFiles.length; fileIndex++) {
nicholas@813 322 xmlFileName = xmlFileFolder+"/"+xmlFiles[fileIndex];
nicholas@813 323 xml = readXML(xmlFileName);
nicholas@813 324 if (xml != null) { // if file exists
nicholas@813 325 // append file name to array of file names
nicholas@813 326 fileNameArray.push(xmlFiles[fileIndex]);
nicholas@813 327
nicholas@813 328 // get root of XML file
nicholas@813 329 root = xml.getElementsByTagName('browserevaluationresult')[0];
nicholas@813 330
nicholas@813 331 // get subject ID, add to array if not already there
nicholas@813 332 pretest = root.getElementsByTagName('pretest')[0];
nicholas@813 333 subjectID = pretest.getElementsByTagName('comment')[0];
nicholas@813 334 if (subjectID){
nicholas@813 335 if (subjectID.getAttribute('id')!='sessionId') { // warning in console when not available
nicholas@813 336 console.log(xmlFiles[fileIndex]+': no SessionID available');
nicholas@813 337 }
nicholas@813 338 if (subjectArray.indexOf(subjectID.textContent) == -1) { // if not already in array
nicholas@813 339 subjectArray.push(subjectID.textContent); // append to array
nicholas@813 340 }
nicholas@813 341 }
nicholas@813 342
nicholas@813 343 // go over all audioholders, add to array if not already there
nicholas@813 344 audioholderNodes = root.getElementsByTagName('audioholder');
nicholas@813 345 // go over audioholderNodes and append audioholder name when not present yet
nicholas@813 346 for (audioholderIndex = 0; audioholderIndex < audioholderNodes.length; audioholderIndex++) {
nicholas@813 347 audioholderName = audioholderNodes[audioholderIndex].getAttribute('id');
nicholas@813 348 if (audioholderArray.indexOf(audioholderName) == -1) { // if not already in array
nicholas@813 349 audioholderArray.push(audioholderName); // append to array
nicholas@813 350 }
nicholas@813 351 // within each audioholder, go over all audioelement IDs, add to array if not already there
nicholas@813 352 audioelementNodes = audioholderNodes[audioholderIndex].getElementsByTagName('audioelement');
nicholas@813 353 for (audioelementIndex = 0; audioelementIndex < audioelementNodes.length; audioelementIndex++) {
nicholas@813 354 audioelementName = audioelementNodes[audioelementIndex].getAttribute('id');
nicholas@813 355 if (audioelementArray.indexOf(audioelementName) == -1) { // if not already in array
nicholas@813 356 audioelementArray.push(audioelementName); // append to array
nicholas@813 357 }
nicholas@813 358 }
nicholas@813 359 }
nicholas@813 360 // count occurrences of each audioholder
nicholas@813 361 // ...
nicholas@813 362 }
nicholas@813 363 else {
nicholas@813 364 console.log('XML file '+xmlFileName+' not found.');
nicholas@813 365 }
nicholas@813 366 }
nicholas@813 367
nicholas@813 368 // sort alphabetically
nicholas@813 369 fileNameArray.sort();
nicholas@813 370 subjectArray.sort();
nicholas@813 371 audioholderArray.sort();
nicholas@813 372 audioelementArray.sort();
nicholas@813 373
nicholas@813 374 // display all information in HTML
nicholas@813 375 // show XML file folder
nicholas@813 376 document.getElementById('xmlFileFolder_span').innerHTML = "\""+xmlFileFolder+"/\"";
nicholas@813 377 // show number of files
nicholas@813 378 document.getElementById('numberOfFiles_span').innerHTML = fileNameArray.length;
nicholas@813 379 // show list of subject names
nicholas@813 380 document.getElementById('subjectArray_span').innerHTML = subjectArray.toString();
nicholas@813 381 // show list of audioholders
nicholas@813 382 document.getElementById('audioholderArray_span').innerHTML = audioholderArray.toString();
nicholas@813 383 // show list of audioelementes
nicholas@813 384 document.getElementById('audioelementArray_span').innerHTML = audioelementArray.toString();
nicholas@813 385 }
nicholas@813 386
nicholas@813 387 function printSurveyData() {
nicholas@813 388 // print some fields from the survey for different people
nicholas@813 389
nicholas@813 390 // go over all XML files
nicholas@813 391 for (fileIndex = 0; fileIndex < xmlFiles.length; fileIndex++) {
nicholas@813 392 xmlFileName = xmlFileFolder+"/"+xmlFiles[fileIndex];
nicholas@813 393 xml = readXML(xmlFileName);
nicholas@813 394 // make a div
nicholas@813 395 var div = document.createElement('div');
nicholas@813 396 document.body.appendChild(div);
nicholas@813 397 div.id = 'div_survey_'+xmlFileName;
nicholas@813 398 div.style.width = '1100px';
nicholas@813 399 //div.style.height = '350px';
nicholas@813 400
nicholas@813 401 // title for that div (subject id)
nicholas@813 402 document.getElementById('div_survey_'+xmlFileName).innerHTML = '<h2>'+xmlFileName+'</h2>';
nicholas@813 403
nicholas@813 404 // which songs did they do
nicholas@813 405 if (xml != null) { // if file exists
nicholas@813 406 // get root of XML file
nicholas@813 407 root = xml.getElementsByTagName('browserevaluationresult')[0];
nicholas@813 408 // go over all audioholders
nicholas@813 409 // document.getElementById('div_survey_'+xmlFileName).innerHTML += '<strong>Audioholders: </strong>';
nicholas@813 410 // audioholderNodes = root.getElementsByTagName('audioholder');
nicholas@813 411 // for (audioholderIndex = 0; audioholderIndex < audioholderNodes.length-1; audioholderIndex++) {
nicholas@813 412 // document.getElementById('div_survey_'+xmlFileName).innerHTML += audioholderNodes[audioholderIndex].getAttribute('id')+', ';
nicholas@813 413 // }
nicholas@813 414 // document.getElementById('div_survey_'+xmlFileName).innerHTML += audioholderNodes[audioholderNodes.length-1].getAttribute('id');
nicholas@813 415
nicholas@813 416 // survey responses (each if available)
nicholas@813 417 // get posttest node for total test
nicholas@813 418 childNodes = root.childNodes;
nicholas@813 419 posttestnode = null;
nicholas@813 420 for (idx = 0; idx < childNodes.length; idx++){
nicholas@813 421 if (childNodes[childNodes.length-idx-1].tagName == 'posttest') {
nicholas@813 422 posttestnode = childNodes[childNodes.length-idx-1];
nicholas@813 423 break;
nicholas@813 424 }
nicholas@813 425 }
nicholas@813 426
nicholas@813 427 // mix experience
nicholas@813 428 if (posttestnode) {
nicholas@813 429 posttestcomments = posttestnode.getElementsByTagName('comment');
nicholas@813 430 for (idx=0; idx < posttestcomments.length; idx++){
nicholas@813 431 commentsToPrint = ['generalExperience', 'interfaceExperience'];
nicholas@813 432 idAttribute = posttestcomments[idx].getAttribute('id');
nicholas@813 433 if (commentsToPrint.indexOf(idAttribute) >= 0) { // if exists?
nicholas@813 434 document.getElementById('div_survey_'+xmlFileName).innerHTML += '<br><strong>'+idAttribute+': </strong>'+posttestcomments[idx].textContent;
nicholas@813 435 }
nicholas@813 436 }
nicholas@813 437 }
nicholas@813 438 }
nicholas@813 439 }
nicholas@813 440 }
nicholas@813 441
nicholas@813 442 function makePlots() { //TODO: split into different functions
nicholas@813 443 // TEMPORARY
nicholas@813 444 makeTimeline(xmlFileFolder+"/"+xmlFiles[7]);
nicholas@813 445
nicholas@813 446 // create value array
nicholas@813 447 var ratings = []; // 3D matrix of ratings (audioholder, audioelement, subject)
nicholas@813 448 for (audioholderIndex = 0; audioholderIndex < audioholderArray.length; audioholderIndex++) {
nicholas@813 449 ratings.push([]);
nicholas@813 450 for (audioelementIndex = 0; audioelementIndex < audioelementArray.length; audioelementIndex++) {
nicholas@813 451 ratings[audioholderIndex].push([]);
nicholas@813 452 }
nicholas@813 453 }
nicholas@813 454
nicholas@813 455 // go over all XML files
nicholas@813 456 for (fileIndex = 0; fileIndex < xmlFiles.length; fileIndex++) {
nicholas@813 457 xmlFileName = xmlFileFolder+"/"+xmlFiles[fileIndex];
nicholas@813 458 xml = readXML(xmlFileName);
nicholas@813 459 if (xml != null) { // if file exists
nicholas@813 460 // get root of XML file
nicholas@813 461 root = xml.getElementsByTagName('browserevaluationresult')[0];
nicholas@813 462 // go over all audioholders
nicholas@813 463 audioholderNodes = root.getElementsByTagName('audioholder');
nicholas@813 464 for (audioholderIndex = 0; audioholderIndex < audioholderNodes.length; audioholderIndex++) {
nicholas@813 465 audioholderName = audioholderNodes[audioholderIndex].getAttribute('id');
nicholas@813 466 audioelementNodes = audioholderNodes[audioholderIndex].getElementsByTagName('audioelement');
nicholas@813 467 // go over all audioelements
nicholas@813 468 for (audioelementIndex = 0; audioelementIndex < audioelementNodes.length; audioelementIndex++) {
nicholas@813 469 audioelementName = audioelementNodes[audioelementIndex].getAttribute('id');
nicholas@813 470 // get value
nicholas@813 471 var value = audioelementNodes[audioelementIndex].getElementsByTagName("value")[0].textContent;
nicholas@813 472 if (value) { // if not empty, null, undefined...
nicholas@813 473 ratingValue = parseFloat(value);
nicholas@813 474 // add to matrix at proper position
nicholas@813 475 aHidx = audioholderArray.indexOf(audioholderName);
nicholas@813 476 aEidx = audioelementArray.indexOf(audioelementName);
nicholas@813 477 ratings[aHidx][aEidx].push(ratingValue);
nicholas@813 478 }
nicholas@813 479 }
nicholas@813 480 }
nicholas@813 481
nicholas@813 482 // go over all audioholders
nicholas@813 483
nicholas@813 484 // go over all audioelements within audioholder, see if present in idMatrix, add if not
nicholas@813 485 // add corresponding rating to 'ratings', at position corresponding with position in idMatrix
nicholas@813 486 }
nicholas@813 487 }
nicholas@813 488
nicholas@813 489 for (audioholderIndex = 0; audioholderIndex < audioholderArray.length; audioholderIndex++) {
nicholas@813 490 audioholderName = audioholderArray[audioholderIndex]; // for this song
nicholas@813 491 tickArray = []
nicholas@813 492
nicholas@813 493 raw_data = [['SubjectID', 'Rating']];
nicholas@813 494 audioElIdx = 0;
nicholas@813 495 for (audioelementIndex = 0; audioelementIndex<ratings[audioholderIndex].length; audioelementIndex++){
nicholas@813 496 if (ratings[audioholderIndex][audioelementIndex].length>0) {
nicholas@813 497 audioElIdx++; // increase if not empty
nicholas@813 498 // make tick label
nicholas@813 499 tickArray.push({v:audioElIdx, f: audioelementArray[audioelementIndex]});
nicholas@813 500 }
nicholas@813 501 for (subject = 0; subject<ratings[audioholderIndex][audioelementIndex].length; subject++){
nicholas@813 502 // add subject-value pair for each subject
nicholas@813 503 raw_data.push([audioElIdx, ratings[audioholderIndex][audioelementIndex][subject]]);
nicholas@813 504 }
nicholas@813 505 }
nicholas@813 506
nicholas@813 507 // create plot (one per song)
nicholas@813 508 var data = google.visualization.arrayToDataTable(raw_data);
nicholas@813 509
nicholas@813 510 var options = {
nicholas@813 511 title: audioholderName,
nicholas@813 512 hAxis: {title: 'audioelement ID', minValue: 0, maxValue: audioElIdx+1,
nicholas@813 513 ticks: tickArray},
nicholas@813 514 vAxis: {title: 'Rating', minValue: 0, maxValue: 1},
nicholas@813 515 seriesType: 'scatter',
nicholas@813 516 legend: 'none'
nicholas@813 517 };
nicholas@813 518 var div = document.createElement('div');
nicholas@813 519 document.body.appendChild(div);
nicholas@813 520 div.id = 'div_'+audioholderName;
nicholas@813 521 div.style.width = '1100px';
nicholas@813 522 div.style.height = '350px';
nicholas@813 523 var chart = new google.visualization.ComboChart(document.getElementById('div_'+audioholderName));
nicholas@813 524 chart.draw(data, options);
nicholas@813 525
nicholas@813 526 // box plots
nicholas@813 527 var div = document.createElement('div');
nicholas@813 528 document.body.appendChild(div);
nicholas@813 529 div.id = 'div_box_'+audioholderName;
nicholas@813 530 div.style.width = '1100px';
nicholas@813 531 div.style.height = '350px';
nicholas@813 532 // Get median, percentiles, maximum and minimum; outliers.
nicholas@813 533 pctl25 = [];
nicholas@813 534 pctl75 = [];
nicholas@813 535 med = [];
nicholas@813 536 min = [];
nicholas@813 537 max = [];
nicholas@813 538 outlierArray = [];
nicholas@813 539 max_n_outliers = 0; // maximum number of outliers for one audioelement
nicholas@813 540 for (audioelementIndex = 0; audioelementIndex<ratings[audioholderIndex].length; audioelementIndex++){
nicholas@813 541 med.push(median(ratings[audioholderIndex][audioelementIndex])); // median
nicholas@813 542 pctl25.push(percentile(ratings[audioholderIndex][audioelementIndex], 25)); // 25th percentile
nicholas@813 543 pctl75.push(percentile(ratings[audioholderIndex][audioelementIndex], 75)); // 75th percentile
nicholas@813 544 IQR = pctl75[pctl75.length-1]-pctl25[pctl25.length-1];
nicholas@813 545 // outliers: range of values which is above pctl75+1.5*IQR or below pctl25-1.5*IQR
nicholas@813 546 outliers = [];
nicholas@813 547 rest = [];
nicholas@813 548 for (idx = 0; idx<ratings[audioholderIndex][audioelementIndex].length; idx++){
nicholas@813 549 if (ratings[audioholderIndex][audioelementIndex][idx] > pctl75[pctl75.length-1]+1.5*IQR ||
nicholas@813 550 ratings[audioholderIndex][audioelementIndex][idx] < pctl25[pctl25.length-1]-1.5*IQR){
nicholas@813 551 outliers.push(ratings[audioholderIndex][audioelementIndex][idx]);
nicholas@813 552 }
nicholas@813 553 else {
nicholas@813 554 rest.push(ratings[audioholderIndex][audioelementIndex][idx]);
nicholas@813 555 }
nicholas@813 556 }
nicholas@813 557 outlierArray.push(outliers);
nicholas@813 558 max_n_outliers = Math.max(max_n_outliers, outliers.length); // update max mber
nicholas@813 559 // max: maximum value which is not outlier
nicholas@813 560 max.push(Math.max.apply(null, rest));
nicholas@813 561 // min: minimum value which is not outlier
nicholas@813 562 min.push(Math.min.apply(null, rest));
nicholas@813 563 }
nicholas@813 564
nicholas@813 565 // Build data array
nicholas@813 566 boxplot_data = [['ID', 'Span', '', '', '', 'Median']];
nicholas@813 567 for (idx = 0; idx < max_n_outliers; idx++) {
nicholas@813 568 boxplot_data[0].push('Outlier');
nicholas@813 569 }
nicholas@813 570 for (audioelementIndex = 0; audioelementIndex<ratings[audioholderIndex].length; audioelementIndex++){
nicholas@813 571 if (ratings[audioholderIndex][audioelementIndex].length>0) { // if rating array not empty for this audioelement
nicholas@813 572 data_array = [
nicholas@813 573 audioelementArray[audioelementIndex], // name
nicholas@813 574 min[audioelementIndex], // minimum
nicholas@813 575 pctl75[audioelementIndex],
nicholas@813 576 pctl25[audioelementIndex],
nicholas@813 577 max[audioelementIndex], // maximum
nicholas@813 578 med[audioelementIndex]
nicholas@813 579 ];
nicholas@813 580 for (idx = 0; idx < max_n_outliers; idx++) {
nicholas@813 581 if (idx<outlierArray[audioelementIndex].length){
nicholas@813 582 data_array.push(outlierArray[audioelementIndex][idx]);
nicholas@813 583 }
nicholas@813 584 else {
nicholas@813 585 data_array.push(null);
nicholas@813 586 }
nicholas@813 587 }
nicholas@813 588 boxplot_data.push(data_array);
nicholas@813 589 }
nicholas@813 590 }
nicholas@813 591
nicholas@813 592 // Create and populate the data table.
nicholas@813 593 var data = google.visualization.arrayToDataTable(boxplot_data);
nicholas@813 594 // Create and draw the visualization.
nicholas@813 595 var ac = new google.visualization.ComboChart(document.getElementById('div_box_'+audioholderName));
nicholas@813 596 ac.draw(data, {
nicholas@813 597 title : audioholderName,
nicholas@813 598 //width: 600,
nicholas@813 599 //height: 400,
nicholas@813 600 vAxis: {title: "Rating"},
nicholas@813 601 hAxis: {title: "audioelement ID"},
nicholas@813 602 seriesType: "line",
nicholas@813 603 pointSize: 5,
nicholas@813 604 lineWidth: 0,
nicholas@813 605 colors: ['black'],
nicholas@813 606 series: { 0: {type: "candlesticks", color: 'blue'}, // box plot shape
nicholas@813 607 1: {type: "line", pointSize: 10, lineWidth: 0, color: 'red' } }, // median
nicholas@813 608 legend: 'none'
nicholas@813 609 });
nicholas@813 610 }
nicholas@813 611 }
nicholas@813 612
nicholas@813 613 function makeTimeline(xmlFileName){ // WIP
nicholas@813 614 // Based on the XML file name, take time data and plot playback and marker movements
nicholas@813 615
nicholas@813 616 // read XML file and check if exists
nicholas@813 617 xml = readXML(xmlFileName);
nicholas@813 618 if (!xml) { // if file does not exist
nicholas@813 619 console.log('XML file '+xml+'does not exist. ('+xmlFileName+')')
nicholas@813 620 return; // do nothing; exit function
nicholas@813 621 }
nicholas@813 622 // get root of XML file
nicholas@813 623 root = xml.getElementsByTagName('browserevaluationresult')[0];
nicholas@813 624
nicholas@813 625 audioholder_time = 0;
nicholas@813 626 previous_audioholder_time = 0; // time spent before current audioholder
nicholas@813 627 time_offset = 0; // test starts at zero
nicholas@813 628
nicholas@813 629 // go over all audioholders
nicholas@813 630 audioholderNodes = root.getElementsByTagName('audioholder');
nicholas@813 631 for (audioholderIndex = 0; audioholderIndex < audioholderNodes.length; audioholderIndex++) {
nicholas@813 632 audioholderName = audioholderNodes[audioholderIndex].getAttribute('id');
nicholas@813 633 if (!audioholderName) {
nicholas@813 634 console.log('audioholder name is empty; go to next one. ('+xmlFileName+')');
nicholas@813 635 break;
nicholas@813 636 }
nicholas@813 637
nicholas@813 638 // subtract total audioholder length from subsequent audioholder event times
nicholas@813 639 audioholder_children = audioholderNodes[audioholderIndex].childNodes;
nicholas@813 640 foundIt = false;
nicholas@813 641 console.log(audioholder_children[2].getElementsByTagName("metricResult")) // not working!
nicholas@813 642 for (idx = 0; idx<audioholder_children.length; idx++) { // go over children
nicholas@813 643
nicholas@813 644 if (audioholder_children[idx].getElementsByTagName('metricResult').length) {
nicholas@813 645 console.log(audioholder_children[idx].getElementsByTagName('metricResult')[0]);
nicholas@813 646 if (audioholder_children[idx].getElementsByTagName('metricResult')[0].getAttribute('id') == "testTime"){
nicholas@813 647 audioholder_time = parseFloat(audioholder_children[idx].getElementsByTagName('metricResult')[0].textContent);
nicholas@813 648 console.log(audioholder_time);
nicholas@813 649 foundIt = true;
nicholas@813 650 }
nicholas@813 651 }
nicholas@813 652 }
nicholas@813 653 if (!foundIt) {
nicholas@813 654 console.log("Skipping audioholder without total time specified from "+xmlFileName+"."); // always hitting this
nicholas@813 655 break;
nicholas@813 656 }
nicholas@813 657
nicholas@813 658 audioelementNodes = audioholderNodes[audioholderIndex].getElementsByTagName('audioelement');
nicholas@813 659
nicholas@813 660 // make div
nicholas@813 661
nicholas@813 662 // draw chart
nicholas@813 663
nicholas@813 664 // legend with audioelement names
nicholas@813 665 }
nicholas@813 666 }
nicholas@813 667
nicholas@813 668 </script>
nicholas@813 669
nicholas@813 670
nicholas@813 671
nicholas@813 672 <style>
nicholas@813 673 div {
nicholas@813 674 padding: 2px;
nicholas@813 675 margin-top: 2px;
nicholas@813 676 margin-bottom: 2px;
nicholas@813 677 }
nicholas@813 678 div.head{
nicholas@813 679 margin-left: 10px;
nicholas@813 680 border: black;
nicholas@813 681 border-width: 2px;
nicholas@813 682 border-style: solid;
nicholas@813 683 }
nicholas@813 684 div.attrib{
nicholas@813 685 margin-left:25px;
nicholas@813 686 border: black;
nicholas@813 687 border-width: 2px;
nicholas@813 688 border-style: dashed;
nicholas@813 689 margin-bottom: 10px;
nicholas@813 690 }
nicholas@813 691 div#headerMatter{
nicholas@813 692 background-color: #FFFFCC;
nicholas@813 693 }
nicholas@813 694 div#currentStatement{
nicholas@813 695 font-size:3.0em;
nicholas@813 696 font-weight: bold;
nicholas@813 697
nicholas@813 698 }
nicholas@813 699 div#debugDisplay {
nicholas@813 700 color: #CCCCCC;
nicholas@813 701 font-size:0.3em;
nicholas@813 702 }
nicholas@813 703 span#scoreDisplay {
nicholas@813 704 font-weight: bold;
nicholas@813 705 }
nicholas@813 706 div#wrapper {
nicholas@813 707 width: 780px;
nicholas@813 708 border: 1px solid black;
nicholas@813 709 overflow: hidden; /* add this to contain floated children */
nicholas@813 710 }
nicholas@813 711 div#instrumentSection {
nicholas@813 712 width: 250px;
nicholas@813 713 border: 1px solid red;
nicholas@813 714 display: inline-block;
nicholas@813 715 }
nicholas@813 716 div#featureSection {
nicholas@813 717 width: 250px;
nicholas@813 718 border: 1px solid green;
nicholas@813 719 display: inline-block;
nicholas@813 720 }
nicholas@813 721 div#valenceSection {
nicholas@813 722 width: 250px;
nicholas@813 723 border: 1px solid blue;
nicholas@813 724 display: inline-block;
nicholas@813 725 }
nicholas@813 726 button#previousComment{
nicholas@813 727 width: 120px;
nicholas@813 728 height: 150px;
nicholas@813 729 font-size:1.5em;
nicholas@813 730 }
nicholas@813 731 button#nextComment{
nicholas@813 732 width: 666px;
nicholas@813 733 height: 150px;
nicholas@813 734 font-size:1.5em;
nicholas@813 735 }
nicholas@813 736 ul
nicholas@813 737 {
nicholas@813 738 list-style-type: none; /* no bullet points */
nicholas@813 739 margin-left: -20px; /* less indent */
nicholas@813 740 margin-top: 0px;
nicholas@813 741 margin-bottom: 5px;
nicholas@813 742 }
nicholas@813 743 </style>
nicholas@813 744
nicholas@813 745 </head>
nicholas@813 746
nicholas@813 747 <body>
nicholas@813 748 <h1>Subjective evaluation results</h1>
nicholas@813 749
nicholas@813 750 <div id="debugDisplay">
nicholas@813 751 XML file folder: <span id="xmlFileFolder_span"></span>
nicholas@813 752 </div>
nicholas@813 753
nicholas@813 754 <div id="headerMatter">
nicholas@813 755 <div>
nicholas@813 756 <strong>Result XML files:</strong> <span id="numberOfFiles_span"></span>
nicholas@813 757 </div>
nicholas@813 758 <div>
nicholas@813 759 <strong>Audioholders in dataset:</strong> <span id="audioholderArray_span"></span>
nicholas@813 760 </div>
nicholas@813 761 <div>
nicholas@813 762 <strong>Subjects in dataset:</strong> <span id="subjectArray_span"></span>
nicholas@813 763 </div>
nicholas@813 764 <div>
nicholas@813 765 <strong>Audioelements in dataset:</strong> <span id="audioelementArray_span"></span>
nicholas@813 766 </div>
nicholas@813 767 <br>
nicholas@813 768 </div>
nicholas@813 769 <br>
nicholas@813 770
nicholas@813 771 <!-- Show time elapsed
nicholas@813 772 The last annotation took <strong><span id="timeDisplay">(N/A)</span></strong> seconds.
nicholas@813 773 <br>-->
nicholas@813 774
nicholas@813 775 </body>
nicholas@813 776 </html>