annotate analyse.html @ 782:1e176e95ef33

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