annotate analyse.html @ 1113:9ee921c8cdd3

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