annotate analyse.html @ 1315:d9b9f707f862

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