annotate analyse.html @ 1506:131465b92a7a

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