# HG changeset patch # User www-data # Date 1492183251 -3600 # Node ID 2b14c1d1f8936c045858d2f9a6c4c6e5804b1e1c # Parent 1f529b6e2d88d929be36a86c6a9c4fca29264a6b# Parent b9efbbe0d829f31def8ed1128c2da88bcee89e25 Merge branch 'master' of https://github.com/BrechtDeMan/WebAudioEvaluationTool diff -r 1f529b6e2d88 -r 2b14c1d1f893 js/core.js --- a/js/core.js Wed Mar 29 16:21:07 2017 +0100 +++ b/js/core.js Fri Apr 14 16:20:51 2017 +0100 @@ -1175,6 +1175,21 @@ function stateMachine() { // Object prototype for tracking and managing the test state + + function pickSubPool(pool, numElements) { + // Assumes each element of pool has function "alwaysInclude" + + // First extract those excluded from picking process + var picked = []; + pool.forEach(function (e) { + if (e.alwaysInclude) { + picked.push(e); + } + }); + + return picked.concat(randomSubArray(pool, numElements - excluded.length)); + } + this.stateMap = []; this.preTestSurvey = null; this.postTestSurvey = null; @@ -1186,63 +1201,55 @@ // Get the data from Specification var pagePool = []; - var pageInclude = []; for (var page of specification.pages) { - if (page.alwaysInclude) { - pageInclude.push(page); - } else { - pagePool.push(page); + if (page.position !== null || page.alwaysInclude) { + page.alwaysInclude = true; + } + pagePool.push(page) + } + if (specification.numPages > 0) { + specification.randomiseOrder = true; + pagePool = pickSubPool(pagePool, specification.numPages); + } + + // Now get the order of pages + var fixed = [] + for (var page of pagePool) { + if (page.position !== null) { + fixed.push(page); + var i = pagePool.indexOf(page); + pagePool.splice(i, 1); } } - // Find how many are left to get - var numPages = specification.poolSize; - if (numPages > pagePool.length) { - console.log("WARNING - You have specified more pages in than you have created!!"); - numPages = specification.pages.length; - } - if (specification.poolSize == 0) { - numPages = specification.pages.length; - } - numPages -= pageInclude.length; - - if (numPages > 0) { - // Go find the rest of the pages from the pool - var subarr = null; - if (specification.randomiseOrder) { - // Append a random sub-array - subarr = randomSubArray(pagePool, numPages); - } else { - // Append the matching number - subarr = pagePool.slice(0, numPages); - } - pageInclude = pageInclude.concat(subarr); + if (specification.randomiseOrder) { + pagePool = randomiseOrder(pagePool); } - // We now have our selected pages in pageInclude array - if (specification.randomiseOrder) { - pageInclude = randomiseOrder(pageInclude); + // Place in the correct order + for (var page of fixed) { + pagePool.splice(page.position, 0, page) } - for (var i = 0; i < pageInclude.length; i++) { - pageInclude[i].presentedId = i; - this.stateMap.push(pageInclude[i]); - // For each selected page, we must get the sub pool - if (pageInclude[i].poolSize != 0 && pageInclude[i].poolSize != pageInclude[i].audioElements.length) { - var elemInclude = []; - var elemPool = []; - for (var elem of pageInclude[i].audioElements) { - if (elem.alwaysInclude || elem.type != "normal") { - elemInclude.push(elem); - } else { - elemPool.push(elem); - } + + // Now process the pages + pagePool.forEach(function (page, i) { + page.presentedId = i; + this.stateMap.push(page); + var elements = page.audioElements + if (page.poolSize > 0 || page.randomiseOrder) { + page.randomiseOrder = true; + if (page.poolSize == 0) { + page.poolSize = page.randomiseOrder; } - var numElems = pageInclude[i].poolSize - elemInclude.length; - pageInclude[i].audioElements = elemInclude.concat(randomSubArray(elemPool, numElems)); + elements = pickSubPool(elements, page.poolSize); } - storage.createTestPageStore(pageInclude[i]); - audioEngineContext.loadPageData(pageInclude[i]); - } + if (page.randomiseOrder) { + elements = randomiseOrder(elements); + } + page.audioElements = elements; + storage.createTestPageStore(page); + audioEngineContext.loadPageData(page); + }, this) if (specification.preTest != null) { this.preTestSurvey = specification.preTest; diff -r 1f529b6e2d88 -r 2b14c1d1f893 js/specification.js --- a/js/specification.js Wed Mar 29 16:21:07 2017 +0100 +++ b/js/specification.js Fri Apr 14 16:20:51 2017 +0100 @@ -521,6 +521,7 @@ this.interfaces = []; this.playOne = null; this.restrictMovement = null; + this.position = null; this.commentBoxPrefix = "Comment on track"; this.audioElements = []; this.commentQuestions = []; diff -r 1f529b6e2d88 -r 2b14c1d1f893 xml/test-schema.xsd --- a/xml/test-schema.xsd Wed Mar 29 16:21:07 2017 +0100 +++ b/xml/test-schema.xsd Fri Apr 14 16:20:51 2017 +0100 @@ -100,6 +100,7 @@ +