diff --git a/server/scripts/generateMasterfile.js b/server/scripts/generateMasterfile.js index 55986e9b7..90089e245 100644 --- a/server/scripts/generateMasterfile.js +++ b/server/scripts/generateMasterfile.js @@ -28,7 +28,8 @@ const generate = async ( pokemon: Object.fromEntries( Object.values(masterfile.pokemon).map((pokemon) => { const { legendary, mythical, ultraBeast, ...rest } = pokemon - const historic = historicRarity.get(pokemon.pokedexId) || 'never' + const historic = + historicRarity.get(pokemon.pokedexId.toString()) || 'never' let rarity = (dbRarity.size diff --git a/server/src/configs/custom-environment-variables.json b/server/src/configs/custom-environment-variables.json index 4a7d06da3..67e0f6917 100644 --- a/server/src/configs/custom-environment-variables.json +++ b/server/src/configs/custom-environment-variables.json @@ -103,6 +103,10 @@ "nests": { "__name": "API_QUERY_UPDATE_HOURS_NESTS", "__format": "number" + }, + "historicalRarity": { + "__name": "API_QUERY_UPDATE_HOURS_HISTORICAL_RARITY", + "__format": "number" } }, "queryOnSessionInit": { diff --git a/server/src/configs/default.json b/server/src/configs/default.json index 17694250d..89c607bcd 100644 --- a/server/src/configs/default.json +++ b/server/src/configs/default.json @@ -34,7 +34,8 @@ "pokemon": 0.25, "quests": 0.5, "raids": 0.2, - "nests": 1 + "nests": 1, + "historicalRarity": 6 }, "queryOnSessionInit": { "pokemon": false, diff --git a/server/src/index.js b/server/src/index.js index 292b12c2c..f6d9850b5 100644 --- a/server/src/index.js +++ b/server/src/index.js @@ -196,7 +196,7 @@ app.use((err, req, res, next) => { Db.determineType().then(async () => { await Promise.all([ - Db.initRarity(), + Db.historicalRarity(), Event.setAvailable('gyms', 'Gym', Db), Event.setAvailable('pokestops', 'Pokestop', Db), Event.setAvailable('pokemon', 'Pokemon', Db), diff --git a/server/src/services/DbCheck.js b/server/src/services/DbCheck.js index acc573f3b..58194754b 100644 --- a/server/src/services/DbCheck.js +++ b/server/src/services/DbCheck.js @@ -118,21 +118,40 @@ module.exports = class DbCheck { ) } - setRarity(id, percent, historical = false) { - if (percent === 0) { - this[historical ? 'historical' : 'rarity'].set(id, 'never') - } else if (percent < this.rarityPercents.ultraRare) { - this[historical ? 'historical' : 'rarity'].set(id, 'ultraRare') - } else if (percent < this.rarityPercents.rare) { - this[historical ? 'historical' : 'rarity'].set(id, 'rare') - } else if (percent < this.rarityPercents.uncommon) { - this[historical ? 'historical' : 'rarity'].set(id, 'uncommon') - } else { - this[historical ? 'historical' : 'rarity'].set(id, 'common') - } + setRarity(results, historical = false) { + const base = {} + const mapKey = historical ? 'historical' : 'rarity' + let total = 0 + results.forEach((result) => { + Object.entries(historical ? result : result.rarity).forEach( + ([key, count]) => { + if (key in base) { + base[key] += count + } else { + base[key] = count + } + total += count + }, + ) + }) + Object.entries(base).forEach(([id, count]) => { + const percent = (count / total) * 100 + if (percent === 0) { + this[mapKey].set(id, 'never') + } else if (percent < this.rarityPercents.ultraRare) { + this[mapKey].set(id, 'ultraRare') + } else if (percent < this.rarityPercents.rare) { + this[mapKey].set(id, 'rare') + } else if (percent < this.rarityPercents.uncommon) { + this[mapKey].set(id, 'uncommon') + } else { + this[mapKey].set(id, 'common') + } + }) } - async initRarity() { + async historicalRarity() { + console.log('[DB] Setting historical rarity stats') const results = await Promise.all( this.models.Pokemon.map(async (source) => source.isMad @@ -143,21 +162,14 @@ module.exports = class DbCheck { .groupBy('pokemon_id'), ), ) - const consolidated = {} - let total = 0 - results.forEach((result) => { - result.forEach((row) => { - if (consolidated[row.pokemon_id]) { - consolidated[row.pokemon_id] += +row.total - } else { - consolidated[row.pokemon_id] = +row.total - } - total += +row.total - }) - }) - Object.entries(consolidated).forEach(([id, count]) => { - this.setRarity(+id, (count / total) * 100, true) - }) + this.setRarity( + results.map((result) => + Object.fromEntries( + result.map((pkmn) => [`${pkmn.pokemon_id}`, +pkmn.total]), + ), + ), + true, + ) } bindConnections(models) { @@ -292,21 +304,7 @@ module.exports = class DbCheck { ) } if (model === 'Pokemon') { - const base = {} - let total = 0 - results.forEach((result) => { - Object.entries(result.rarity).forEach(([key, count]) => { - if (key in base) { - base[key] += count - } else { - base[key] = count - } - total += count - }) - }) - Object.entries(base).forEach(([id, count]) => { - this.setRarity(id, (count / total) * 100) - }) + this.setRarity(results, false) } if (results.length === 1) return results[0].available if (results.length > 1) { diff --git a/server/src/services/EventManager.js b/server/src/services/EventManager.js index 60233fe00..56bbe4be3 100644 --- a/server/src/services/EventManager.js +++ b/server/src/services/EventManager.js @@ -53,6 +53,9 @@ module.exports = class EventManager { setInterval(async () => { await this.getInvasions() }, 1000 * 60 * 60 * (config.map.invasionCacheHrs || 1)) + setInterval(async () => { + await Db.historicalRarity() + }, 1000 * 60 * 60 * (config.api.queryUpdateHours.historicalRarity || 6)) setInterval(async () => { await this.getMasterfile(Db.historical, Db.rarity) }, 1000 * 60 * 60 * (config.map.masterfileCacheHrs || 6)) diff --git a/src/components/layout/drawer/AreaTile.jsx b/src/components/layout/drawer/AreaTile.jsx index 168154b66..f54e0928f 100644 --- a/src/components/layout/drawer/AreaTile.jsx +++ b/src/components/layout/drawer/AreaTile.jsx @@ -61,14 +61,14 @@ export default function AreaTile({ {name || feature.properties.name ? ( - Utility.getProperName(name || feature.properties.name) - .split(' ') - .join('\n') + Utility.getProperName( + name || + feature.properties.formattedName || + feature.properties.name, + ) ) : ( <>  )} @@ -94,13 +94,15 @@ export default function AreaTile({ } style={{ color: - !childAreas.length || hasManual + !childAreas.length || hasManual || !feature.properties.name ? feature?.properties?.fillColor || feature?.properties?.fill || '#212121' : 'none', }} - disabled={!childAreas.length || hasManual} + disabled={ + !childAreas.length || hasManual || !feature.properties.name + } />