Permalink
Browse files

by color winrates

IMproved the algorithm to calculate a deck's colors by also counting lands.
  • Loading branch information...
Manuel-777 committed Nov 6, 2018
1 parent 9eebdad commit 896743d834784babbbc47b8b3ea336e3ed8392e7
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN +3.25 KB images/type_land.png
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -592,6 +592,13 @@ function get_deck_colors(deck) {
if (cdb) {
var card_name = cdb.name;
var card_cost = cdb.cost;
if (cdb.type.indexOf("Land") !== -1 && cdb.frame.length < 3) {
if (cdb.frame.includes(1) && !deck.colors.includes(1)) deck.colors.push(1);
if (cdb.frame.includes(2) && !deck.colors.includes(2)) deck.colors.push(2);
if (cdb.frame.includes(3) && !deck.colors.includes(3)) deck.colors.push(3);
if (cdb.frame.includes(4) && !deck.colors.includes(4)) deck.colors.push(4);
if (cdb.frame.includes(5) && !deck.colors.includes(5)) deck.colors.push(5);
}
card_cost.forEach(function(c) {
if (c.indexOf('w') !== -1 && !deck.colors.includes(1)) deck.colors.push(1);
if (c.indexOf('u') !== -1 && !deck.colors.includes(2)) deck.colors.push(2);
@@ -662,6 +669,9 @@ function add_deck_colors(colors, deck) {
//
function compare_colors(color_a, color_b) {
if (color_a.length != color_b.length)
return false;
for (var i = color_a.length; i--;) {
if (color_a[i] !== color_b[i]) {
return false;
@@ -292,9 +292,11 @@ function requestHistorySend(state) {
calculateRankWins(history);
}
if (state == 1) {
// Send the data and open history tab
ipc_send("background_set_history", JSON.stringify(history));
}
else {
/// Send only the data
ipc_send("background_set_history_data", JSON.stringify(history));
}
}
@@ -2388,6 +2390,7 @@ function httpBasic() {
eventsList = parsedResult.events;
ipc_send("set_db", parsedResult);
cardsDb.set(parsedResult);
ipc_send("popup", {"text": "Metadata: Ok", "time": 1000});
}
}
@@ -36,6 +36,7 @@ var currentOpenDeck = null;
var lastSettingsSection = 1;
var serverStatus = undefined;
var loggedIn = false;
var canLogin = false;
var rankOffset = 0;
var rankTitle = "";
@@ -99,6 +100,7 @@ ipc.on('set_db', function (event, arg) {
eventsList = arg.events;
delete arg.sets;
delete arg.events;
canLogin = true;
cardsDb.set(arg);
});
@@ -537,12 +539,14 @@ $(document).ready(function() {
});
$(".login_link").click(function() {
var user = document.getElementById("signin_user").value;
var pass = document.getElementById("signin_pass").value;
if (pass != "********") {
pass = sha1(pass);
if (canLogin) {
var user = document.getElementById("signin_user").value;
var pass = document.getElementById("signin_pass").value;
if (pass != "********") {
pass = sha1(pass);
}
ipc_send("login", {username: user, password: pass});
}
ipc_send("login", {username: user, password: pass});
});
//
@@ -2268,19 +2272,23 @@ function open_deck(i, type) {
}
for (let i=0; i<wr.colors.length; i++) {
curvediv.append($('<div class="mana_curve_column back_green" style="height: '+(wr.colors[i].wins/curveMax*100)+'%"></div>'))
curvediv.append($('<div class="mana_curve_column back_red" style="height: '+(wr.colors[i].losses/curveMax*100)+'%"></div>'))
if (wr.colors[i].wins + wr.colors[i].losses > 2) {
curvediv.append($('<div class="mana_curve_column back_green" style="height: '+(wr.colors[i].wins/curveMax*100)+'%"></div>'))
curvediv.append($('<div class="mana_curve_column back_red" style="height: '+(wr.colors[i].losses/curveMax*100)+'%"></div>'))
}
}
curvediv.appendTo(stats);
var curvediv = $('<div class="mana_curve_costs"></div>');
for (let i=0; i<wr.colors.length; i++) {
var cn = $('<div class="mana_curve_column_number"></div>');
var colors = wr.colors[i].colors;
colors.forEach(function(color) {
cn.append($('<div style="margin: 0 auto !important" class="mana_s16 mana_'+mana[color]+'"></div>'));
})
curvediv.append(cn);
if (wr.colors[i].wins + wr.colors[i].losses > 2) {
var cn = $('<div class="mana_curve_column_number"></div>');
var colors = wr.colors[i].colors;
colors.forEach(function(color) {
cn.append($('<div style="margin: 0 auto !important" class="mana_s16 mana_'+mana[color]+'"></div>'));
})
curvediv.append(cn);
}
}
curvediv.appendTo(stats);
}
@@ -3947,6 +3955,7 @@ function getDeckWinrate(deckid, lastEdit) {
if (matchesHistory == undefined) {
return 0;
}
matchesHistory.matches.forEach(function(matchid, index) {
match = matchesHistory[matchid];
if (matchid != null && match != undefined) {
@@ -3955,6 +3964,7 @@ function getDeckWinrate(deckid, lastEdit) {
var oppDeckColors = get_deck_colors(match.oppDeck);
if (oppDeckColors.length > 0) {
var added = -1;
colorsWinrates.forEach(function(wr, index) {
if (compare_colors(wr.colors, oppDeckColors)) {
added = index;
@@ -4001,11 +4011,22 @@ function getDeckWinrate(deckid, lastEdit) {
var winrateLastEdit = Math.round((1/(winsLastEdit+lossLastEdit)*winsLastEdit) * 100) / 100;
if (winsLastEdit == 0) winrateLastEdit = 0;
colorsWinrates.sort(compare_color_winrates);
//colorsWinrates.sort(compare_color_winrates);
colorsWinrates.sort(compare_winrates);
return {total: winrate, lastEdit: winrateLastEdit, colors: colorsWinrates};
}
function compare_winrates(a, b) {
var _a = a.wins/a.losses;
var _b = b.wins/b.losses;
if (_a < _b) return 1;
if (_a > _b) return -1;
return compare_color_winrates(a, b);
}
function compare_color_winrates(a, b) {
var a = a.colors;
var b = b.colors;

0 comments on commit 896743d

Please sign in to comment.