diff --git a/index.html b/index.html old mode 100755 new mode 100644 index 0ccf3d9..ae4915c --- a/index.html +++ b/index.html @@ -42,6 +42,7 @@ background , text , links + , goal (ms) (0 or empty to ignore dynamic weights)
Any questions/suggestions/bugs reports - post in this thread diff --git a/scripts/algsinfo.js b/scripts/algsinfo.js index fab7265..f014fa4 100755 --- a/scripts/algsinfo.js +++ b/scripts/algsinfo.js @@ -1,5 +1,9 @@ var selCases = []; +var algsOrder = []; + +var selCasesWeights = []; + var algsGroups = { "All Edges Oriented Correctly" : [26, 27, 21, 22, 24, 25, 23], "T-Shapes" : [33, 45], @@ -17,6 +21,10 @@ var algsGroups = { "No Edges Flipped Correctly" : [1,2,3,4,18,19,17,20], }; +for (i in algsGroups) { + algsOrder = algsOrder.concat(algsGroups[i]); +} + var algsInfo = { 1: { "name": "Runway", diff --git a/scripts/saveload.js b/scripts/saveload.js old mode 100755 new mode 100644 index ad23ceb..3b062d4 --- a/scripts/saveload.js +++ b/scripts/saveload.js @@ -27,7 +27,13 @@ function loadLocal(name, defaultValue) { } } +function initializeSelCasesWeights() { + window.selCasesWeights = new Array(window.selCases.length).fill(1); +} + function saveSelection() { + // we re-initialize the weights on selection change (save) + initializeSelCasesWeights(); return saveLocal('ollSelection', JSON.stringify(window.selCases)); } diff --git a/scripts/timer.js b/scripts/timer.js old mode 100755 new mode 100644 index 5d08fc8..89ccc2f --- a/scripts/timer.js +++ b/scripts/timer.js @@ -4,6 +4,7 @@ if (timesArray == null) // todo fix when figure out why JSON.parse("[]") returns timesArray = []; var lastScramble = ""; var lastCase = 0; +var goal = 0; displayStats(); // after loading @@ -29,6 +30,31 @@ function randomElement(arr) return arr[Math.floor(Math.random()*arr.length)]; } +// https://stackoverflow.com/a/55671924 +function randomWeightedElement(items, weights) { + var i; + var _w = weights.slice(); // don't want to modify the original weights + + for (i = 1; i < _w.length; i++) + _w[i] += _w[i - 1]; + + var random = Math.random() * _w[_w.length - 1]; + + for (i = 0; i < _w.length; i++) + if (_w[i] > random) + break; + + return items[i]; +} + +function updateSelectedWeights(ms) +{ + if (isNaN(window.goal) || window.goal == 0) return; + const index = window.selCases.indexOf(window.lastCase); + if (ms > window.goal) window.selCasesWeights[index] *= 2; + else window.selCasesWeights[index] /= 2; +} + function confirmUnsel(i) { if (confirm("Do you want to unselect this case?")) { var index = window.selCases.indexOf(i); @@ -62,7 +88,7 @@ function generateScramble() // get random case var caseNum = 0; if (recapArray.length == 0) { // train - caseNum = randomElement(window.selCases); + caseNum = randomWeightedElement(window.selCases, window.selCasesWeights); } else { // recap // select the case caseNum = randomElement(window.recapArray); @@ -348,7 +374,9 @@ function escapeHtml(text) { function appendStats() { // assuming the time can be grabbed from timer label, and the case - window.lastCase - window.timesArray.push(makeResultInstance()); + var mri = makeResultInstance(); + window.timesArray.push(mri); + updateSelectedWeights(mri.ms); displayStats(); } @@ -389,6 +417,7 @@ function confirmClear() { if (confirm("Are you sure you want to clear session?")) { window.timesArray = []; + initializeSelCasesWeights(); document.getElementById('infoHeader').innerHTML = ('') displayStats(); } @@ -453,7 +482,10 @@ function displayStats() } var keys = Object.keys(resultsByCase); - keys.sort(); + keys.sort(function(a, b) { + //return parseInt(a) - parseInt(b); // old simple fix numerical order + return algsOrder.indexOf(a) - algsOrder.indexOf(b); // new algsinfo ordering + }); var s = ""; // allocate them inside times span @@ -462,6 +494,8 @@ function displayStats() var timesString = ""; var meanForCase = 0.0; var i = 0; + if (!isNaN(window.goal) && window.goal > 0) + timesString += "[weight: " + window.selCasesWeights[window.selCases.indexOf(parseInt(oll))] + "] "; for (; i < resultsByCase[oll].length; i++) { timesString += makeHtmlDisplayableTime(resultsByCase[oll][i]); @@ -570,6 +604,12 @@ function resetStyle(dark) { savestyle(); } +function applygoal() { + //window.goal = document.getElementById("goal_in").value; + window.goal = document.querySelector('#goal_in').valueAsNumber; + displayStats(); +} + // add key listeners to blur settings inputs var inputs = document.getElementsByClassName("settinginput"); Array.prototype.forEach.call(inputs, function(el) {