Skip to content

Instantly share code, notes, and snippets.

@ivanpepelko
Last active September 30, 2015 09:35
Show Gist options
  • Save ivanpepelko/8ef121fc3f751ea9a12e to your computer and use it in GitHub Desktop.
Save ivanpepelko/8ef121fc3f751ea9a12e to your computer and use it in GitHub Desktop.
Dotabuff heroes sorting
(function () {
$('.tableAd').remove();
$('.score').remove();
var totalMatches = parseInt($('.game-record .wins').text().replace(',', ''))
+ parseInt($('.game-record .losses').text().replace(',', ''))
+ parseInt($('.game-record .abandons').text().replace(',', ''));
$('table thead tr').append('<th class="nosort score" data-sortcolumn="5" data-sortkey="5-0">Score</th>');
$('table tbody tr').each(function() {
var MP = parseInt($(this).find('td').eq(2).text());
var WR = parseFloat($(this).find('td').eq(3).text());
var KDA = parseFloat($(this).find('td').eq(4).text());
var score = (MP / totalMatches) * WR * KDA;
var scoreView = parseInt(score * 1000);
$(this).append('<td class=score data-value=' + scoreView + '>' + scoreView + '</td>')
});
})();
(function () {
$('.tableAd').remove();
var totalMatches = parseInt($('.game-record .wins').text().replace(',', ''))
+ parseInt($('.game-record .losses').text().replace(',', ''))
+ parseInt($('.game-record .abandons').text().replace(',', ''));
console.log(totalMatches);
parseFloat($('table tbody tr').eq(0).find('td').eq(4).text())
var sorted = $('table tbody tr').sort(function (a, b) {
var aMP = parseInt($(a).find('td').eq(2).text());
var aWR = parseFloat($(a).find('td').eq(3).text());
var aKDA = parseFloat($(a).find('td').eq(4).text());
var bMP = parseInt($(b).find('td').eq(2).text());
var bWR = parseFloat($(b).find('td').eq(3).text());
var bKDA = parseFloat($(b).find('td').eq(4).text());
var theA = (aMP / totalMatches) * aWR * aKDA;
var theB = (bMP / totalMatches) * bWR * bKDA;
return theB - theA;
});
$('table tbody').html(sorted);
}) ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment