# HG changeset patch # User Nicholas Jillings # Date 1432741548 -3600 # Node ID 9c09cb530ec19fc56568eedc9e6e5358477e4363 # Parent ba734075da2d476116c55134761d6ab61af8db64 Major Update. All new state machine to track the session state and hold session data. Will enable new interfaces to be built on top and have the same common structures. diff -r ba734075da2d -r 9c09cb530ec1 ape.js --- a/ape.js Wed May 27 11:49:20 2015 +0100 +++ b/ape.js Wed May 27 16:45:48 2015 +0100 @@ -30,12 +30,25 @@ var xmlSetup = xmlDoc.find('setup'); // Should put in an error function here incase of malprocessed or malformed XML + // Create pre and post test questions + + var preTest = xmlSetup.find('PreTest'); + var postTest = xmlSetup.find('PostTest'); + preTest = preTest[0]; + postTest = postTest[0]; + + if (preTest == undefined) {preTest = document.createElement("preTest");} + if (postTest == undefined){postTest= document.createElement("postTest");} + + testState.stateMap.push(preTest); + // Extract the different test XML DOM trees var audioHolders = xmlDoc.find('audioHolder'); + var testXMLSetups = []; audioHolders.each(function(index,element) { var repeatN = element.attributes['repeatCount'].value; for (var r=0; r<=repeatN; r++) { - testXMLSetups[testXMLSetups.length] = element; + testXMLSetups.push(element); } }); @@ -55,6 +68,12 @@ { testXMLSetups = randomiseOrder(testXMLSetups); } + + $(testXMLSetups).each(function(index,elem){ + testState.stateMap.push(elem); + }) + + testState.stateMap.push(postTest); // Obtain the metrics enabled var metricNode = xmlSetup.find('Metric'); @@ -232,23 +251,8 @@ testContent.style.zIndex = 1; insertPoint.innerHTML = null; // Clear the current schema - // Create pre and post test questions - - var preTest = xmlSetup.find('PreTest'); - var postTest = xmlSetup.find('PostTest'); - preTest = preTest[0]; - postTest = postTest[0]; - currentState = 'preTest'; - // Create Pre-Test Box - if (preTest != undefined && preTest.childElementCount >= 1) - { - //popup.showPopup(); - //preTestPopupStart(preTest); - popup.initState(preTest); - } - // Inject into HTML testContent.appendChild(title); // Insert the title testContent.appendChild(pagetitle); @@ -258,17 +262,17 @@ insertPoint.appendChild(testContent); // Load the full interface - + testState.initialise(); + testState.advanceState(); } -function loadTest(id) +function loadTest(textXML) { // Reset audioEngineContext.Metric globals for new test audioEngineContext.newTestPage(); - // Used to load a specific test page - var textXML = testXMLSetups[id]; + var id = textXML.id; var feedbackHolder = document.getElementById('feedbackHolder'); var canvas = document.getElementById('slider'); @@ -483,19 +487,6 @@ trackComment.appendChild(trackCommentBox); feedbackHolder.appendChild(trackComment); }); - - // Now process any pre-test commands - - var preTest = $(testXMLSetups[id]).find('PreTest')[0]; - if (preTest.childElementCount > 0) - { - currentState = 'testRunPre-'+id; - //preTestPopupStart(preTest); - popup.initState(preTest); - //popup.showPopup(); - } else { - currentState = 'testRun-'+id; - } } @@ -534,12 +525,7 @@ return; } } - if (currentState.substr(0,7) == 'testRun') - { - hasBeenPlayed = []; // clear array to prepare for next test - audioEngineContext.timer.stopTest(); - advanceState(); - } + testState.advanceState(); } else // if a fragment has not been played yet { str = ""; @@ -605,13 +591,13 @@ }); } -function pageXMLSave(testId) +function pageXMLSave(store, testXML, testId) { // Saves a specific test page - var xmlDoc = currentTestHolder; + var xmlDoc = store; // Check if any session wide metrics are enabled - var commentShow = testXMLSetups[testId].attributes['elementComments']; + var commentShow = testXML.attributes['elementComments']; if (commentShow != undefined) { if (commentShow.value == 'false') {commentShow = false;} else {commentShow = true;} @@ -716,21 +702,5 @@ cqHolder.appendChild(comment); xmlDoc.appendChild(cqHolder); } - testResultsHolders[testId] = xmlDoc; -} - -// Only other global function which must be defined in the interface class. Determines how to create the XML document. -function interfaceXMLSave(){ - // Create the XML string to be exported with results - var xmlDoc = document.createElement("BrowserEvaluationResult"); - xmlDoc.appendChild(returnDateNode()); - for (var i=0; i 0) { + if(this.stateIndex != null) { + console.log('NOTE - State already initialise'); + } + this.stateIndex = -1; + var that = this; + for (var id=0; id 0) - { - currentState = 'testRunPost-'+testId; - popup.initState(postXML); + }; + this.advanceState = function(){ + if (this.stateIndex == null) { + this.initialise(); + } + if (this.stateIndex == -1) { + console.log('Starting test...'); + } + if (this.currentIndex == null){ + if (this.currentStateMap.nodeName == "audioHolder") { + // Save current page + this.testPageCompleted(this.stateResults[this.stateIndex],this.currentStateMap,this.currentTestId); + this.currentTestId++; + } + this.stateIndex++; + if (this.stateIndex >= this.stateMap.length) { + console.log('Test Completed'); + createProjectSave(projectReturn); + } else { + this.currentStateMap = this.stateMap[this.stateIndex]; + if (this.currentStateMap.nodeName == "audioHolder") { + console.log('Loading test page'); + loadTest(this.currentStateMap); + this.initialiseInnerState(this.currentStateMap); + } else if (this.currentStateMap.nodeName == "PreTest" || this.currentStateMap.nodeName == "PostTest") { + if (this.currentStateMap.childElementCount >= 1) { + popup.initState(this.currentStateMap); + } else { + this.advanceState(); + } + } else { + this.advanceState(); + } + } + } else { + this.advanceInnerState(); + } + }; + + this.testPageCompleted = function(store, testXML, testId) { + // Function called each time a test page has been completed + // Can be used to over-rule default behaviour + + pageXMLSave(store, testXML, testId); + } + + this.initialiseInnerState = function(testXML) { + // Parses the received testXML for pre and post test options + this.currentStateMap = []; + var preTest = $(testXML).find('PreTest')[0]; + var postTest = $(testXML).find('PostTest')[0]; + if (preTest == undefined) {preTest = document.createElement("preTest");} + if (postTest == undefined){postTest= document.createElement("postTest");} + this.currentStateMap.push(preTest); + this.currentStateMap.push(testXML); + this.currentStateMap.push(postTest); + this.currentIndex = -1; + this.advanceInnerState(); + } + + this.advanceInnerState = function() { + this.currentIndex++; + if (this.currentIndex >= this.currentStateMap.length) { + this.currentIndex = null; + this.currentStateMap = this.stateMap[this.stateIndex]; + this.advanceState(); + } else { + if (this.currentStateMap[this.currentIndex].nodeName == "audioHolder") { + console.log("Loading test page"+this.currentTestId); + } else if (this.currentStateMap[this.currentIndex].nodeName == "PreTest") { + popup.initState(this.currentStateMap[this.currentIndex]); + } else if (this.currentStateMap[this.currentIndex].nodeName == "PostTest") { + popup.initState(this.currentStateMap[this.currentIndex]); + } else { + this.advanceInnerState(); + } } } - console.log(currentState); + + this.previousState = function(){}; } function testEnded(testId) @@ -303,6 +382,19 @@ return submitDiv; } +// Only other global function which must be defined in the interface class. Determines how to create the XML document. +function interfaceXMLSave(){ + // Create the XML string to be exported with results + var xmlDoc = document.createElement("BrowserEvaluationResult"); + xmlDoc.appendChild(returnDateNode()); + for (var i=0; i --> What is your mixing experiance + Please enter the genre