annotate analyse.html @ 1106:282dfb8076f5

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