Mercurial > hg > webaudioevaluationtool
comparison ape.js @ 129:0e13112d8501
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.
author | Nicholas Jillings <nicholas.jillings@eecs.qmul.ac.uk> |
---|---|
date | Wed, 27 May 2015 16:45:48 +0100 |
parents | 4ce9f5887eee |
children | 67cc1058bfad |
comparison
equal
deleted
inserted
replaced
127:4ce9f5887eee | 129:0e13112d8501 |
---|---|
28 // Decode parts of the xmlDoc that are needed | 28 // Decode parts of the xmlDoc that are needed |
29 // xmlDoc MUST already be parsed by jQuery! | 29 // xmlDoc MUST already be parsed by jQuery! |
30 var xmlSetup = xmlDoc.find('setup'); | 30 var xmlSetup = xmlDoc.find('setup'); |
31 // Should put in an error function here incase of malprocessed or malformed XML | 31 // Should put in an error function here incase of malprocessed or malformed XML |
32 | 32 |
33 // Create pre and post test questions | |
34 | |
35 var preTest = xmlSetup.find('PreTest'); | |
36 var postTest = xmlSetup.find('PostTest'); | |
37 preTest = preTest[0]; | |
38 postTest = postTest[0]; | |
39 | |
40 if (preTest == undefined) {preTest = document.createElement("preTest");} | |
41 if (postTest == undefined){postTest= document.createElement("postTest");} | |
42 | |
43 testState.stateMap.push(preTest); | |
44 | |
33 // Extract the different test XML DOM trees | 45 // Extract the different test XML DOM trees |
34 var audioHolders = xmlDoc.find('audioHolder'); | 46 var audioHolders = xmlDoc.find('audioHolder'); |
47 var testXMLSetups = []; | |
35 audioHolders.each(function(index,element) { | 48 audioHolders.each(function(index,element) { |
36 var repeatN = element.attributes['repeatCount'].value; | 49 var repeatN = element.attributes['repeatCount'].value; |
37 for (var r=0; r<=repeatN; r++) { | 50 for (var r=0; r<=repeatN; r++) { |
38 testXMLSetups[testXMLSetups.length] = element; | 51 testXMLSetups.push(element); |
39 } | 52 } |
40 }); | 53 }); |
41 | 54 |
42 // New check if we need to randomise the test order | 55 // New check if we need to randomise the test order |
43 var randomise = xmlSetup[0].attributes['randomiseOrder']; | 56 var randomise = xmlSetup[0].attributes['randomiseOrder']; |
53 | 66 |
54 if (randomise) | 67 if (randomise) |
55 { | 68 { |
56 testXMLSetups = randomiseOrder(testXMLSetups); | 69 testXMLSetups = randomiseOrder(testXMLSetups); |
57 } | 70 } |
71 | |
72 $(testXMLSetups).each(function(index,elem){ | |
73 testState.stateMap.push(elem); | |
74 }) | |
75 | |
76 testState.stateMap.push(postTest); | |
58 | 77 |
59 // Obtain the metrics enabled | 78 // Obtain the metrics enabled |
60 var metricNode = xmlSetup.find('Metric'); | 79 var metricNode = xmlSetup.find('Metric'); |
61 var metricNode = metricNode.find('metricEnable'); | 80 var metricNode = metricNode.find('metricEnable'); |
62 metricNode.each(function(index,node){ | 81 metricNode.each(function(index,node){ |
230 feedbackHolder.id = 'feedbackHolder'; | 249 feedbackHolder.id = 'feedbackHolder'; |
231 | 250 |
232 testContent.style.zIndex = 1; | 251 testContent.style.zIndex = 1; |
233 insertPoint.innerHTML = null; // Clear the current schema | 252 insertPoint.innerHTML = null; // Clear the current schema |
234 | 253 |
235 // Create pre and post test questions | |
236 | |
237 var preTest = xmlSetup.find('PreTest'); | |
238 var postTest = xmlSetup.find('PostTest'); | |
239 preTest = preTest[0]; | |
240 postTest = postTest[0]; | |
241 | |
242 currentState = 'preTest'; | 254 currentState = 'preTest'; |
243 | |
244 // Create Pre-Test Box | |
245 if (preTest != undefined && preTest.childElementCount >= 1) | |
246 { | |
247 //popup.showPopup(); | |
248 //preTestPopupStart(preTest); | |
249 popup.initState(preTest); | |
250 } | |
251 | 255 |
252 // Inject into HTML | 256 // Inject into HTML |
253 testContent.appendChild(title); // Insert the title | 257 testContent.appendChild(title); // Insert the title |
254 testContent.appendChild(pagetitle); | 258 testContent.appendChild(pagetitle); |
255 testContent.appendChild(interfaceButtons); | 259 testContent.appendChild(interfaceButtons); |
256 testContent.appendChild(sliderBox); | 260 testContent.appendChild(sliderBox); |
257 testContent.appendChild(feedbackHolder); | 261 testContent.appendChild(feedbackHolder); |
258 insertPoint.appendChild(testContent); | 262 insertPoint.appendChild(testContent); |
259 | 263 |
260 // Load the full interface | 264 // Load the full interface |
261 | 265 testState.initialise(); |
266 testState.advanceState(); | |
262 } | 267 } |
263 | 268 |
264 function loadTest(id) | 269 function loadTest(textXML) |
265 { | 270 { |
266 | 271 |
267 // Reset audioEngineContext.Metric globals for new test | 272 // Reset audioEngineContext.Metric globals for new test |
268 audioEngineContext.newTestPage(); | 273 audioEngineContext.newTestPage(); |
269 | 274 |
270 // Used to load a specific test page | 275 var id = textXML.id; |
271 var textXML = testXMLSetups[id]; | |
272 | 276 |
273 var feedbackHolder = document.getElementById('feedbackHolder'); | 277 var feedbackHolder = document.getElementById('feedbackHolder'); |
274 var canvas = document.getElementById('slider'); | 278 var canvas = document.getElementById('slider'); |
275 feedbackHolder.innerHTML = null; | 279 feedbackHolder.innerHTML = null; |
276 canvas.innerHTML = null; | 280 canvas.innerHTML = null; |
481 trackComment.appendChild(trackString); | 485 trackComment.appendChild(trackString); |
482 trackComment.appendChild(br); | 486 trackComment.appendChild(br); |
483 trackComment.appendChild(trackCommentBox); | 487 trackComment.appendChild(trackCommentBox); |
484 feedbackHolder.appendChild(trackComment); | 488 feedbackHolder.appendChild(trackComment); |
485 }); | 489 }); |
486 | |
487 // Now process any pre-test commands | |
488 | |
489 var preTest = $(testXMLSetups[id]).find('PreTest')[0]; | |
490 if (preTest.childElementCount > 0) | |
491 { | |
492 currentState = 'testRunPre-'+id; | |
493 //preTestPopupStart(preTest); | |
494 popup.initState(preTest); | |
495 //popup.showPopup(); | |
496 } else { | |
497 currentState = 'testRun-'+id; | |
498 } | |
499 } | 490 } |
500 | 491 |
501 | 492 |
502 function dragEnd(ev) { | 493 function dragEnd(ev) { |
503 // Function call when a div has been dropped | 494 // Function call when a div has been dropped |
532 { | 523 { |
533 alert('You have not started the test! Please press start to begin the test!'); | 524 alert('You have not started the test! Please press start to begin the test!'); |
534 return; | 525 return; |
535 } | 526 } |
536 } | 527 } |
537 if (currentState.substr(0,7) == 'testRun') | 528 testState.advanceState(); |
538 { | |
539 hasBeenPlayed = []; // clear array to prepare for next test | |
540 audioEngineContext.timer.stopTest(); | |
541 advanceState(); | |
542 } | |
543 } else // if a fragment has not been played yet | 529 } else // if a fragment has not been played yet |
544 { | 530 { |
545 str = ""; | 531 str = ""; |
546 if (hasBeenPlayed.length > 1) { | 532 if (hasBeenPlayed.length > 1) { |
547 for (var i=0; i<hasBeenPlayed.length; i++) { | 533 for (var i=0; i<hasBeenPlayed.length; i++) { |
603 var pixelPosition = (position*width)+marginsize; | 589 var pixelPosition = (position*width)+marginsize; |
604 scaleObj.style.left = Math.floor((pixelPosition-($(scaleObj).width()/2)))+'px'; | 590 scaleObj.style.left = Math.floor((pixelPosition-($(scaleObj).width()/2)))+'px'; |
605 }); | 591 }); |
606 } | 592 } |
607 | 593 |
608 function pageXMLSave(testId) | 594 function pageXMLSave(store, testXML, testId) |
609 { | 595 { |
610 // Saves a specific test page | 596 // Saves a specific test page |
611 var xmlDoc = currentTestHolder; | 597 var xmlDoc = store; |
612 // Check if any session wide metrics are enabled | 598 // Check if any session wide metrics are enabled |
613 | 599 |
614 var commentShow = testXMLSetups[testId].attributes['elementComments']; | 600 var commentShow = testXML.attributes['elementComments']; |
615 if (commentShow != undefined) { | 601 if (commentShow != undefined) { |
616 if (commentShow.value == 'false') {commentShow = false;} | 602 if (commentShow.value == 'false') {commentShow = false;} |
617 else {commentShow = true;} | 603 else {commentShow = true;} |
618 } else {commentShow = true;} | 604 } else {commentShow = true;} |
619 | 605 |
714 console.log('Question ' + i + ': ' + commentQuestion[i].children[2].value); // DEBUG/SAFETY | 700 console.log('Question ' + i + ': ' + commentQuestion[i].children[2].value); // DEBUG/SAFETY |
715 cqHolder.appendChild(question); | 701 cqHolder.appendChild(question); |
716 cqHolder.appendChild(comment); | 702 cqHolder.appendChild(comment); |
717 xmlDoc.appendChild(cqHolder); | 703 xmlDoc.appendChild(cqHolder); |
718 } | 704 } |
719 testResultsHolders[testId] = xmlDoc; | 705 store = xmlDoc; |
720 } | 706 } |
721 | |
722 // Only other global function which must be defined in the interface class. Determines how to create the XML document. | |
723 function interfaceXMLSave(){ | |
724 // Create the XML string to be exported with results | |
725 var xmlDoc = document.createElement("BrowserEvaluationResult"); | |
726 xmlDoc.appendChild(returnDateNode()); | |
727 for (var i=0; i<testResultsHolders.length; i++) | |
728 { | |
729 xmlDoc.appendChild(testResultsHolders[i]); | |
730 } | |
731 // Append Pre/Post Questions | |
732 xmlDoc.appendChild(preTestQuestions); | |
733 xmlDoc.appendChild(postTestQuestions); | |
734 | |
735 return xmlDoc; | |
736 } |