Skip to content

Instantly share code, notes, and snippets.

@vpusher
Last active December 3, 2018 09:39
Show Gist options
  • Save vpusher/3582bdb57df858d0a89bea6a93be8e59 to your computer and use it in GitHub Desktop.
Save vpusher/3582bdb57df858d0a89bea6a93be8e59 to your computer and use it in GitHub Desktop.
function computeStats(table, betMin = 0, betMax = 1000) {
let rows = Array.prototype.slice.call(table.rows);
let winCount = 0;
let total = 0;
rows.forEach((row) => {
if (row.cells.length === 9) {
let leftScore = Number(row.cells[3].textContent.split(' - ')[0]);
let rightScore = Number(row.cells[3].textContent.split(' - ')[1]);
let leftBet = Number(row.cells[5].textContent);
let rightBet = Number(row.cells[7].textContent);
let shouldIncrement = false
// Left wins.
if ((leftBet >= betMin) && (leftBet <= betMax)) {
if ((leftScore > rightScore) && (leftBet < rightBet)) {
winCount++;
}
shouldIncrement = true
}
// Right wins.
if ((rightBet >= betMin) && (rightBet <= betMax)) {
if ((leftScore < rightScore) && (leftBet > rightBet)) {
winCount++;
}
shouldIncrement = true
}
if (shouldIncrement) {
total++;
}
}
})
return [winCount/total, winCount];
}
function findBestOddsRange(minOdds = 1.1, maxOdds = 2.5) {
let current1;
let current2;
let result = [];
for (current1 = minOdds; current1 <= maxOdds; current1 += 0.1) {
for (current2 = current1; current2 <= maxOdds; current2 += 0.1) {
if (!result[current1]) {
result[current1] = []
}
var [rate, count] = computeStats(document.querySelector('table'), current1, current2);
result[current1][current2] = (rate * 100).toFixed(1) + `/ ${count}`
}
}
return result
}
function exportToCsv(rows) {
let csvContent = "data:text/csv;charset=utf-8,";
csvContent += "," + Object.keys(rows).join(",") + "\r\n";
Object.keys(rows).forEach(function(odd){
let row = odd + "," + Object.values(rows[odd]).join(",");
csvContent += row + "\r\n";
});
console.log(csvContent)
var encodedUri = encodeURI(csvContent);
window.open(encodedUri);
}
table(findBestOddsRange());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment