annotate analyse.html @ 1306:cc55cc323592

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