Skip to content
Permalink
Browse files

Merge pull request #617 from Lego6245/sortByWildcards

Add "Sort By Wildcards" function
  • Loading branch information...
Manuel-777 committed Oct 11, 2019
2 parents 6eed44f + 850ba6a commit d5cf1644259ee55eda7f1c42ce619722be14c355
Showing with 31 additions and 2 deletions.
  1. +28 −1 window_main/aggregator.js
  2. +2 −0 window_main/decks.js
  3. +1 −1 window_main/filter-panel.js
@@ -15,7 +15,12 @@ const {
} = require("../shared/constants");
const db = require("../shared/database");
const pd = require("../shared/player-data");
const { getReadableEvent, getRecentDeckName } = require("../shared/util");
const {
getReadableEvent,
getRecentDeckName,
get_deck_missing,
getBoosterCountEstimate
} = require("../shared/util");
const { normalApproximationInterval } = require("../shared/stats-fns");

// Default filter values
@@ -47,6 +52,9 @@ class Aggregator {
this.compareDecks = this.compareDecks.bind(this);
this.compareDecksByWins = this.compareDecksByWins.bind(this);
this.compareDecksByWinrates = this.compareDecksByWinrates.bind(this);
this.compareDecksByIncompleteness = this.compareDecksByIncompleteness.bind(
this
);
this.compareEvents = this.compareEvents.bind(this);
this.updateFilters(filters);
}
@@ -460,6 +468,25 @@ class Aggregator {
);
}

compareDecksByIncompleteness(a, b) {
const aMissing = get_deck_missing(a);
const bMissing = get_deck_missing(b);
const aMissingBoosters = getBoosterCountEstimate(aMissing);
const bMissingBoosters = getBoosterCountEstimate(bMissing);

const aName = getRecentDeckName(a.id);
const bName = getRecentDeckName(b.id);

return (
bMissingBoosters - aMissingBoosters ||
bMissing.mythic - aMissing.mythic ||
bMissing.rare - aMissing.rare ||
bMissing.uncommon - aMissing.uncommon ||
bMissing.common - aMissing.common ||
aName.localeCompare(bName)
);
}

compareEvents(a, b) {
const aDate = this.eventLastPlayed[a];
const bDate = this.eventLastPlayed[b];
@@ -113,6 +113,8 @@ function openDecksTab(_filters = {}, scrollTop = 0) {
decks.sort(aggregator.compareDecksByWinrates);
} else if (filters.sort === "By Wins") {
decks.sort(aggregator.compareDecksByWins);
} else if (filters.sort === "By Incomplete") {
decks.sort(aggregator.compareDecksByIncompleteness);
} else {
decks.sort(aggregator.compareDecks);
}
@@ -357,7 +357,7 @@ class FilterPanel {
sortDiv.appendChild(sortLabel);
const sortSelect = createSelect(
sortDiv,
["By Date", "By Wins", "By Winrate"],
["By Date", "By Wins", "By Winrate", "By Incomplete"],
this.filters.sort,
filter => {
this.filters.sort = filter;

0 comments on commit d5cf164

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