Last active
September 30, 2015 09:35
-
-
Save ivanpepelko/8ef121fc3f751ea9a12e to your computer and use it in GitHub Desktop.
Dotabuff heroes sorting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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>') | |
}); | |
})(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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