Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions index.html
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
background <input type='text' value='#f5f5f5' class='settinginput' id='bgcolor_in' onchange="applystyle();" placeholder='#f5f5f5' maxlength='12'/>
, text <input type='text' value='black' class='settinginput' id='textcolor_in' onchange="applystyle();" placeholder='#000' maxlength='12'/>
, links <input type='text' value='#004411' class='settinginput' id='linkscolor_in' onchange="applystyle();" placeholder='#004411' maxlength='12'/>
, goal (ms) <input type='number' value = 0 class='settinginput' id='goal_in' onchange="applygoal();" placeholder=0 max=10000 title="Goal in ms to beat in each alg solve. If you beat the goal, the probability of getting the same alg will decrease. Otherwise it will increase. Leave this at 0 (default) to keep every selected alg with the same probability."/> (0 or empty to ignore dynamic weights)
<br>
<span id="last_scramble">
Any questions/suggestions/bugs reports - post in <a href="https://www.speedsolving.com/forum/threads/oll-trainer.66924/" target="_blank" class="settings">this thread</a>
Expand Down
8 changes: 8 additions & 0 deletions scripts/algsinfo.js
Original file line number Diff line number Diff line change
@@ -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],
Expand All @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions scripts/saveload.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
46 changes: 43 additions & 3 deletions scripts/timer.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -389,6 +417,7 @@ function confirmClear()
{
if (confirm("Are you sure you want to clear session?")) {
window.timesArray = [];
initializeSelCasesWeights();
document.getElementById('infoHeader').innerHTML = ('')
displayStats();
}
Expand Down Expand Up @@ -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
Expand All @@ -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]);
Expand Down Expand Up @@ -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) {
Expand Down