diff --git a/src/configs/config.example.json b/src/configs/config.example.json index 2b356f9..16550e8 100644 --- a/src/configs/config.example.json +++ b/src/configs/config.example.json @@ -62,11 +62,12 @@ "enabled": true, "active": true, "lifetime": true, - "top10": { + "top": { "enabled": true, "lifetime": true, "today": true, - "iv": true + "iv": true, + "limit": 20 } }, "gyms": { diff --git a/src/configs/default.json b/src/configs/default.json index b590276..98702bb 100644 --- a/src/configs/default.json +++ b/src/configs/default.json @@ -57,11 +57,12 @@ "enabled": true, "active": true, "lifetime": true, - "top10": { + "top": { "enabled": true, "lifetime": true, "today": true, - "iv": true + "iv": true, + "limit": 20 } }, "gyms": { diff --git a/src/data/map.js b/src/data/map.js index b291f40..165c3b9 100644 --- a/src/data/map.js +++ b/src/data/map.js @@ -163,7 +163,7 @@ async function getPokemonOverviewStats() { return results; } -async function getTopPokemonIVStats(iv = 100, limit = 10) { +async function getTopPokemonIVStats(iv = 100, limit = config.pages.home.custom.pokemon.top.limit || 20) { const sql = ` SELECT pokemon_id, iv, COUNT(iv) AS count FROM pokemon @@ -177,11 +177,12 @@ async function getTopPokemonIVStats(iv = 100, limit = 10) { return results; } -async function getTopPokemonStats(lifetime = false, limit = 10) { +async function getTopPokemonStats(lifetime = false, limit = config.pages.home.custom.pokemon.top.limit || 20) { let sql = ''; if (lifetime) { sql = ` - SELECT iv.pokemon_id, SUM(shiny.count) AS shiny, SUM(iv.count) AS count + SELECT iv.pokemon_id, SUM(shiny.count) AS shiny, SUM(iv.count) AS count, + (SELECT SUM(count) FROM pokemon_iv_stats) AS total FROM pokemon_iv_stats iv LEFT JOIN pokemon_shiny_stats shiny ON iv.date = shiny.date AND iv.pokemon_id = shiny.pokemon_id @@ -191,7 +192,8 @@ async function getTopPokemonStats(lifetime = false, limit = 10) { `; } else { sql = ` - SELECT iv.pokemon_id, SUM(shiny.count) AS shiny, SUM(iv.count) AS count + SELECT iv.pokemon_id, SUM(shiny.count) AS shiny, SUM(iv.count) AS count, + SUM(iv.count) OVER() AS total FROM pokemon_iv_stats iv LEFT JOIN pokemon_shiny_stats shiny ON iv.date = shiny.date AND iv.pokemon_id = shiny.pokemon_id diff --git a/src/routes/ui.js b/src/routes/ui.js index c10efa4..358e5bc 100644 --- a/src/routes/ui.js +++ b/src/routes/ui.js @@ -15,6 +15,7 @@ const svc = new GeofenceService.GeofenceService(); router.get(['/', '/index'], async function(req, res) { const data = defaultData; + const topLimit = config.pages.home.custom.pokemon.top.limit || 20; const newPokestops = await map.getNewPokestops(); const newGyms = await map.getNewGyms(); const topGymDefenders = await map.getGymDefenders(10); @@ -24,9 +25,9 @@ router.get(['/', '/index'], async function(req, res) { x.slots_available = x.available_slots === 0 ? 'Full' : x.available_slots + '/6'; x.raid_battle_timestamp = utils.toHHMMSS(x.raid_battle_timestamp * 1000); }); - const top10_100IVStats = await map.getTopPokemonIVStats(100, 10); - const lifetime = await map.getTopPokemonStats(true, 10); - const today = await map.getTopPokemonStats(false, 10); + const top_100IVStats = await map.getTopPokemonIVStats(100, topLimit); + const lifetime = await map.getTopPokemonStats(true, topLimit); + const today = await map.getTopPokemonStats(false, topLimit); const defenders = await Promise.all(topGymDefenders.map(async x => { return { @@ -36,7 +37,7 @@ router.get(['/', '/index'], async function(req, res) { image_url: await Localizer.instance.getPokemonIcon(x.guarding_pokemon_id) }; })); - data.top10_100iv_pokemon = await Promise.all(top10_100IVStats.map(async x => { + data.top_100iv_pokemon = await Promise.all(top_100IVStats.map(async x => { return { pokemon_id: x.pokemon_id, name: Localizer.instance.getPokemonName(x.pokemon_id), @@ -51,6 +52,7 @@ router.get(['/', '/index'], async function(req, res) { name: Localizer.instance.getPokemonName(x.pokemon_id), shiny: (x.shiny || 0).toLocaleString(), count: (x.count || 0).toLocaleString(), + percent: (x.count/x.total || 0).toLocaleString(undefined, {style: 'percent', maximumFractionDigits: 2}), image_url: await Localizer.instance.getPokemonIcon(x.pokemon_id) }; })); @@ -60,6 +62,7 @@ router.get(['/', '/index'], async function(req, res) { name: Localizer.instance.getPokemonName(x.pokemon_id), shiny: (x.shiny || 0).toLocaleString(), count: (x.count || 0).toLocaleString(), + percent: (x.count/x.total || 0).toLocaleString(undefined, {style: 'percent', maximumFractionDigits: 2}), image_url: await Localizer.instance.getPokemonIcon(x.pokemon_id) }; })); @@ -73,10 +76,11 @@ router.get(['/', '/index'], async function(req, res) { data.custom_active_iv = config.pages.home.custom.pokemon.active; data.custom_lifetime_iv = config.pages.home.custom.pokemon.lifetime; - data.custom_pokemon_top10 = config.pages.home.custom.pokemon.top10.enabled; - data.custom_pokemon_top10_lifetime = config.pages.home.custom.pokemon.top10.lifetime; - data.custom_pokemon_top10_today = config.pages.home.custom.pokemon.top10.today; - data.custom_pokemon_top10_iv = config.pages.home.custom.pokemon.top10.iv; + data.custom_pokemon_top = config.pages.home.custom.pokemon.top.enabled; + data.custom_pokemon_top_lifetime = config.pages.home.custom.pokemon.top.lifetime; + data.custom_pokemon_top_today = config.pages.home.custom.pokemon.top.today; + data.custom_pokemon_top_iv = config.pages.home.custom.pokemon.top.iv; + data.top_pokemon_count = topLimit; data.custom_gyms = config.pages.home.custom.gyms.enabled; data.custom_gyms_new = config.pages.home.custom.gyms.newGyms; diff --git a/src/views/index.mustache b/src/views/index.mustache index 2a1cc8d..8edfb9e 100644 --- a/src/views/index.mustache +++ b/src/views/index.mustache @@ -185,24 +185,24 @@ {{/custom_lifetime_iv}} - - {{#custom_pokemon_top10}} + + {{#custom_pokemon_top}}
-
Top 10 Pokemon
+
Top {{top_pokemon_count}} Pokemon
- {{#custom_pokemon_top10_lifetime}} -
+ {{#custom_pokemon_top_lifetime}} +
@@ -211,16 +211,16 @@ {{name}}
- {{shiny}}/{{count}} + {{shiny}}/{{count}}
({{percent}})
{{/lifetime}}
- {{/custom_pokemon_top10_lifetime}} - {{#custom_pokemon_top10_today}} -
+ {{/custom_pokemon_top_lifetime}} + {{#custom_pokemon_top_today}} +
@@ -229,36 +229,36 @@ {{name}}
- {{shiny}}/{{count}} + {{shiny}}/{{count}}
({{percent}})
{{/today}}
- {{/custom_pokemon_top10_today}} - {{#custom_pokemon_top10_iv}} -
+ {{/custom_pokemon_top_today}} + {{#custom_pokemon_top_iv}} +
- {{#top10_100iv_pokemon}} + {{#top_100iv_pokemon}}
{{name}}
{{count}} 100%
- {{/top10_100iv_pokemon}} + {{/top_100iv_pokemon}}
- {{/custom_pokemon_top10_iv}} + {{/custom_pokemon_top_iv}}
- {{/custom_pokemon_top10}} - + {{/custom_pokemon_top}} +
{{/custom_pokemon}}