annotate analyse.html @ 1418:6d47c4ed0e67

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