annotate analyse.html @ 767:d7f2912bf487

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