annotate analyse.html @ 1318:64541cd9265d

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