annotate analyse.html @ 534:a95d323a911e giulio-working

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