annotate analyse.html @ 1303:ade3acb0cee3

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