Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion server/scripts/generateMasterfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions server/src/configs/custom-environment-variables.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@
"nests": {
"__name": "API_QUERY_UPDATE_HOURS_NESTS",
"__format": "number"
},
"historicalRarity": {
"__name": "API_QUERY_UPDATE_HOURS_HISTORICAL_RARITY",
"__format": "number"
}
},
"queryOnSessionInit": {
Expand Down
3 changes: 2 additions & 1 deletion server/src/configs/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"pokemon": 0.25,
"quests": 0.5,
"raids": 0.2,
"nests": 1
"nests": 1,
"historicalRarity": 6
},
"queryOnSessionInit": {
"pokemon": false,
Expand Down
2 changes: 1 addition & 1 deletion server/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
84 changes: 41 additions & 43 deletions server/src/services/DbCheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions server/src/services/EventManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
18 changes: 10 additions & 8 deletions src/components/layout/drawer/AreaTile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ export default function AreaTile({
<Typography
variant={name ? 'h6' : 'caption'}
align="center"
style={{
whiteSpace: 'pre-wrap',
}}
style={{ whiteSpace: 'pre-wrap', width: '100%' }}
>
{name || feature.properties.name ? (
Utility.getProperName(name || feature.properties.name)
.split(' ')
.join('\n')
Utility.getProperName(
name ||
feature.properties.formattedName ||
feature.properties.name,
)
) : (
<>&nbsp;</>
)}
Expand All @@ -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
}
/>
</Grid>
</Grid>
Expand Down