annotate analyse.html @ 750:c9c010690d56

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