annotate analyse.html @ 1097:ebf52bf47fb7

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