annotate analyse.html @ 815:3b0770e1e616

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