Skip to content
Permalink
Browse files

Merge pull request #319 from lusbenjamin/order-bugfixes

Order bugfixes
  • Loading branch information...
Manuel-777 committed May 6, 2019
2 parents c08f48f + 451a496 commit 79599cb909f2a958168f0fce3477921ab32088ab
Showing with 32 additions and 13 deletions.
  1. +26 −9 shared/Aggregator.js
  2. +2 −1 window_main/decks.js
  3. +2 −1 window_main/history.js
  4. +2 −2 window_main/renderer.js
@@ -40,6 +40,7 @@ class Aggregator {
this.filterDeck = this.filterDeck.bind(this);
this.filterMatch = this.filterMatch.bind(this);
this.updateFilters = this.updateFilters.bind(this);
this.compareDecks = this.compareDecks.bind(this);
this.updateFilters(filters);
}

@@ -199,6 +200,7 @@ class Aggregator {
const eventSet = new Set();
this._decks = [];
const deckMap = {};
const deckLastPlayed = {};
const deckWinrates = {};
const deckRecentWinrates = {};
const archSet = new Set();
@@ -214,7 +216,15 @@ class Aggregator {
eventSet.add(match.eventId);
}
if (match.playerDeck) {
deckMap[match.playerDeck.id] = match.playerDeck;
const id = match.playerDeck.id;
let deckIsMoreRecent = true;
if (id in deckLastPlayed) {
deckIsMoreRecent = match.date > deckLastPlayed[id];
}
if (deckIsMoreRecent) {
deckMap[id] = match.playerDeck;
deckLastPlayed[id] = match.date;
}
}
// some of the data is wierd. Games which last years or have no data.
if (match.duration && match.duration < 3600) {
@@ -301,6 +311,8 @@ class Aggregator {
}
}
});
this.deckLastPlayed = deckLastPlayed;
this._eventIds.reverse();
this._stats = {
wins,
losses: loss,
@@ -338,14 +350,19 @@ class Aggregator {
this._decks.push(deck);
}
}
this._decks.sort((a, b) => {
const aName = getRecentDeckName(a.id);
const aExists = doesDeckStillExist(a.id) ? 1 : 0;
const bName = getRecentDeckName(b.id);
const bExists = doesDeckStillExist(b.id) ? 1 : 0;
// sort by existence, then name
return bExists - aExists || aName.localeCompare(bName);
});
this._decks.sort(this.compareDecks);
}

compareDecks(a, b) {
const dateMax = (a, b) => (a > b) ? a : b;
const aDate = dateMax(this.deckLastPlayed[a.id], a.lastUpdated);
const bDate = dateMax(this.deckLastPlayed[b.id], b.lastUpdated);
if (aDate && bDate && aDate !== bDate) {
return new Date(bDate) - new Date(aDate);
}
const aName = getRecentDeckName(a.id);
const bName = getRecentDeckName(b.id);
return aName.localeCompare(bName);
}

get matches() {
@@ -18,6 +18,7 @@ global
open_deck,
orderedCardRarities,
sidebarActive,
sidebarSize,
sort_decks,
getTagColor,
setTagColor,
@@ -30,7 +31,6 @@ filters.onlyCurrentDecks = true;
//
function open_decks_tab() {
if (sidebarActive == 0 && decks != null) {
sort_decks();
hideLoadingBars();
var mainDiv = document.getElementById("ux_0");
mainDiv.classList.add("flex_item");
@@ -98,6 +98,7 @@ function open_decks_tab() {
decks_top.appendChild(decks_top_filter);
wrap_l.appendChild(decks_top);

sort_decks(aggregator.compareDecks);
decks.filter(aggregator.filterDeck).forEach(function(deck, index) {
var tileGrpid = deck.deckTileId;

@@ -29,6 +29,7 @@ globals
setTagColor,
showLoadingBars,
sidebarActive,
sidebarSize,
sort_decks,
StatsPanel,
timeSince,
@@ -85,7 +86,6 @@ function open_history_tab(loadMore, _filters = {}) {
if (sidebarActive != 1 || decks == null) return;

let allMatches;
sort_decks();
hideLoadingBars();
var mainDiv = document.getElementById("ux_0");
var div, d;
@@ -120,6 +120,7 @@ function open_history_tab(loadMore, _filters = {}) {
const statsPanel = new StatsPanel("history_top", filteredMatches.stats, sidebarSize);
const historyTopWinrate = statsPanel.render();
div.appendChild(historyTopWinrate);
sort_decks(filteredMatches.compareDecks);

let wrap_l = createDivision(["wrapper_column"]);
wrap_l.setAttribute("id", "history_column");
@@ -2990,8 +2990,8 @@ function compare_color_winrates(a, b) {
}

//
function sort_decks() {
decks.sort(compare_decks);
function sort_decks(compareFunc = compare_decks) {
decks.sort(compareFunc);
decks.forEach(function(deck) {
deck.colors = [];
deck.colors = get_deck_colors(deck);

0 comments on commit 79599cb

Please sign in to comment.
You can’t perform that action at this time.