Mercurial > hg > webaudioevaluationtool
comparison js/core.js @ 2674:b9efbbe0d829
#191: Now added to <page> nodes the “position” attribute
author | Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk> |
---|---|
date | Thu, 13 Apr 2017 11:36:24 +0100 |
parents | a513533565cf |
children | 04cc7a27ae64 2dfc19a33bbc |
comparison
equal
deleted
inserted
replaced
2672:0b1c48849b4f | 2674:b9efbbe0d829 |
---|---|
1173 testState.advanceState(); | 1173 testState.advanceState(); |
1174 } | 1174 } |
1175 | 1175 |
1176 function stateMachine() { | 1176 function stateMachine() { |
1177 // Object prototype for tracking and managing the test state | 1177 // Object prototype for tracking and managing the test state |
1178 | |
1179 function pickSubPool(pool, numElements) { | |
1180 // Assumes each element of pool has function "alwaysInclude" | |
1181 | |
1182 // First extract those excluded from picking process | |
1183 var picked = []; | |
1184 pool.forEach(function (e) { | |
1185 if (e.alwaysInclude) { | |
1186 picked.push(e); | |
1187 } | |
1188 }); | |
1189 | |
1190 return picked.concat(randomSubArray(pool, numElements - excluded.length)); | |
1191 } | |
1192 | |
1178 this.stateMap = []; | 1193 this.stateMap = []; |
1179 this.preTestSurvey = null; | 1194 this.preTestSurvey = null; |
1180 this.postTestSurvey = null; | 1195 this.postTestSurvey = null; |
1181 this.stateIndex = null; | 1196 this.stateIndex = null; |
1182 this.currentStateMap = null; | 1197 this.currentStateMap = null; |
1184 this.currentStore = null; | 1199 this.currentStore = null; |
1185 this.initialise = function () { | 1200 this.initialise = function () { |
1186 | 1201 |
1187 // Get the data from Specification | 1202 // Get the data from Specification |
1188 var pagePool = []; | 1203 var pagePool = []; |
1189 var pageInclude = []; | |
1190 for (var page of specification.pages) { | 1204 for (var page of specification.pages) { |
1191 if (page.alwaysInclude) { | 1205 if (page.position !== null || page.alwaysInclude) { |
1192 pageInclude.push(page); | 1206 page.alwaysInclude = true; |
1193 } else { | 1207 } |
1194 pagePool.push(page); | 1208 pagePool.push(page) |
1195 } | 1209 } |
1196 } | 1210 if (specification.numPages > 0) { |
1197 | 1211 specification.randomiseOrder = true; |
1198 // Find how many are left to get | 1212 pagePool = pickSubPool(pagePool, specification.numPages); |
1199 var numPages = specification.poolSize; | 1213 } |
1200 if (numPages > pagePool.length) { | 1214 |
1201 console.log("WARNING - You have specified more pages in <setup poolSize> than you have created!!"); | 1215 // Now get the order of pages |
1202 numPages = specification.pages.length; | 1216 var fixed = [] |
1203 } | 1217 for (var page of pagePool) { |
1204 if (specification.poolSize == 0) { | 1218 if (page.position !== null) { |
1205 numPages = specification.pages.length; | 1219 fixed.push(page); |
1206 } | 1220 var i = pagePool.indexOf(page); |
1207 numPages -= pageInclude.length; | 1221 pagePool.splice(i, 1); |
1208 | 1222 } |
1209 if (numPages > 0) { | 1223 } |
1210 // Go find the rest of the pages from the pool | 1224 |
1211 var subarr = null; | |
1212 if (specification.randomiseOrder) { | |
1213 // Append a random sub-array | |
1214 subarr = randomSubArray(pagePool, numPages); | |
1215 } else { | |
1216 // Append the matching number | |
1217 subarr = pagePool.slice(0, numPages); | |
1218 } | |
1219 pageInclude = pageInclude.concat(subarr); | |
1220 } | |
1221 | |
1222 // We now have our selected pages in pageInclude array | |
1223 if (specification.randomiseOrder) { | 1225 if (specification.randomiseOrder) { |
1224 pageInclude = randomiseOrder(pageInclude); | 1226 pagePool = randomiseOrder(pagePool); |
1225 } | 1227 } |
1226 for (var i = 0; i < pageInclude.length; i++) { | 1228 |
1227 pageInclude[i].presentedId = i; | 1229 // Place in the correct order |
1228 this.stateMap.push(pageInclude[i]); | 1230 for (var page of fixed) { |
1229 // For each selected page, we must get the sub pool | 1231 pagePool.splice(page.position, 0, page) |
1230 if (pageInclude[i].poolSize != 0 && pageInclude[i].poolSize != pageInclude[i].audioElements.length) { | 1232 } |
1231 var elemInclude = []; | 1233 |
1232 var elemPool = []; | 1234 // Now process the pages |
1233 for (var elem of pageInclude[i].audioElements) { | 1235 pagePool.forEach(function (page, i) { |
1234 if (elem.alwaysInclude || elem.type != "normal") { | 1236 page.presentedId = i; |
1235 elemInclude.push(elem); | 1237 this.stateMap.push(page); |
1236 } else { | 1238 var elements = page.audioElements |
1237 elemPool.push(elem); | 1239 if (page.poolSize > 0 || page.randomiseOrder) { |
1238 } | 1240 page.randomiseOrder = true; |
1239 } | 1241 if (page.poolSize == 0) { |
1240 var numElems = pageInclude[i].poolSize - elemInclude.length; | 1242 page.poolSize = page.randomiseOrder; |
1241 pageInclude[i].audioElements = elemInclude.concat(randomSubArray(elemPool, numElems)); | 1243 } |
1242 } | 1244 elements = pickSubPool(elements, page.poolSize); |
1243 storage.createTestPageStore(pageInclude[i]); | 1245 } |
1244 audioEngineContext.loadPageData(pageInclude[i]); | 1246 if (page.randomiseOrder) { |
1245 } | 1247 elements = randomiseOrder(elements); |
1248 } | |
1249 page.audioElements = elements; | |
1250 storage.createTestPageStore(page); | |
1251 audioEngineContext.loadPageData(page); | |
1252 }, this) | |
1246 | 1253 |
1247 if (specification.preTest != null) { | 1254 if (specification.preTest != null) { |
1248 this.preTestSurvey = specification.preTest; | 1255 this.preTestSurvey = specification.preTest; |
1249 } | 1256 } |
1250 if (specification.postTest != null) { | 1257 if (specification.postTest != null) { |