annotate analyse.html @ 830:f8d96b78e620

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