annotate ape.js @ 674:436db2f29f73

Updated metric functions. Completed Metric Exporting.
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Mon, 13 Apr 2015 09:58:16 +0100
parents d4e55184f776
children 7e73d1cdcff8
rev   line source
n@656 1 /**
n@656 2 * ape.js
n@656 3 * Create the APE interface
n@656 4 */
n@656 5
n@656 6 /*
n@656 7 *
n@656 8 * WARNING!!!
n@656 9 *
n@656 10 * YOU ARE VIEWING THE DEV VERSION. THERE IS NO GUARANTEE THIS WILL BE FULLY FUNCTIONAL
n@656 11 *
n@656 12 * WARNING!!!
n@656 13 *
n@656 14 */
n@656 15
n@662 16 var currentState; // Keep track of the current state (pre/post test, which test, final test? first test?)
n@662 17 // preTest - In preTest state
n@662 18 // testRun-ID - In test running, test Id number at the end 'testRun-2'
n@662 19 // testRunPost-ID - Post test of test ID
n@662 20 // testRunPre-ID - Pre-test of test ID
n@662 21 // postTest - End of test, final submission!
n@662 22
n@656 23
n@656 24 // Once this is loaded and parsed, begin execution
n@656 25 loadInterface(projectXML);
n@656 26
n@656 27 function loadInterface(xmlDoc) {
n@656 28
n@656 29 // Get the dimensions of the screen available to the page
n@656 30 var width = window.innerWidth;
n@656 31 var height = window.innerHeight;
n@656 32
n@656 33 // The injection point into the HTML page
n@656 34 var insertPoint = document.getElementById("topLevelBody");
n@656 35 var testContent = document.createElement('div');
n@656 36 testContent.id = 'testContent';
n@656 37
n@656 38
n@656 39 // Decode parts of the xmlDoc that are needed
n@656 40 // xmlDoc MUST already be parsed by jQuery!
n@656 41 var xmlSetup = xmlDoc.find('setup');
n@656 42 // Should put in an error function here incase of malprocessed or malformed XML
n@656 43
n@658 44 // Extract the different test XML DOM trees
n@674 45 var audioHolders = xmlDoc.find('audioHolder');
n@674 46 audioHolders.each(function(index,element) {
n@674 47 var repeatN = element.attributes['repeatCount'].value;
n@674 48 for (var r=0; r<=repeatN; r++) {
n@674 49 testXMLSetups[testXMLSetups.length] = element;
n@674 50 }
n@674 51 });
n@668 52
n@674 53 // New check if we need to randomise the test order
n@674 54 var randomise = xmlSetup[0].attributes['randomiseOrder'];
n@674 55 if (randomise != undefined) {
n@674 56 randomise = Boolean(randomise.value);
n@674 57 } else {
n@674 58 randomise = false;
n@674 59 }
n@674 60 if (randomise)
n@674 61 {
n@674 62 // TODO: Implement Randomisation!!
n@674 63 }
n@668 64
n@674 65 // Obtain the metrics enabled
n@674 66 var metricNode = xmlSetup.find('Metric');
n@674 67 var metricNode = metricNode.find('metricEnable');
n@674 68 metricNode.each(function(index,node){
n@674 69 var enabled = node.textContent;
n@674 70 switch(enabled)
n@674 71 {
n@674 72 case 'testTimer':
n@674 73 sessionMetrics.prototype.enableTestTimer = true;
n@674 74 break;
n@674 75 case 'elementTimer':
n@674 76 sessionMetrics.prototype.enableElementTimer = true;
n@674 77 break;
n@674 78 case 'elementTracker':
n@674 79 sessionMetrics.prototype.enableElementTracker = true;
n@674 80 break;
n@674 81 case 'elementInitalPosition':
n@674 82 sessionMetrics.prototype.enableElementInitialPosition = true;
n@674 83 break;
n@674 84 case 'elementFlagListenedTo':
n@674 85 sessionMetrics.prototype.enableFlagListenedTo = true;
n@674 86 break;
n@674 87 case 'elementFlagMoved':
n@674 88 sessionMetrics.prototype.enableFlagMoved = true;
n@674 89 break;
n@674 90 case 'elementFlagComments':
n@674 91 sessionMetrics.prototype.enableFlagComments = true;
n@674 92 break;
n@674 93 }
n@674 94 });
n@658 95
n@656 96 // Create the top div for the Title element
n@656 97 var titleAttr = xmlSetup[0].attributes['title'];
n@656 98 var title = document.createElement('div');
n@656 99 title.className = "title";
n@656 100 title.align = "center";
n@656 101 var titleSpan = document.createElement('span');
n@656 102
n@656 103 // Set title to that defined in XML, else set to default
n@656 104 if (titleAttr != undefined) {
n@656 105 titleSpan.innerHTML = titleAttr.value;
n@656 106 } else {
n@656 107 titleSpan.innerHTML = 'APE Tool';
n@656 108 }
n@656 109 // Insert the titleSpan element into the title div element.
n@656 110 title.appendChild(titleSpan);
n@656 111
n@671 112 var pagetitle = document.createElement('div');
n@671 113 pagetitle.className = "pageTitle";
n@671 114 pagetitle.align = "center";
n@671 115 var titleSpan = document.createElement('span');
n@671 116 titleSpan.id = "pageTitle";
n@671 117 pagetitle.appendChild(titleSpan);
n@671 118
n@656 119 // Store the return URL path in global projectReturn
n@656 120 projectReturn = xmlSetup[0].attributes['projectReturn'].value;
n@656 121
n@656 122 // Create Interface buttons!
n@656 123 var interfaceButtons = document.createElement('div');
n@656 124 interfaceButtons.id = 'interface-buttons';
n@656 125
n@656 126 // MANUAL DOWNLOAD POINT
n@656 127 // If project return is null, this MUST be specified as the location to create the download link
n@656 128 var downloadPoint = document.createElement('div');
n@656 129 downloadPoint.id = 'download-point';
n@656 130
n@656 131 // Create playback start/stop points
n@656 132 var playback = document.createElement("button");
n@656 133 playback.innerHTML = 'Start';
n@673 134 playback.id = 'playback-button';
n@656 135 // onclick function. Check if it is playing or not, call the correct function in the
n@656 136 // audioEngine, change the button text to reflect the next state.
n@656 137 playback.onclick = function() {
n@656 138 if (audioEngineContext.status == 0) {
n@656 139 audioEngineContext.play();
n@656 140 this.innerHTML = 'Stop';
n@656 141 } else {
n@656 142 audioEngineContext.stop();
n@656 143 this.innerHTML = 'Start';
n@656 144 }
n@656 145 };
n@656 146 // Create Submit (save) button
n@656 147 var submit = document.createElement("button");
n@656 148 submit.innerHTML = 'Submit';
n@667 149 submit.onclick = buttonSubmitClick;
n@673 150 submit.id = 'submit-button';
n@656 151 // Append the interface buttons into the interfaceButtons object.
n@656 152 interfaceButtons.appendChild(playback);
n@656 153 interfaceButtons.appendChild(submit);
n@656 154 interfaceButtons.appendChild(downloadPoint);
n@656 155
n@656 156 // Now create the slider and HTML5 canvas boxes
n@656 157
n@656 158 // Create the div box to center align
n@656 159 var sliderBox = document.createElement('div');
n@656 160 sliderBox.className = 'sliderCanvasDiv';
n@656 161 sliderBox.id = 'sliderCanvasHolder';
n@656 162 sliderBox.align = 'center';
n@656 163
n@656 164 // Create the slider box to hold the slider elements
n@656 165 var canvas = document.createElement('div');
n@656 166 canvas.id = 'slider';
n@656 167 // Must have a known EXACT width, as this is used later to determine the ratings
n@656 168 canvas.style.width = width - 100 +"px";
n@656 169 canvas.align = "left";
n@656 170 sliderBox.appendChild(canvas);
n@656 171
n@671 172 // Create the div to hold any scale objects
n@671 173 var scale = document.createElement('div');
n@671 174 scale.className = 'sliderScale';
n@671 175 scale.id = 'sliderScaleHolder';
n@671 176 scale.align = 'left';
n@671 177 sliderBox.appendChild(scale);
n@671 178
n@656 179 // Global parent for the comment boxes on the page
n@656 180 var feedbackHolder = document.createElement('div');
n@658 181 feedbackHolder.id = 'feedbackHolder';
n@656 182
n@662 183 testContent.style.zIndex = 1;
n@662 184 insertPoint.innerHTML = null; // Clear the current schema
n@662 185
n@656 186 // Create pre and post test questions
n@662 187 var blank = document.createElement('div');
n@662 188 blank.className = 'testHalt';
n@656 189
n@662 190 var popupHolder = document.createElement('div');
n@662 191 popupHolder.id = 'popupHolder';
n@662 192 popupHolder.className = 'popupHolder';
n@662 193 popupHolder.style.position = 'absolute';
n@662 194 popupHolder.style.left = (window.innerWidth/2)-250 + 'px';
n@662 195 popupHolder.style.top = (window.innerHeight/2)-125 + 'px';
n@662 196 insertPoint.appendChild(popupHolder);
n@662 197 insertPoint.appendChild(blank);
n@662 198 hidePopup();
n@656 199
n@660 200 var preTest = xmlSetup.find('PreTest');
n@660 201 var postTest = xmlSetup.find('PostTest');
n@656 202 preTest = preTest[0];
n@656 203 postTest = postTest[0];
n@662 204
n@662 205 currentState = 'preTest';
n@656 206
n@656 207 // Create Pre-Test Box
n@656 208 if (preTest != undefined && preTest.children.length >= 1)
n@656 209 {
n@662 210 showPopup();
n@663 211 preTestPopupStart(preTest);
n@656 212 }
n@662 213
n@662 214 // Inject into HTML
n@662 215 testContent.appendChild(title); // Insert the title
n@671 216 testContent.appendChild(pagetitle);
n@662 217 testContent.appendChild(interfaceButtons);
n@662 218 testContent.appendChild(sliderBox);
n@662 219 testContent.appendChild(feedbackHolder);
n@662 220 insertPoint.appendChild(testContent);
n@656 221
n@660 222 // Load the full interface
n@663 223
n@656 224 }
n@656 225
n@663 226 function loadTest(id)
n@658 227 {
n@658 228 // Used to load a specific test page
n@663 229 var textXML = testXMLSetups[id];
n@658 230
n@658 231 var feedbackHolder = document.getElementById('feedbackHolder');
n@658 232 var canvas = document.getElementById('slider');
n@658 233 feedbackHolder.innerHTML = null;
n@658 234 canvas.innerHTML = null;
n@671 235
n@671 236 // Setup question title
n@671 237 var interfaceObj = $(textXML).find('interface');
n@671 238 var titleNode = interfaceObj.find('title');
n@671 239 if (titleNode[0] != undefined)
n@671 240 {
n@671 241 document.getElementById('pageTitle').textContent = titleNode[0].textContent;
n@671 242 }
n@671 243 var positionScale = canvas.style.width.substr(0,canvas.style.width.length-2);
n@671 244 var offset = 50-8; // Half the offset of the slider (window width -100) minus the body padding of 8
n@671 245 // TODO: AUTOMATE ABOVE!!
n@671 246 var scale = document.getElementById('sliderScaleHolder');
n@671 247 scale.innerHTML = null;
n@671 248 interfaceObj.find('scale').each(function(index,scaleObj){
n@671 249 var position = Number(scaleObj.attributes['position'].value)*0.01;
n@671 250 var pixelPosition = (position*positionScale)+offset;
n@671 251 var scaleDOM = document.createElement('span');
n@671 252 scaleDOM.textContent = scaleObj.textContent;
n@671 253 scale.appendChild(scaleDOM);
n@671 254 scaleDOM.style.left = Math.floor((pixelPosition-($(scaleDOM).width()/2)))+'px';
n@671 255 });
n@658 256
n@658 257 // Extract the hostURL attribute. If not set, create an empty string.
n@658 258 var hostURL = textXML.attributes['hostURL'];
n@658 259 if (hostURL == undefined) {
n@658 260 hostURL = "";
n@658 261 } else {
n@658 262 hostURL = hostURL.value;
n@658 263 }
n@658 264 // Extract the sampleRate. If set, convert the string to a Number.
n@658 265 var hostFs = textXML.attributes['sampleRate'];
n@658 266 if (hostFs != undefined) {
n@658 267 hostFs = Number(hostFs.value);
n@658 268 }
n@658 269
n@658 270 /// CHECK FOR SAMPLE RATE COMPATIBILITY
n@658 271 if (hostFs != undefined) {
n@658 272 if (Number(hostFs) != audioContext.sampleRate) {
n@658 273 var errStr = 'Sample rates do not match! Requested '+Number(hostFs)+', got '+audioContext.sampleRate+'. Please set the sample rate to match before completing this test.';
n@658 274 alert(errStr);
n@658 275 return;
n@658 276 }
n@658 277 }
n@669 278
n@670 279 currentTestHolder = document.createElement('audioHolder');
n@670 280 currentTestHolder.id = textXML.id;
n@670 281 currentTestHolder.repeatCount = textXML.attributes['repeatCount'].value;
n@670 282 var currentPreTestHolder = document.createElement('preTest');
n@670 283 var currentPostTestHolder = document.createElement('postTest');
n@670 284 currentTestHolder.appendChild(currentPreTestHolder);
n@670 285 currentTestHolder.appendChild(currentPostTestHolder);
n@670 286
n@669 287 var randomise = textXML.attributes['randomiseOrder'];
n@669 288 if (randomise != undefined) {randomise = randomise.value;}
n@669 289 else {randomise = false;}
n@669 290
n@658 291 var audioElements = $(textXML).find('audioElements');
n@658 292 audioElements.each(function(index,element){
n@669 293 // Find any blind-repeats
n@669 294 // Not implemented yet, but just incase
n@669 295 currentTrackOrder[index] = element;
n@669 296 });
n@669 297 if (randomise) {
n@669 298 // TODO: Randomise order
n@669 299 }
n@669 300
n@669 301 // Find all the audioElements from the audioHolder
n@669 302 $(currentTrackOrder).each(function(index,element){
n@658 303 // Find URL of track
n@658 304 // In this jQuery loop, variable 'this' holds the current audioElement.
n@658 305
n@658 306 // Now load each audio sample. First create the new track by passing the full URL
n@658 307 var trackURL = hostURL + this.attributes['url'].value;
n@658 308 audioEngineContext.newTrack(trackURL);
n@658 309 // Create document objects to hold the comment boxes
n@658 310 var trackComment = document.createElement('div');
n@661 311 trackComment.className = 'comment-div';
n@658 312 // Create a string next to each comment asking for a comment
n@658 313 var trackString = document.createElement('span');
n@658 314 trackString.innerHTML = 'Comment on track '+index;
n@658 315 // Create the HTML5 comment box 'textarea'
n@658 316 var trackCommentBox = document.createElement('textarea');
n@658 317 trackCommentBox.rows = '4';
n@658 318 trackCommentBox.cols = '100';
n@658 319 trackCommentBox.name = 'trackComment'+index;
n@658 320 trackCommentBox.className = 'trackComment';
n@658 321 var br = document.createElement('br');
n@658 322 // Add to the holder.
n@658 323 trackComment.appendChild(trackString);
n@658 324 trackComment.appendChild(br);
n@658 325 trackComment.appendChild(trackCommentBox);
n@658 326 feedbackHolder.appendChild(trackComment);
n@658 327
n@658 328 // Create a slider per track
n@658 329
n@658 330 var trackSliderObj = document.createElement('div');
n@658 331 trackSliderObj.className = 'track-slider';
n@658 332 trackSliderObj.id = 'track-slider-'+index;
n@658 333 // Distribute it randomnly
n@658 334 var w = window.innerWidth - 100;
n@658 335 w = Math.random()*w;
n@658 336 trackSliderObj.style.left = Math.floor(w)+50+'px';
n@658 337 trackSliderObj.innerHTML = '<span>'+index+'</span>';
n@658 338 trackSliderObj.draggable = true;
n@658 339 trackSliderObj.ondragend = dragEnd;
n@673 340 trackSliderObj.ondragstart = function()
n@673 341 {
n@673 342 var id = Number(this.id.substr(13,2)); // Maximum theoretical tracks is 99!
n@673 343 audioEngineContext.metric.sliderMoveStart(id);
n@673 344 };
n@658 345
n@658 346 // Onclick, switch playback to that track
n@658 347 trackSliderObj.onclick = function() {
n@658 348 // Get the track ID from the object ID
n@658 349 var id = Number(this.id.substr(13,2)); // Maximum theoretical tracks is 99!
n@673 350 audioEngineContext.metric.sliderPlayed(id);
n@658 351 audioEngineContext.selectedTrack(id);
n@658 352 };
n@658 353
n@658 354 canvas.appendChild(trackSliderObj);
n@658 355 });
n@663 356
n@663 357 // Now process any pre-test commands
n@663 358
n@668 359 var preTest = $(testXMLSetups[id]).find('PreTest')[0];
n@663 360 if (preTest.children.length > 0)
n@663 361 {
n@663 362 currentState = 'testRunPre-'+id;
n@663 363 preTestPopupStart(preTest);
n@663 364 showPopup();
n@663 365 } else {
n@663 366 currentState = 'testRun-'+id;
n@663 367 }
n@663 368 }
n@663 369
n@663 370 function preTestPopupStart(preTest)
n@663 371 {
n@663 372 var popupHolder = document.getElementById('popupHolder');
n@663 373 popupHolder.innerHTML = null;
n@663 374 // Parse the first box
n@663 375 var preTestOption = document.createElement('div');
n@663 376 preTestOption.id = 'preTest';
n@663 377 preTestOption.style.marginTop = '25px';
n@663 378 preTestOption.align = "center";
n@663 379 var child = preTest.children[0];
n@663 380 if (child.nodeName == 'statement')
n@663 381 {
n@663 382 preTestOption.innerHTML = '<span>'+child.innerHTML+'</span>';
n@663 383 } else if (child.nodeName == 'question')
n@663 384 {
n@663 385 var questionId = child.attributes['id'].value;
n@663 386 var textHold = document.createElement('span');
n@663 387 textHold.innerHTML = child.innerHTML;
n@663 388 textHold.id = questionId + 'response';
n@663 389 var textEnter = document.createElement('textarea');
n@663 390 preTestOption.appendChild(textHold);
n@663 391 preTestOption.appendChild(textEnter);
n@663 392 }
n@663 393 var nextButton = document.createElement('button');
n@663 394 nextButton.className = 'popupButton';
n@663 395 nextButton.value = '0';
n@663 396 nextButton.innerHTML = 'Next';
n@663 397 nextButton.onclick = popupButtonClick;
n@663 398
n@663 399 popupHolder.appendChild(preTestOption);
n@663 400 popupHolder.appendChild(nextButton);
n@658 401 }
n@658 402
n@662 403 function popupButtonClick()
n@662 404 {
n@662 405 // Global call from the 'Next' button click
n@662 406 if (currentState == 'preTest')
n@662 407 {
n@662 408 // At the start of the preTest routine!
n@663 409 var xmlTree = projectXML.find('setup');
n@663 410 var preTest = xmlTree.find('PreTest')[0];
n@663 411 this.value = preTestButtonClick(preTest,this.value);
n@663 412 } else if (currentState.substr(0,10) == 'testRunPre')
n@663 413 {
n@663 414 //Specific test pre-test
n@663 415 var testId = currentState.substr(11,currentState.length-10);
n@668 416 var preTest = $(testXMLSetups[testId]).find('PreTest')[0];
n@663 417 this.value = preTestButtonClick(preTest,this.value);
n@666 418 } else if (currentState.substr(0,11) == 'testRunPost')
n@666 419 {
n@666 420 // Specific test post-test
n@666 421 var testId = currentState.substr(12,currentState.length-11);
n@668 422 var preTest = $(testXMLSetups[testId]).find('PostTest')[0];
n@666 423 this.value = preTestButtonClick(preTest,this.value);
n@665 424 } else if (currentState == 'postTest')
n@665 425 {
n@665 426 // At the end of the test, running global post test
n@665 427 var xmlTree = projectXML.find('setup');
n@665 428 var PostTest = xmlTree.find('PostTest')[0];
n@665 429 this.value = preTestButtonClick(PostTest,this.value);
n@662 430 }
n@662 431 }
n@662 432
n@663 433 function preTestButtonClick(preTest,index)
n@658 434 {
n@658 435 // Called on click of pre-test button
n@660 436 // Need to find and parse preTest again!
n@660 437 var preTestOption = document.getElementById('preTest');
n@660 438 // Check if current state is a question!
n@662 439 if (preTest.children[index].nodeName == 'question') {
n@662 440 var questionId = preTest.children[index].attributes['id'].value;
n@660 441 var questionHold = document.createElement('comment');
n@660 442 var questionResponse = document.getElementById(questionId + 'response');
n@660 443 questionHold.id = questionId;
n@660 444 questionHold.innerHTML = questionResponse.value;
n@670 445 postPopupResponse(questionHold);
n@660 446 }
n@662 447 index++;
n@662 448 if (index < preTest.children.length)
n@660 449 {
n@660 450 // More to process
n@662 451 var child = preTest.children[index];
n@660 452 if (child.nodeName == 'statement')
n@660 453 {
n@660 454 preTestOption.innerHTML = '<span>'+child.innerHTML+'</span>';
n@660 455 } else if (child.nodeName == 'question')
n@660 456 {
n@660 457 var textHold = document.createElement('span');
n@660 458 textHold.innerHTML = child.innerHTML;
n@660 459 var textEnter = document.createElement('textarea');
n@660 460 textEnter.id = child.attributes['id'].value + 'response';
n@660 461 var br = document.createElement('br');
n@660 462 preTestOption.innerHTML = null;
n@660 463 preTestOption.appendChild(textHold);
n@660 464 preTestOption.appendChild(br);
n@660 465 preTestOption.appendChild(textEnter);
n@660 466 }
n@660 467 } else {
n@660 468 // Time to clear
n@661 469 preTestOption.innerHTML = null;
n@667 470 if (currentState != 'postTest') {
n@667 471 hidePopup();
n@667 472 // Progress the state!
n@667 473 advanceState();
n@667 474 } else {
n@667 475 a = createProjectSave(projectReturn);
n@667 476 preTestOption.appendChild(a);
n@667 477 }
n@660 478 }
n@662 479 return index;
n@660 480 }
n@660 481
n@670 482 function postPopupResponse(response)
n@670 483 {
n@670 484 if (currentState == 'preTest') {
n@670 485 preTestQuestions.appendChild(response);
n@670 486 } else if (currentState == 'postTest') {
n@670 487 postTestQuestions.appendChild(response);
n@670 488 } else {
n@670 489 // Inside a specific test
n@670 490 if (currentState.substr(0,10) == 'testRunPre') {
n@670 491 // Pre Test
n@670 492 var store = $(currentTestHolder).find('preTest');
n@670 493 } else {
n@670 494 // Post Test
n@670 495 var store = $(currentTestHolder).find('postTest');
n@670 496 }
n@670 497 store[0].appendChild(response);
n@670 498 }
n@670 499 }
n@670 500
n@660 501 function showPopup()
n@660 502 {
n@661 503 var popupHolder = document.getElementById('popupHolder');
n@662 504 popupHolder.style.zIndex = 3;
n@661 505 popupHolder.style.visibility = 'visible';
n@661 506 var blank = document.getElementsByClassName('testHalt')[0];
n@661 507 blank.style.zIndex = 2;
n@661 508 blank.style.visibility = 'visible';
n@660 509 }
n@660 510
n@660 511 function hidePopup()
n@660 512 {
n@661 513 var popupHolder = document.getElementById('popupHolder');
n@661 514 popupHolder.style.zIndex = -1;
n@661 515 popupHolder.style.visibility = 'hidden';
n@661 516 var blank = document.getElementsByClassName('testHalt')[0];
n@661 517 blank.style.zIndex = -2;
n@661 518 blank.style.visibility = 'hidden';
n@658 519 }
n@658 520
n@656 521 function dragEnd(ev) {
n@656 522 // Function call when a div has been dropped
n@657 523 var slider = document.getElementById('slider');
n@656 524 if (ev.x >= 50 && ev.x < window.innerWidth-50) {
n@656 525 this.style.left = (ev.x)+'px';
n@656 526 } else {
n@656 527 if (ev.x<50) {
n@656 528 this.style.left = '50px';
n@656 529 } else {
n@656 530 this.style.left = window.innerWidth-50 + 'px';
n@656 531 }
n@656 532 }
n@673 533 audioEngineContext.metric.sliderMoved();
n@656 534 }
n@656 535
n@663 536 function advanceState()
n@663 537 {
n@663 538 console.log(currentState);
n@663 539 if (currentState == 'preTest')
n@663 540 {
n@663 541 // End of pre-test, begin the test
n@663 542 loadTest(0);
n@663 543 } else if (currentState.substr(0,10) == 'testRunPre')
n@663 544 {
n@663 545 // Start the test
n@663 546 var testId = currentState.substr(11,currentState.length-10);
n@663 547 currentState = 'testRun-'+testId;
n@666 548 } else if (currentState.substr(0,11) == 'testRunPost')
n@666 549 {
n@668 550 var testId = currentState.substr(12,currentState.length-11);
n@666 551 testEnded(testId);
n@664 552 } else if (currentState.substr(0,7) == 'testRun')
n@664 553 {
n@664 554 var testId = currentState.substr(8,currentState.length-7);
n@664 555 // Check if we have any post tests to perform
n@668 556 var postXML = $(testXMLSetups[testId]).find('PostTest')[0];
n@664 557 if (postXML.children.length > 0)
n@664 558 {
n@666 559 currentState = 'testRunPost-'+testId;
n@666 560 showPopup();
n@666 561 preTestPopupStart(postXML);
n@664 562 }
n@666 563 else {
n@664 564
n@664 565
n@666 566 // No post tests, check if we have another test to perform instead
n@666 567 testEnded(testId);
n@664 568 }
n@663 569 }
n@663 570 console.log(currentState);
n@663 571 }
n@663 572
n@666 573 function testEnded(testId)
n@666 574 {
n@669 575 pageXMLSave(testId);
n@666 576 if (testXMLSetups.length-1 > testId)
n@666 577 {
n@666 578 // Yes we have another test to perform
n@668 579 testId = (Number(testId)+1);
n@668 580 currentState = 'testRun-'+testId;
n@668 581 loadTest(testId);
n@666 582 } else {
n@666 583 console.log('Testing Completed!');
n@666 584 currentState = 'postTest';
n@666 585 // Check for any post tests
n@666 586 var xmlSetup = projectXML.find('setup');
n@666 587 var postTest = xmlSetup.find('PostTest')[0];
n@666 588 showPopup();
n@666 589 preTestPopupStart(postTest);
n@666 590 }
n@666 591 }
n@666 592
n@664 593 function buttonSubmitClick()
n@664 594 {
n@673 595 if (audioEngineContext.status == 1) {
n@673 596 var playback = document.getElementById('playback-button');
n@673 597 playback.click();
n@664 598 // This function is called when the submit button is clicked. Will check for any further tests to perform, or any post-test options
n@673 599 }
n@664 600 if (currentState.substr(0,7) == 'testRun')
n@664 601 {
n@673 602 audioEngineContext.timer.stopTest();
n@664 603 advanceState();
n@664 604 }
n@664 605 }
n@664 606
n@668 607 function pageXMLSave(testId)
n@668 608 {
n@668 609 // Saves a specific test page
n@670 610 var xmlDoc = currentTestHolder;
n@674 611 // Check if any session wide metrics are enabled
n@674 612 var metric = document.createElement('metric');
n@674 613 if (audioEngineContext.metric.enableTestTimer)
n@674 614 {
n@674 615 var testTime = document.createElement('metricResult');
n@674 616 testTime.id = 'testTime';
n@674 617 testTime.textContent = audioEngineContext.timer.testDuration;
n@674 618 metric.appendChild(testTime);
n@674 619 }
n@674 620 xmlDoc.appendChild(metric);
n@669 621 var trackSliderObjects = document.getElementsByClassName('track-slider');
n@669 622 var commentObjects = document.getElementsByClassName('comment-div');
n@669 623 var rateMin = 50;
n@669 624 var rateMax = window.innerWidth-50;
n@669 625 for (var i=0; i<trackSliderObjects.length; i++)
n@669 626 {
n@669 627 var audioElement = document.createElement('audioElement');
n@669 628 audioElement.id = currentTrackOrder[i].attributes['id'].value;
n@669 629 audioElement.url = currentTrackOrder[i].attributes['url'].value;
n@669 630 var value = document.createElement("value");
n@669 631 var rate = Number(trackSliderObjects[i].style.left.substr(0,trackSliderObjects[i].style.left.length-2));
n@669 632 rate = (rate-rateMin)/rateMax;
n@669 633 value.innerHTML = Math.floor(rate*100);
n@669 634 var comment = document.createElement("comment");
n@669 635 var question = document.createElement("question");
n@669 636 var response = document.createElement("response");
n@669 637 question.textContent = commentObjects[i].children[0].textContent;
n@669 638 response.textContent = commentObjects[i].children[2].value;
n@669 639 comment.appendChild(question);
n@669 640 comment.appendChild(response);
n@669 641 audioElement.appendChild(value);
n@669 642 audioElement.appendChild(comment);
n@674 643 // Check for any per element metrics
n@674 644 var metric = document.createElement('metric');
n@674 645 var elementMetric = audioEngineContext.audioObjects[i].metric;
n@674 646 if (audioEngineContext.metric.enableElementTimer) {
n@674 647 var elementTimer = document.createElement('metricResult');
n@674 648 elementTimer.id = 'elementTimer';
n@674 649 elementTimer.textContent = elementMetric.listenedTimer;
n@674 650 metric.appendChild(elementTimer);
n@674 651 }
n@674 652 if (audioEngineContext.metric.enableElementTracker) {
n@674 653 var elementTrackerFull = document.createElement('metricResult');
n@674 654 elementTrackerFull.id = 'elementTrackerFull';
n@674 655 var data = elementMetric.movementTracker;
n@674 656 for (var k=0; k<data.length; k++)
n@674 657 {
n@674 658 var timePos = document.createElement('timePos');
n@674 659 timePos.id = k;
n@674 660 var time = document.createElement('time');
n@674 661 time.textContent = data[k][0];
n@674 662 var position = document.createElement('position');
n@674 663 position.textContent = data[k][1];
n@674 664 timePos.appendChild(time);
n@674 665 timePos.appendChild(position);
n@674 666 elementTrackerFull.appendChild(timePos);
n@674 667 }
n@674 668 metric.appendChild(elementTrackerFull);
n@674 669 }
n@674 670 if (audioEngineContext.metric.enableElementInitialPosition) {
n@674 671 var elementInitial = document.createElement('metricResult');
n@674 672 elementInitial.id = 'elementInitialPosition';
n@674 673 elementInitial.textContent = elementMetric.initialPosition;
n@674 674 metric.appendChild(elementInitial);
n@674 675 }
n@674 676 if (audioEngineContext.metric.enableFlagListenedTo) {
n@674 677 var flagListenedTo = document.createElement('metricResult');
n@674 678 flagListenedTo.id = 'elementFlagListenedTo';
n@674 679 flagListenedTo.textContent = elementMetric.wasListenedTo;
n@674 680 metric.appendChild(flagListenedTo);
n@674 681 }
n@674 682 if (audioEngineContext.metric.enableFlagMoved) {
n@674 683 var flagMoved = document.createElement('metricResult');
n@674 684 flagMoved.id = 'elementFlagMoved';
n@674 685 flagMoved.textContent = elementMetric.wasMoved;
n@674 686 metric.appendChild(flagMoved);
n@674 687 }
n@674 688 if (audioEngineContext.metric.enableFlagComments) {
n@674 689 var flagComments = document.createElement('metricResult');
n@674 690 flagComments.id = 'elementFlagComments';
n@674 691 if (response.textContent.length == 0) {flag.textContent = 'false';}
n@674 692 else {flag.textContet = 'true';}
n@674 693 metric.appendChild(flagComments);
n@674 694 }
n@674 695 audioElement.appendChild(metric);
n@669 696 xmlDoc.appendChild(audioElement);
n@669 697 }
n@669 698 testResultsHolders[testId] = xmlDoc;
n@668 699 }
n@668 700
n@656 701 // Only other global function which must be defined in the interface class. Determines how to create the XML document.
n@656 702 function interfaceXMLSave(){
n@656 703 // Create the XML string to be exported with results
n@656 704 var xmlDoc = document.createElement("BrowserEvaluationResult");
n@669 705 for (var i=0; i<testResultsHolders.length; i++)
n@656 706 {
n@669 707 xmlDoc.appendChild(testResultsHolders[i]);
n@656 708 }
n@656 709 // Append Pre/Post Questions
n@656 710 xmlDoc.appendChild(preTestQuestions);
n@656 711 xmlDoc.appendChild(postTestQuestions);
n@656 712
n@656 713 return xmlDoc;
n@656 714 }
n@656 715