Skip to content

Commit

Permalink
Merge pull request #59 from Anna-28/master
Browse files Browse the repository at this point in the history
Show top Pokemon percentages and top 20 instead of top 10
  • Loading branch information
versx authored Jul 9, 2022
2 parents d75f856 + b65305f commit 4362fdb
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 43 deletions.
5 changes: 3 additions & 2 deletions src/configs/config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
5 changes: 3 additions & 2 deletions src/configs/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
10 changes: 6 additions & 4 deletions src/data/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
20 changes: 12 additions & 8 deletions src/routes/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 {
Expand All @@ -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),
Expand All @@ -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)
};
}));
Expand All @@ -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)
};
}));
Expand All @@ -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;
Expand Down
54 changes: 27 additions & 27 deletions src/views/index.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -185,24 +185,24 @@
{{/custom_lifetime_iv}}
</div>

<!-- Start Top 10 -->
{{#custom_pokemon_top10}}
<!-- Start Top 20 -->
{{#custom_pokemon_top}}
<div class="card-body text-center p-1 m-3">
<div class="card-header bg-dark text-light"><b>Top 10 Pokemon</b></div>
<div class="card-header bg-dark text-light"><b>Top {{top_pokemon_count}} Pokemon</b></div>
<ul class="nav nav-tabs justify-content-center" role="tablist">
{{#custom_pokemon_top10_lifetime}}
<li class="nav-item"><a class="nav-link active" id="top10-lifetime-tab" data-toggle="tab" href="#top10-lifetime" role="tab" aria-controls="top10-lifetime" aria-selected="true">Lifetime</a></li>
{{/custom_pokemon_top10_lifetime}}
{{#custom_pokemon_top10_today}}
<li class="nav-item"><a class="nav-link" id="top10-today-tab" data-toggle="tab" href="#top10-today" role="tab" aria-controls="top10-today" aria-selected="false">Today</a></li>
{{/custom_pokemon_top10_today}}
{{#custom_pokemon_top10_iv}}
<li class="nav-item"><a class="nav-link" id="top10-iv-today-tab" data-toggle="tab" href="#top10-iv-today" role="tab" aria-controls="top10-iv-today" aria-selected="false">IV Today</a></li>
{{/custom_pokemon_top10_iv}}
{{#custom_pokemon_top_lifetime}}
<li class="nav-item"><a class="nav-link active" id="top-lifetime-tab" data-toggle="tab" href="#top-lifetime" role="tab" aria-controls="top-lifetime" aria-selected="true">Lifetime</a></li>
{{/custom_pokemon_top_lifetime}}
{{#custom_pokemon_top_today}}
<li class="nav-item"><a class="nav-link" id="top-today-tab" data-toggle="tab" href="#top-today" role="tab" aria-controls="top-today" aria-selected="false">Today</a></li>
{{/custom_pokemon_top_today}}
{{#custom_pokemon_top_iv}}
<li class="nav-item"><a class="nav-link" id="top-iv-today-tab" data-toggle="tab" href="#top-iv-today" role="tab" aria-controls="top-iv-today" aria-selected="false">IV Today</a></li>
{{/custom_pokemon_top_iv}}
</ul>
<div class="tab-content">
{{#custom_pokemon_top10_lifetime}}
<div class="tab-pane fade show active" id="top10-lifetime" role="tabpanel" aria-labelledby="top10-lifetime-tab">
{{#custom_pokemon_top_lifetime}}
<div class="tab-pane fade show active" id="top-lifetime" role="tabpanel" aria-labelledby="top-lifetime-tab">
<div class="card-body">
<div class="container">
<div class="row justify-content-center">
Expand All @@ -211,16 +211,16 @@
<img src="{{image_url}}" style="width: 64px; height: 64px; object-fit: contain;">
<span class="text-nowrap"><b>{{name}}</b></span>
<br>
<span class="text-nowrap">{{shiny}}/{{count}}</span>
<span class="text-nowrap">{{shiny}}/{{count}}<br/>({{percent}})</span>
</div>
{{/lifetime}}
</div>
</div>
</div>
</div>
{{/custom_pokemon_top10_lifetime}}
{{#custom_pokemon_top10_today}}
<div class="tab-pane fade" id="top10-today" role="tabpanel" aria-labelledby="top10-today-tab">
{{/custom_pokemon_top_lifetime}}
{{#custom_pokemon_top_today}}
<div class="tab-pane fade" id="top-today" role="tabpanel" aria-labelledby="top-today-tab">
<div class="card-body">
<div class="container">
<div class="row justify-content-center">
Expand All @@ -229,36 +229,36 @@
<img src="{{image_url}}" style="width: 64px; height: 64px; object-fit: contain;">
<span class="text-nowrap"><b>{{name}}</b></span>
<br>
<span class="text-nowrap">{{shiny}}/{{count}}</span>
<span class="text-nowrap">{{shiny}}/{{count}}<br/>({{percent}})</span>
</div>
{{/today}}
</div>
</div>
</div>
</div>
{{/custom_pokemon_top10_today}}
{{#custom_pokemon_top10_iv}}
<div class="tab-pane fade" id="top10-iv-today" role="tabpanel" aria-labelledby="top10-iv-today-tab">
{{/custom_pokemon_top_today}}
{{#custom_pokemon_top_iv}}
<div class="tab-pane fade" id="top-iv-today" role="tabpanel" aria-labelledby="top-iv-today-tab">
<div class="card-body">
<div class="container">
<div class="row justify-content-center">
{{#top10_100iv_pokemon}}
{{#top_100iv_pokemon}}
<div class="col-md-2">
<img src="{{image_url}}" style="width: 64px; height: 64px; object-fit: contain;">
<span class="text-nowrap"><b>{{name}}</b></span>
<br>
<span class="text-nowrap">{{count}} 100%</span>
</div>
{{/top10_100iv_pokemon}}
{{/top_100iv_pokemon}}
</div>
</div>
</div>
</div>
{{/custom_pokemon_top10_iv}}
{{/custom_pokemon_top_iv}}
</div>
</div>
{{/custom_pokemon_top10}}
<!-- End Top 10 -->
{{/custom_pokemon_top}}
<!-- End Top 20 -->

</div>
{{/custom_pokemon}}
Expand Down

0 comments on commit 4362fdb

Please sign in to comment.