Skip to content

Instantly share code, notes, and snippets.

@DylanDelobel
Created April 16, 2019 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DylanDelobel/964ed2580aae54a9e09206a5a8964c91 to your computer and use it in GitHub Desktop.
Save DylanDelobel/964ed2580aae54a9e09206a5a8964c91 to your computer and use it in GitHub Desktop.
Elo calculator
function GetGloryFromWins(totalwins) {
if (totalwins <= 150)
return 20 * totalwins;
return Math.floor((10 * (45 * Math.pow(Math.log10(totalwins * 2), 2))) + 245);
}
function GetGloryFromBestRating(bestrating) {
var retval = 0;
if (bestrating < 1200)
retval = 250;
if (bestrating >= 1200 && bestrating < 1286)
retval = 10 * (25 + ((0.872093023) * (86 - (1286 - bestrating))));
if (bestrating >= 1286 && bestrating < 1390)
retval = 10 * (100 + ((0.721153846) * (104 - (1390 - bestrating))));
if (bestrating >= 1390 && bestrating < 1680)
retval = 10 * (187 + ((0.389655172) * (290 - (1680 - bestrating))));
if (bestrating >= 1680 && bestrating < 2000)
retval = 10 * (300 + ((0.428125) * (320 - (2000 - bestrating))));
if (bestrating >= 2000 && bestrating < 2300)
retval = 10 * (437 + ((0.143333333) * (300 - (2300 - bestrating))));
if (bestrating >= 2300)
retval = 10 * (480 + ((0.05) * (400 - (2700 - bestrating))));
return Math.floor(retval);
}
function GetHeroEloFromOldElo(elo) {
if (elo < 2000)
return Math.floor((elo + 375) / 1.5);
return Math.floor(1583 + (elo - 2000) / 10)
}
function GetPersonalEloFromOldElo(elo) {
if (elo >= 1400)
return Math.floor(1400 + (elo - 1400.0) / (3.0 - (3000 - elo) / 800.0))
return elo;
}
function Submit() {
var myDiv = document.getElementById("results");
var box = document.getElementById("mingamesbox");
if (!box.checked) {
myDiv.innerHTML = "Sorry, gotta play 10 games!";
return;
}
var bestRating = parseFloat(document.getElementById("best").value);
var wins = parseFloat(document.getElementById("wins").value);
var gloryFromBest = GetGloryFromBestRating(bestRating);
var gloryFromWins = GetGloryFromWins(wins);
var gloryTotal = (gloryFromBest + gloryFromWins);
myDiv.innerHTML = "Glory from Wins: " + gloryFromWins + "<br>Glory from best rating: " + gloryFromBest + "<br>Total Glory this Season: " + gloryTotal;
}
function SubmitSquash() {
var myDiv = document.getElementById("resultsSquash");
var personalRating = parseFloat(document.getElementById("curr").value);
var heroRating = parseFloat(document.getElementById("herorating").value);
var outPersonal = GetPersonalEloFromOldElo(personalRating);
var outHero = GetHeroEloFromOldElo(heroRating);
myDiv.innerHTML = "New personal: " + outPersonal + "<br>New Hero/Team: " + outHero;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment