diff options
| author | schneefux <schneefux+commit@schneefux.xyz> | 2018-05-21 13:57:44 +0200 |
|---|---|---|
| committer | schneefux <schneefux+commit@schneefux.xyz> | 2018-12-13 16:59:34 +0100 |
| commit | d354784b68469e440e9e21a76cfec409b17400c6 (patch) | |
| tree | 13717ce6c08730abdb6bcb5eb5bf6489c1f41e07 /src | |
| parent | fdf8388eb527408ddeffe0e09b928dbdec8a4ebc (diff) | |
| download | brokentalents-d354784b68469e440e9e21a76cfec409b17400c6.tar.gz brokentalents-d354784b68469e440e9e21a76cfec409b17400c6.zip | |
ReportService: Use Maps for performance
Diffstat (limited to 'src')
| -rw-r--r-- | src/report-service.js | 94 |
1 files changed, 47 insertions, 47 deletions
diff --git a/src/report-service.js b/src/report-service.js index 9fdbbf3..33bf1f5 100644 --- a/src/report-service.js +++ b/src/report-service.js @@ -8,106 +8,106 @@ export default class ReportService { this.report = require('../data/98aae7f0/report.json') .filter((entry) => entry.Actor != undefined); // bad data from API downtime - this.reports = {}; - this.totalPicks = {}; - this.top10Relevancy = {}; - this.topPicks = {}; - this.topWins = {}; - this.topRareWins = {}; - this.topEpicWins = {}; - this.topLegendaryWins = {}; - this.topLeveledUp = {}; - this.topLeveledDown = {}; - this.topUnpopularWins = {}; + this.reports = new Map(); + this.totalPicks = new Map(); + this.top10Relevancy = new Map(); + this.topPicks = new Map(); + this.topWins = new Map(); + this.topRareWins = new Map(); + this.topEpicWins = new Map(); + this.topLegendaryWins = new Map(); + this.topLeveledUp = new Map(); + this.topLeveledDown = new Map(); + this.topUnpopularWins = new Map(); this.actors = []; this.modes = MODES; for(let mode of MODES) { const relevancy = (entry) => (entry.Count / this.totalPicks[mode]) * (entry.Winner / entry.Count); - this.reports[mode] = this.report.filter((entry) => entry.Mode == mode); - this.totalPicks[mode] = this.report.map((entry) => entry.Count).reduce((agg, cur) => agg + cur, 0); - this.top10Relevancy[mode] = this.reports[mode].sort((entry1, entry2) => relevancy(entry2) - relevancy(entry1)).slice(0, 10); - this.topPicks[mode] = this.reports[mode].sort((entry1, entry2) => entry2.Count - entry1.Count)[0]; - this.topWins[mode] = this.reports[mode] - .filter((entry) => 100 * 6 * entry.Count / this.totalPicks[mode] > POPULAR_THRESHOLD) - .sort((entry1, entry2) => entry2.Winner - entry1.Winner)[0]; - this.topUnpopularWins[mode] = this.reports[mode] - .filter((entry) => 100 * 6 * entry.Count / this.totalPicks[mode] <= POPULAR_THRESHOLD) - .sort((entry1, entry2) => entry2.Winner - entry1.Winner)[0]; - this.topRareWins[mode] = this.reports[mode] - .filter((entry) => maps.getTalentRarity(entry.Talent) == 'Rare' && 100 * 6 * entry.Count / this.totalPicks[mode] > POPULAR_THRESHOLD) - .sort((entry1, entry2) => entry2.Winner - entry1.Winner)[0]; - this.topEpicWins[mode] = this.reports[mode] - .filter((entry) => maps.getTalentRarity(entry.Talent) == 'Epic' && 100 * 6 * entry.Count / this.totalPicks[mode] > POPULAR_THRESHOLD) - .sort((entry1, entry2) => entry2.Winner - entry1.Winner)[0]; - this.topLegendaryWins[mode] = this.reports[mode] - .filter((entry) => maps.getTalentRarity(entry.Talent) == 'Legendary' && 100 * 6 * entry.Count / this.totalPicks[mode] > POPULAR_THRESHOLD) - .sort((entry1, entry2) => entry2.Winner - entry1.Winner)[0]; - this.topLeveledUp[mode] = this.reports[mode].sort((entry1, entry2) => { + this.reports.set(mode, this.report.filter((entry) => entry.Mode == mode)); + this.totalPicks.set(mode, this.report.map((entry) => entry.Count).reduce((agg, cur) => agg + cur, 0)); + this.top10Relevancy.set(mode, this.reports.get(mode).sort((entry1, entry2) => relevancy(entry2) - relevancy(entry1)).slice(0, 10)); + this.topPicks.set(mode, this.reports.get(mode).sort((entry1, entry2) => entry2.Count - entry1.Count)[0]); + this.topWins.set(mode, this.reports.get(mode) + .filter((entry) => 100 * 6 * entry.Count / this.totalPicks.get(mode) > POPULAR_THRESHOLD) + .sort((entry1, entry2) => entry2.Winner - entry1.Winner)[0]); + this.topUnpopularWins.set(mode, this.reports.get(mode) + .filter((entry) => 100 * 6 * entry.Count / this.totalPicks.get(mode) <= POPULAR_THRESHOLD) + .sort((entry1, entry2) => entry2.Winner - entry1.Winner)[0]); + this.topRareWins.set(mode, this.reports.get(mode) + .filter((entry) => maps.getTalentRarity(entry.Talent) == 'Rare' && 100 * 6 * entry.Count / this.totalPicks.get(mode) > POPULAR_THRESHOLD) + .sort((entry1, entry2) => entry2.Winner - entry1.Winner)[0]); + this.topEpicWins.set(mode, this.reports.get(mode) + .filter((entry) => maps.getTalentRarity(entry.Talent) == 'Epic' && 100 * 6 * entry.Count / this.totalPicks.get(mode) > POPULAR_THRESHOLD) + .sort((entry1, entry2) => entry2.Winner - entry1.Winner)[0]); + this.topLegendaryWins.set(mode, this.reports.get(mode) + .filter((entry) => maps.getTalentRarity(entry.Talent) == 'Legendary' && 100 * 6 * entry.Count / this.totalPicks.get(mode) > POPULAR_THRESHOLD) + .sort((entry1, entry2) => entry2.Winner - entry1.Winner)[0]); + this.topLeveledUp.set(mode, this.reports.get(mode).sort((entry1, entry2) => { if (!entry1.Level) return 1; if (!entry2.Level) return -1; return entry1.Level < entry2.Level ? 1 : -1; - })[0]; - this.topLeveledDown[mode] = this.reports[mode].sort((entry1, entry2) => { + })[0]); + this.topLeveledDown.set(mode, this.reports.get(mode).sort((entry1, entry2) => { if (!entry1.Level) return 1; if (!entry2.Level) return -1; return entry1.Level < entry2.Level ? -1 : 1; - })[0]; + })[0]); if (this.actors.length == 0) { - this.actors = [...new Set(this.reports[mode].map((entry) => entry.Actor))]; + this.actors = [...new Set(this.reports.get(mode).map((entry) => entry.Actor))]; } } } getReport(mode) { - return this.reports[mode]; + return this.reports.get(mode); } getTotalPicks(mode) { - return this.totalPicks[mode]; + return this.totalPicks.get(mode); } getTopPick(mode) { - return this.topPicks[mode]; + return this.topPicks.get(mode); } getTop10Picks(mode) { - return this.top10Relevancy[mode]; + return this.top10Relevancy.get(mode); } getHighestLevelAvg(mode) { - return this.topLeveledUp[mode]; + return this.topLeveledUp.get(mode); } getLowestLevelAvg(mode) { - return this.topLeveledDown[mode]; + return this.topLeveledDown.get(mode); } getTopWin(mode) { - return this.topWins[mode]; + return this.topWins.get(mode); } getTopUnpopularWin(mode) { - return this.topUnpopularWins[mode]; + return this.topUnpopularWins.get(mode); } getTopRareWins(mode) { - return this.topRareWins[mode]; + return this.topRareWins.get(mode); } getTopEpicWins(mode) { - return this.topEpicWins[mode]; + return this.topEpicWins.get(mode); } getTopLegendaryWins(mode) { - return this.topLegendaryWins[mode]; + return this.topLegendaryWins.get(mode); } getBestUnpopular(mode) { - return this.topUnpopular[mode]; + return this.topUnpopular.get(mode); } getActors() { |
