Mercurial > hg > webaudioevaluationtool
comparison js/core.js @ 2716:57ba3f490836
Better merge of master
author | Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk> |
---|---|
date | Fri, 14 Apr 2017 16:11:38 +0100 |
parents | 23f84278dc2a |
children | 723e1e5bae6f |
comparison
equal
deleted
inserted
replaced
2715:23f84278dc2a | 2716:57ba3f490836 |
---|---|
1211 testState.advanceState(); | 1211 testState.advanceState(); |
1212 } | 1212 } |
1213 | 1213 |
1214 function stateMachine() { | 1214 function stateMachine() { |
1215 // Object prototype for tracking and managing the test state | 1215 // Object prototype for tracking and managing the test state |
1216 | |
1217 function pickSubPool(pool, numElements) { | |
1218 // Assumes each element of pool has function "alwaysInclude" | |
1219 | |
1220 // First extract those excluded from picking process | |
1221 var picked = []; | |
1222 pool.forEach(function (e) { | |
1223 if (e.alwaysInclude) { | |
1224 picked.push(e); | |
1225 } | |
1226 }); | |
1227 | |
1228 return picked.concat(randomSubArray(pool, numElements - picked.length)); | |
1229 } | |
1230 | |
1216 this.stateMap = []; | 1231 this.stateMap = []; |
1217 this.preTestSurvey = null; | 1232 this.preTestSurvey = null; |
1218 this.postTestSurvey = null; | 1233 this.postTestSurvey = null; |
1219 this.stateIndex = null; | 1234 this.stateIndex = null; |
1220 this.currentStateMap = null; | 1235 this.currentStateMap = null; |
1222 this.currentStore = null; | 1237 this.currentStore = null; |
1223 this.initialise = function () { | 1238 this.initialise = function () { |
1224 | 1239 |
1225 // Get the data from Specification | 1240 // Get the data from Specification |
1226 var pagePool = []; | 1241 var pagePool = []; |
1227 var pageInclude = []; | 1242 for (var page of specification.pages) { |
1228 var i; | 1243 if (page.position !== null || page.alwaysInclude) { |
1229 for (i = 0; i < specification.pages.length; i++) { | 1244 page.alwaysInclude = true; |
1230 var page = specification.pages[i]; | 1245 } |
1231 if (page.alwaysInclude) { | 1246 pagePool.push(page); |
1232 pageInclude.push(page); | 1247 } |
1233 } else { | 1248 if (specification.numPages > 0) { |
1234 pagePool.push(page); | 1249 specification.randomiseOrder = true; |
1235 } | 1250 pagePool = pickSubPool(pagePool, specification.numPages); |
1236 } | 1251 } |
1237 | 1252 |
1238 // Find how many are left to get | 1253 // Now get the order of pages |
1239 var numPages = specification.poolSize; | 1254 var fixed = []; |
1240 if (numPages > pagePool.length) { | 1255 for (var page of pagePool) { |
1241 console.log("WARNING - You have specified more pages in <setup poolSize> than you have created!!"); | 1256 if (page.position !== null) { |
1242 numPages = specification.pages.length; | 1257 fixed.push(page); |
1243 } | 1258 var i = pagePool.indexOf(page); |
1244 if (specification.poolSize === 0) { | 1259 pagePool.splice(i, 1); |
1245 numPages = specification.pages.length; | 1260 } |
1246 } | 1261 } |
1247 numPages -= pageInclude.length; | 1262 |
1248 | |
1249 if (numPages > 0) { | |
1250 // Go find the rest of the pages from the pool | |
1251 var subarr = null; | |
1252 if (specification.randomiseOrder) { | |
1253 // Append a random sub-array | |
1254 subarr = randomSubArray(pagePool, numPages); | |
1255 } else { | |
1256 // Append the matching number | |
1257 subarr = pagePool.slice(0, numPages); | |
1258 } | |
1259 pageInclude = pageInclude.concat(subarr); | |
1260 } | |
1261 | |
1262 // We now have our selected pages in pageInclude array | |
1263 if (specification.randomiseOrder) { | 1263 if (specification.randomiseOrder) { |
1264 pageInclude = randomiseOrder(pageInclude); | 1264 pagePool = randomiseOrder(pagePool); |
1265 } | 1265 } |
1266 for (i = 0; i < pageInclude.length; i++) { | 1266 |
1267 pageInclude[i].presentedId = i; | 1267 // Place in the correct order |
1268 this.stateMap.push(pageInclude[i]); | 1268 for (var page of fixed) { |
1269 // For each selected page, we must get the sub pool | 1269 pagePool.splice(page.position, 0, page); |
1270 if (pageInclude[i].poolSize !== 0 && pageInclude[i].poolSize !== pageInclude[i].audioElements.length) { | 1270 } |
1271 var elemInclude = []; | 1271 |
1272 var elemPool = []; | 1272 // Now process the pages |
1273 for (var j = 0; j < pageInclude[i].audioElements.length; j++) { | 1273 pagePool.forEach(function (page, i) { |
1274 var elem = pageInclude[i].audioElements[j]; | 1274 page.presentedId = i; |
1275 if (elem.alwaysInclude || elem.type != "normal") { | 1275 this.stateMap.push(page); |
1276 elemInclude.push(elem); | 1276 var elements = page.audioElements; |
1277 } else { | 1277 if (page.poolSize > 0 || page.randomiseOrder) { |
1278 elemPool.push(elem); | 1278 page.randomiseOrder = true; |
1279 } | 1279 if (page.poolSize === 0) { |
1280 } | 1280 page.poolSize = page.randomiseOrder; |
1281 var numElems = pageInclude[i].poolSize - elemInclude.length; | 1281 } |
1282 pageInclude[i].audioElements = elemInclude.concat(randomSubArray(elemPool, numElems)); | 1282 elements = pickSubPool(elements, page.poolSize); |
1283 } | 1283 } |
1284 storage.createTestPageStore(pageInclude[i]); | 1284 if (page.randomiseOrder) { |
1285 audioEngineContext.loadPageData(pageInclude[i]); | 1285 elements = randomiseOrder(elements); |
1286 } | 1286 } |
1287 page.audioElements = elements; | |
1288 storage.createTestPageStore(page); | |
1289 audioEngineContext.loadPageData(page); | |
1290 }, this); | |
1287 | 1291 |
1288 if (specification.preTest !== null) { | 1292 if (specification.preTest !== null) { |
1289 this.preTestSurvey = specification.preTest; | 1293 this.preTestSurvey = specification.preTest; |
1290 } | 1294 } |
1291 if (specification.postTest !== null) { | 1295 if (specification.postTest !== null) { |