Permalink
Browse files

Filter history by event

  • Loading branch information...
Manuel-777 committed Dec 30, 2018
1 parent 800d64d commit 4822a00d5423a28fe331e1a5444fdcc19cb4f73b
Showing with 96 additions and 6 deletions.
  1. +77 −6 window_main/history.js
  2. +10 −0 window_main/index.css
  3. +9 −0 window_main/renderer.js
@@ -18,10 +18,13 @@ globals
rankLimitedTier,
rankConstructed,
rankConstructedStep,
rankConstructedTier
rankConstructedTier,
getReadableEvent
*/
let loadHistory = 0;
let filterEvent = 'All';
let filteredSampleSize = 0;

function open_history_tab(loadMore) {
var mainDiv = document.getElementById("ux_0");
@@ -106,21 +109,84 @@ function open_history_tab(loadMore) {
}

mainDiv = document.getElementById("history_column");

// Event ID filter
if (loadHistory == 0) {
let events_list = [];
let wins = 0;
let losses = 0;
filteredSampleSize = 0;
matchesHistory.matches.forEach((matchId) => {
let match = matchesHistory[matchId];
if (match) {
if (match.eventId) {
if (events_list.indexOf(match.eventId) == -1) {
events_list.push(match.eventId);
}
if (filterEvent == 'All' || match.eventId == filterEvent) {
wins += match.player.win;
losses += match.opponent.win;
filteredSampleSize++;
}
}
}
});
if (filteredSampleSize == 0) filteredSampleSize = matchesHistory.matches.length;

div = document.createElement("div");
div.classList.add("history_top");

let history_top_filter = document.createElement("div");
history_top_filter.classList.add('history_top_filter');

let history_top_winrate = document.createElement("div");
history_top_winrate.classList.add('history_top_winrate');

d = document.createElement("div");
d.classList.add('list_deck_winrate');
let wrTotal = 1 / (wins+losses) * wins;

let colClass = getWinrateClass(wrTotal);

d.innerHTML = `'Wins: ${wins} / Losses: ${losses} (<span class="${colClass}_bright">${Math.round(wrTotal*100)}%</span>)`;
history_top_winrate.appendChild(d);

div.appendChild(history_top_filter);
div.appendChild(history_top_winrate);

var select = $('<select id="query_select"></select>');
if (filterEvent != "All") {
select.append('<option value="All">All</option>');
}
events_list.forEach((evId) => {
if (evId !== filterEvent) {
select.append('<option value="'+evId+'">'+getReadableEvent(evId)+'</option>');
}
});
history_top_filter.appendChild(select[0]);
mainDiv.appendChild(div);
selectAdd(select, filterHistory);
select.next('div.select-styled').text(getReadableEvent(filterEvent));
}

console.log("Load more: ", loadHistory, loadMore, loadHistory+loadMore);
for (var loadEnd = loadHistory + loadMore; loadHistory < loadEnd; loadHistory++) {
//console.log("Load more: ", loadHistory, loadMore, loadHistory+loadMore);
var actuallyLoaded = loadHistory;
for (var loadEnd = loadHistory + loadMore; actuallyLoaded < loadEnd && loadHistory <= matchesHistory.matches.length && actuallyLoaded < filteredSampleSize; loadHistory++) {
var match_id = matchesHistory.matches[loadHistory];
var match = matchesHistory[match_id];

console.log("match: ", match_id, match);
//console.log("match: ", match_id, match);
if (match == undefined) continue;
if (match.type == "match") {
if (match.opponent == undefined) continue;
if (match.opponent.userid.indexOf("Familiar") !== -1) continue;
}
if (match.type == "Event") continue;
console.log("Load match: ", match_id, match);
console.log("Match: ", loadHistory, match.type, match);
if (filterEvent !== 'All' && filterEvent !== match.eventId) continue;

actuallyLoaded++;
//console.log("Load match: ", match_id, match);
//console.log("Match: ", loadHistory, match.type, match);

div = document.createElement("div");
div.classList.add(match.id);
@@ -323,6 +389,11 @@ function open_history_tab(loadMore) {
loadHistory = loadEnd;
}

function filterHistory(filter) {
filterEvent = filter;
open_history_tab(0);
}

function getNextRank(mode) {
let cr = rankLimited;
if (!mode) cr = rankConstructed;
@@ -712,6 +712,13 @@ a:hover {
justify-content: space-between;
}

.history_top {
display: flex;
height: 64px;
margin-left: 16px;
justify-content: space-between;
}

.list_deck_name {
-webkit-user-select:none;
align-self: center;
@@ -2032,6 +2039,9 @@ a:hover {
.select-options {
display: none;
position: absolute;
max-height: 384px;
overflow-y: auto;
overflow-x: hidden;
top: 100%;
right: 0;
left: 0;
@@ -2215,6 +2215,15 @@ function updateSettings() {
ipc_send('save_settings', settings);
}

//
function getWinrateClass(wr) {
if (wr > 0.65) return 'blue';
if (wr > 0.55) return 'green';
if (wr < 0.45) return 'orange';
if (wr < 0.35) return 'red';
return 'white';
}

//
function getDeckWinrate(deckid, lastEdit) {
var wins = 0;

1 comment on commit 4822a00

@Manuel-777

This comment has been minimized.

Copy link
Owner

Manuel-777 commented on 4822a00 Dec 30, 2018

fixes #11
(this one took a very long time to get done! wow!)

Please sign in to comment.