From 4f56dd213c989e9cf1431ad13314b419deadf8a8 Mon Sep 17 00:00:00 2001 From: Jeff Colombo Date: Mon, 7 Jan 2019 23:03:01 -0500 Subject: [PATCH] fix grades --- generatePokemonData.ts | 27 ++++++++++++++++----------- package.json | 1 + 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/generatePokemonData.ts b/generatePokemonData.ts index 45ad6b2..68dc8f1 100644 --- a/generatePokemonData.ts +++ b/generatePokemonData.ts @@ -77,7 +77,6 @@ Pokemon.forEach((mon) => { metaGrade: Grade.F, }; pokemonWithIvs.total = pokemonWithIvs.hp + pokemonWithIvs.atk + pokemonWithIvs.def; - stats.pvp[league].push(pokemonWithIvs); const combinedStats = maxLeagueCp + pokemonWithIvs.total; combinedStatsDistribution[league][combinedStats] = combinedStatsDistribution[league][combinedStats] || []; @@ -90,17 +89,12 @@ Pokemon.forEach((mon) => { // process the pokemon stats for league-worthiness Object.keys(stats.pvp).forEach((key) => { const league = key as League; - stats.pvp[league].sort((a, b) => { - if (a.total === b.total) { - return a.total > b.total ? 0 : 1; - } - return a.level > b.level ? 0 : 1; - }); const orderedCombinedStats = Object.keys(combinedStatsDistribution[league]).map(cpTotal => parseInt(cpTotal)).sort(); - const offset = orderedCombinedStats[orderedCombinedStats.length - 1]; - const max = orderedCombinedStats[1] - offset; // index 0 is always `Grade.S` - for (let index = orderedCombinedStats.length - 1; index >= 0; index--) { + const len = orderedCombinedStats.length - 1; + const offset = orderedCombinedStats[1]; + const max = orderedCombinedStats[len] - offset; // index 0 is always `Grade.S` + for (let index = len; index >= 0; index--) { const combinedStats = orderedCombinedStats[index]; const percent = (combinedStats - offset) / max; @@ -111,7 +105,7 @@ Pokemon.forEach((mon) => { } combinedStatsDistribution[league][combinedStats].forEach((pokemonStats) => { - if (index === 0) { + if (index === len) { pokemonStats.speciesGrade = Grade.S; } else { if (percent >= 0.9) { @@ -124,7 +118,18 @@ Pokemon.forEach((mon) => { pokemonStats.speciesGrade = Grade.D; } } + stats.pvp[league].push(pokemonStats); }); + combinedStatsDistribution[league][combinedStats].sort((a, b) => { + if (a.total !== b.total) { + return a.total < b.total ? -1 : 1; + } + if (a.level !== b.level) { + return a.level < b.level ? -1 : 1; + } + return 0; + }); + stats.pvp[league].push(...combinedStatsDistribution[league][combinedStats]); } }); diff --git a/package.json b/package.json index bdae905..4549a37 100644 --- a/package.json +++ b/package.json @@ -1,4 +1,5 @@ { + "license": "UNLICENSED", "scripts": { "#": "DO NOT ADD '-d' OPTION TO WEBPACK OR ALL SOURCEMAPS WILL BREAK: https://webpack.js.org/api/cli/#shortcuts", "package": "yarn build -- --config webpack.config.prod.js --bail --display-used-exports -p",