From 4861ab4aa7fd69cfcc7d0d9dbc9a2087adda2eba Mon Sep 17 00:00:00 2001 From: TurtIeSocks <58572875+TurtIeSocks@users.noreply.github.com> Date: Sun, 3 Jul 2022 15:03:23 -0400 Subject: [PATCH 1/4] Dynamic Rarity - Read historical spawn data from RDM, needs testing to know to skip MAD - Read current DB when querying for available to determine current rarity - Fix release action --- .github/workflows/release.yml | 5 ++ public/base-locales/en.json | 5 +- server/scripts/generateMasterfile.js | 80 ++++++++++++------- server/src/configs/default.json | 8 +- server/src/data/defaultRarity.json | 7 +- server/src/index.js | 24 +++--- server/src/models/Pokemon.js | 19 ++++- server/src/services/DbCheck.js | 64 ++++++++++++++- server/src/services/EventManager.js | 6 +- server/src/services/initialization.js | 1 + server/src/services/ui/advMenus.js | 54 ++++++++----- .../layout/dialogs/filters/Options.jsx | 2 +- .../dialogs/filters/OptionsContainer.jsx | 4 +- src/hooks/useFilter.js | 21 ++++- src/services/filtering/genPokemon.js | 3 +- 15 files changed, 225 insertions(+), 78 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index fb5a2af6d..207898138 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -21,3 +21,8 @@ jobs: - name: Sentry Build run: yarn release + env: + SENTRY_AUTH_TOKEN: ${{secrets.SENTRY_AUTH_TOKEN}} + SENTRY_DSN: ${{secrets.SENTRY_DSN}} + SENTRY_ORG: ${{secrets.SENTRY_ORG}} + SENTRY_PROJECT: ${{secrets.SENTRY_PROJECT}} diff --git a/public/base-locales/en.json b/public/base-locales/en.json index cd3acd484..1aab20329 100644 --- a/public/base-locales/en.json +++ b/public/base-locales/en.json @@ -37,7 +37,7 @@ "generations": "Generations", "types": "Types", "forms": "Forms", - "rarity": "Rarity", + "rarity": "Current Rarity", "others": "Others", "categories": "Categories", "rank": "Rank", @@ -546,5 +546,6 @@ "poi_color": "POI Color", "quest_condition": "Quest Condition", "always_show_labels": "Always Show Labels", - "scan_areas_options": "Scan Areas Options" + "scan_areas_options": "Scan Areas Options", + "historic_rarity": "Historic Rarity" } diff --git a/server/scripts/generateMasterfile.js b/server/scripts/generateMasterfile.js index ed57b315b..55986e9b7 100644 --- a/server/scripts/generateMasterfile.js +++ b/server/scripts/generateMasterfile.js @@ -1,51 +1,72 @@ -/* eslint-disable no-console */ -/* eslint-disable no-restricted-syntax */ const fs = require('fs') -const path = require('path') -const { rarity } = require('../src/services/config') +const { resolve } = require('path') +const { rarity: customRarity } = require('../src/services/config') const fetchJson = require('../src/services/api/fetchJson') const defaultRarity = require('../src/data/defaultRarity.json') -const getRarityLevel = (id, pkmn) => { - let pkmnRarity - for (const [tier, pokemon] of Object.entries(defaultRarity)) { - if (rarity?.[tier]?.length) { - if (rarity[tier].includes(parseInt(id))) { - pkmnRarity = tier - } - } else if (pokemon.includes(parseInt(id))) { - pkmnRarity = tier - } +const rarityObj = {} +Object.entries(defaultRarity).forEach(([tier, pokemon]) => { + if (customRarity?.[tier]?.length) { + customRarity[tier].forEach((mon) => (rarityObj[mon] = tier)) + } else { + pokemon.forEach((mon) => (rarityObj[mon] = tier)) } - if (pkmn.legendary) pkmnRarity = 'legendary' - if (pkmn.mythical) pkmnRarity = 'mythical' - if (pkmn.ultraBeast) pkmnRarity = 'ultraBeast' - return pkmnRarity -} +}) -const generate = async (save) => { +const generate = async ( + save = false, + historicRarity = new Map(), + dbRarity = new Map(), +) => { try { const masterfile = await fetchJson( 'https://raw.githubusercontent.com/WatWowMap/Masterfile-Generator/master/master-latest-react-map.json', ) - Object.values(masterfile.pokemon).forEach((pokemon) => { - pokemon.rarity = getRarityLevel(pokemon.pokedexId, pokemon) - pokemon.types = pokemon.types || [] - delete pokemon.mythical - delete pokemon.legendary - }) + const newMf = { + ...masterfile, + pokemon: Object.fromEntries( + Object.values(masterfile.pokemon).map((pokemon) => { + const { legendary, mythical, ultraBeast, ...rest } = pokemon + const historic = historicRarity.get(pokemon.pokedexId) || 'never' + + let rarity = + (dbRarity.size + ? dbRarity.get(`${pokemon.pokedexId}-${pokemon.defaultFormId}`) + : rarityObj[pokemon.pokedexId]) || 'never' + if (legendary) rarity = 'legendary' + if (mythical) rarity = 'mythical' + if (ultraBeast) rarity = 'ultraBeast' + if (rarityObj[pokemon.pokedexId] === 'regional') rarity = 'regional' + + const forms = Object.fromEntries( + Object.entries(pokemon.forms || {}).map(([formId, form]) => [ + formId, + { + ...form, + rarity: + +formId === pokemon.defaultFormId + ? rarity + : dbRarity.get(`${pokemon.pokedexId}-${formId}`) || 'never', + }, + ]), + ) + return [pokemon.pokedexId, { ...rest, forms, rarity, historic }] + }), + ), + } if (save) { fs.writeFileSync( - path.resolve(`${__dirname}/../src/data/masterfile.json`), - JSON.stringify(masterfile, null, 2), + resolve(`${__dirname}/../src/data/masterfile.json`), + JSON.stringify(newMf, null, 2), 'utf8', () => {}, ) } - return masterfile + return newMf } catch (e) { + // eslint-disable-next-line no-console console.warn('[WARN] Unable to generate new masterfile, using existing.', e) } } @@ -53,5 +74,6 @@ const generate = async (save) => { module.exports.generate = generate if (require.main === module) { + // eslint-disable-next-line no-console generate(true).then(() => console.log('Masterfile generated')) } diff --git a/server/src/configs/default.json b/server/src/configs/default.json index 718171d47..3dc3c35ef 100644 --- a/server/src/configs/default.json +++ b/server/src/configs/default.json @@ -699,12 +699,18 @@ } }, "rarity": { + "percents": { + "uncommon": 0.25, + "rare": 0.1, + "ultraRare": 0.01 + }, "common": [], "uncommon": [], "rare": [], "ultraRare": [], "regional": [], - "event": [] + "event": [], + "never": [] }, "manualAreas": [] } \ No newline at end of file diff --git a/server/src/data/defaultRarity.json b/server/src/data/defaultRarity.json index 5bd194937..9fa61caf1 100644 --- a/server/src/data/defaultRarity.json +++ b/server/src/data/defaultRarity.json @@ -6,7 +6,7 @@ 2,5,8,11,14,17,20,22,24,26,30,33,36,38,40,42,44,47,49,51,53,55,57,59,61,64,67,70,73,75,78,80,82,85,87,89,91,93,97,99,101,103,105,110,112,117,119,121,124,125,126,127,139,141,153,156,159,162,164,166,168,171,178,180,184,185,188,195,202,203,205,206,210,211,213,217,219,221,224,226,227,229,234,253,256,259,262,264,266,268,271,274,277,279,281,284,286,288,294,297,301,302,305,308,310,317,319,323,326,329,332,340,342,344,346,348,354,356,362,364,388,391,394,397,400,402,419,426,428,432,435,437,450,452,454,457,460,496,499,502,505,507,510,520,522,524,528,536,541,544,547,549,552,558,563,569,573,578,581,583,586,587,591,595,603,606,614,615,620,651,654,657,660,662,668 ], "rare": [ - 3,6,9,12,15,18,28,31,34,45,62,65,68,71,76,94,106,107,108,113,114,130,131,132,134135,136,137,142,143,144,154,157,160,169,176,181,189,232,235,237,241,242,254,257,260,267,269,272,275,282,289,295,306,330,358,365,389,392,395,398,408,409,410,411,413,414,497,500,503,508,518,521,523,525,526,530,531,537,542,545,553,554,555,564,565,566,567,571,574,575,576,579,584,589,593,594,596,597,598,604,617,618,621,622,623,625,630,636,637,652,655,658 + 3,6,9,12,15,18,28,31,34,45,62,65,68,71,76,94,106,107,108,113,114,130,131,132,134,135,136,137,142,143,144,154,157,160,169,176,181,189,232,235,237,241,242,254,257,260,267,269,272,275,282,289,295,306,330,358,365,389,392,395,398,408,409,410,411,413,414,497,500,503,508,518,521,523,525,526,530,531,537,542,545,553,554,555,564,565,566,567,571,574,575,576,579,584,589,593,594,596,597,598,604,617,618,621,622,623,625,630,636,637,652,655,658 ], "ultraRare": [ 147,148,149,201,246,247,248,371,372,373,374,375,376,443,444,445,607,608,609,610,611,612,633,634,635,714,715 @@ -14,7 +14,8 @@ "regional": [ 83,115,122,128,214,222,313,314,324,335,336,337,338,357,369,417,422,423,439,441,455,480,481,482,511,512,513,514,515,516,538,539,550,556,561,626,631,632,707 ], - "event": [ + "never": [ 172,173,174,175,182,186,192,196,197,199,208,212,225,230,233,236,238,239,240,290,291,292,298,303,321,327,334,350,352,359,360,367,368,403,404,405,406,407,416,424,429,430,433,438,439,440,442,446,447,448,458,461,462,463,464,465,466,467,468,469,470,471,472,473,474,475,476,477,478,479,532,533,534,559,560,599,600,601,627,628,677,678 - ] + ], + "event": [] } diff --git a/server/src/index.js b/server/src/index.js index b00b839aa..292b12c2c 100644 --- a/server/src/index.js +++ b/server/src/index.js @@ -196,20 +196,24 @@ app.use((err, req, res, next) => { Db.determineType().then(async () => { await Promise.all([ - Event.getUicons(config.icons.styles), - Event.getMasterfile(), - Event.getInvasions(), - Event.getWebhooks(config), + Db.initRarity(), Event.setAvailable('gyms', 'Gym', Db), Event.setAvailable('pokestops', 'Pokestop', Db), Event.setAvailable('pokemon', 'Pokemon', Db), Event.setAvailable('nests', 'Nest', Db), - ]).then(() => { - Event.addAvailable() - app.listen(config.port, config.interface, () => { - console.log( - `[INIT] Server is now listening at http://${config.interface}:${config.port}`, - ) + ]).then(async () => { + await Promise.all([ + Event.getUicons(config.icons.styles), + Event.getMasterfile(Db.historical, Db.rarity), + Event.getInvasions(), + Event.getWebhooks(config), + ]).then(() => { + Event.addAvailable() + app.listen(config.port, config.interface, () => { + console.log( + `[INIT] Server is now listening at http://${config.interface}:${config.port}`, + ) + }) }) }) }) diff --git a/server/src/models/Pokemon.js b/server/src/models/Pokemon.js index dd476b90f..7e520467d 100644 --- a/server/src/models/Pokemon.js +++ b/server/src/models/Pokemon.js @@ -416,8 +416,8 @@ module.exports = class Pokemon extends Model { static async getAvailable({ isMad }) { const ts = Math.floor(new Date().getTime() / 1000) - const results = await this.query() - .select('pokemon_id', 'form') + const availableQuery = this.query() + .select(['pokemon_id', 'form']) .where( isMad ? 'disappear_time' : 'expire_timestamp', '>=', @@ -425,8 +425,21 @@ module.exports = class Pokemon extends Model { ) .groupBy('pokemon_id', 'form') .orderBy('pokemon_id', 'form') + const rarityQuery = this.query() + .select(['pokemon_id AS id', 'form as formId']) + .count('pokemon_id AS count') + .groupBy('pokemon_id', 'form') + .where( + isMad ? 'disappear_time' : 'expire_timestamp', + '>=', + isMad ? this.knex().fn.now() : ts, + ) + + const [available, rarity] = await Promise.all([availableQuery, rarityQuery]) + return { - available: results.map((pkmn) => `${pkmn.pokemon_id}-${pkmn.form}`), + available: available.map((pkmn) => `${pkmn.pokemon_id}-${pkmn.form}`), + rarity: Object.fromEntries(rarity.map((pkmn) => [`${pkmn.id}-${pkmn.formId}`, pkmn.count])), } } diff --git a/server/src/services/DbCheck.js b/server/src/services/DbCheck.js index ff8b66eaa..964243114 100644 --- a/server/src/services/DbCheck.js +++ b/server/src/services/DbCheck.js @@ -4,12 +4,15 @@ const { raw } = require('objection') const extend = require('extend') module.exports = class DbCheck { - constructor(validModels, dbSettings, queryDebug, apiSettings, distanceUnit) { + constructor(validModels, dbSettings, queryDebug, apiSettings, distanceUnit, rarityPercents) { this.validModels = validModels.flatMap((s) => s.useFor) this.singleModels = ['User', 'Badge', 'Session'] this.searchLimit = apiSettings.searchLimit + this.rarityPercents = rarityPercents this.models = {} this.questConditions = {} + this.rarity = new Map() + this.historical = new Map() this.connections = dbSettings.schemas .filter((s) => s.useFor.length) .map((schema, i) => { @@ -108,6 +111,48 @@ 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') + } + } + + async initRarity() { + const results = await Promise.all( + this.models.Pokemon.map(async (source) => + source.isMad + ? () => [] + : source.SubModel.query() + .select('pokemon_id', raw('SUM(count) as total')) + .from('pokemon_stats') + .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) + }) + } + bindConnections(models) { try { Object.entries(this.models).forEach(([model, sources]) => { @@ -239,6 +284,23 @@ 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) + }) + } if (results.length === 1) return results[0].available if (results.length > 1) { const returnSet = new Set() diff --git a/server/src/services/EventManager.js b/server/src/services/EventManager.js index 106ba476e..60233fe00 100644 --- a/server/src/services/EventManager.js +++ b/server/src/services/EventManager.js @@ -54,7 +54,7 @@ module.exports = class EventManager { await this.getInvasions() }, 1000 * 60 * 60 * (config.map.invasionCacheHrs || 1)) setInterval(async () => { - await this.getMasterfile() + await this.getMasterfile(Db.historical, Db.rarity) }, 1000 * 60 * 60 * (config.map.masterfileCacheHrs || 6)) if (Pvp) { setInterval(async () => { @@ -154,10 +154,10 @@ module.exports = class EventManager { } } - async getMasterfile() { + async getMasterfile(historical, dbRarity) { console.log('[EVENT] Fetching Latest Masterfile') try { - const newMf = await generate() + const newMf = await generate(false, historical, dbRarity) this.masterfile = newMf ?? this.masterfile this.addAvailable() } catch (e) { diff --git a/server/src/services/initialization.js b/server/src/services/initialization.js index 382101509..0dd56cb3e 100644 --- a/server/src/services/initialization.js +++ b/server/src/services/initialization.js @@ -20,6 +20,7 @@ const Db = new DbCheck( config.devOptions.queryDebug, config.api, config.map.distanceUnit, + config.rarity.percents ) const Pvp = config.api.pvp.reactMapHandlesPvp ? new PvpWrapper(config.api.pvp) diff --git a/server/src/services/ui/advMenus.js b/server/src/services/ui/advMenus.js index 798835950..f106afc64 100644 --- a/server/src/services/ui/advMenus.js +++ b/server/src/services/ui/advMenus.js @@ -21,30 +21,46 @@ if (map.enableQuestRewardTypeFilters) { categories.pokestops.push('general') } -const pokemonFilters = { - generations: [ - ...new Set( - Object.values(Event.masterfile.pokemon).map( - (val) => `generation_${val.genId}`, - ), - ), - ].filter((val) => val !== undefined), - types: Object.keys(Event.masterfile.types) - .map((key) => `poke_type_${key}`) - .filter((val) => val !== 'poke_type_0'), - rarity: [ - ...new Set( - Object.values(Event.masterfile.pokemon).map((val) => val.rarity), - ), - ].filter((val) => val !== undefined), - forms: ['normalForms', 'altForms', 'Alola', 'Galarian'], - others: ['reverse', 'selected', 'unselected', 'onlyAvailable'], -} +const baseRarity = [ + 'common', + 'uncommon', + 'rare', + 'ultraRare', + 'regional', + 'ultraBeast', + 'legendary', + 'mythical', + 'never', +] module.exports = function buildMenus() { const menuFilters = {} const returnedItems = {} + const rarityTiers = new Set( + Object.values(Event.masterfile.pokemon).map((val) => val.rarity), + ) + const historicalTiers = new Set( + Object.values(Event.masterfile.pokemon).map((val) => val.historic), + ) + + const pokemonFilters = { + generations: [ + ...new Set( + Object.values(Event.masterfile.pokemon).map( + (val) => `generation_${val.genId}`, + ), + ), + ].filter((val) => val !== undefined), + types: Object.keys(Event.masterfile.types) + .map((key) => `poke_type_${key}`) + .filter((val) => val !== 'poke_type_0'), + rarity: baseRarity.filter((tier) => rarityTiers.has(tier)), + historicRarity: baseRarity.filter((tier) => historicalTiers.has(tier)), + forms: ['normalForms', 'altForms', 'Alola', 'Galarian'], + others: ['reverse', 'selected', 'unselected', 'onlyAvailable'], + } + Object.entries(pokemonFilters).forEach(([key, items]) => { menuFilters[key] = Object.fromEntries(items.map((item) => [item, false])) }) diff --git a/src/components/layout/dialogs/filters/Options.jsx b/src/components/layout/dialogs/filters/Options.jsx index 49d482c8a..d6aa1b836 100644 --- a/src/components/layout/dialogs/filters/Options.jsx +++ b/src/components/layout/dialogs/filters/Options.jsx @@ -37,7 +37,7 @@ export default function FilterOptions({ {Object.keys(options).map((key) => ( { if (bool && options[filter] !== undefined) { - applied.push(filter) + applied.push(`${cat}-${filter}`) } }, ) @@ -110,7 +110,7 @@ export default function OptionsContainer({ {applied.map((x) => ( s.menuFilters, [])) const { - filters: { generations, types, rarity, forms, others, categories }, + filters: { + generations, + types, + rarity, + historicRarity, + forms, + others, + categories, + }, } = menus[category] const tempAdvFilter = {} const filteredArr = [] @@ -41,9 +49,11 @@ export default function useFilter( menus[category].filters[subCategory], ).every((val) => val === false) }) - tempAdvFilter.all = Object.values(tempAdvFilter).every((val) => val === true) - if ((others.selected && others.unselected) || tempAdvFilter.all) { + if ( + (others.selected && others.unselected) || + Object.values(tempAdvFilter).every((val) => val === true) + ) { switchKey = 'all' } else if (others.selected) { switchKey = 'selected' @@ -138,6 +148,8 @@ export default function useFilter( ((tempAdvFilter.generations || generations[item.genId]) && (tempAdvFilter.types || typeResolver(item.formTypes)) && (tempAdvFilter.rarity || rarity[item.rarity]) && + (tempAdvFilter.historicRarity || + historicRarity[item.historic]) && (tempAdvFilter.categories || categories[subCategory]) && (tempAdvFilter.forms || forms[item.formName] || @@ -167,6 +179,8 @@ export default function useFilter( ((tempAdvFilter.generations || generations[item.genId]) && (tempAdvFilter.types || typeResolver(item.formTypes)) && (tempAdvFilter.rarity || rarity[item.rarity]) && + (tempAdvFilter.historicRarity || + historicRarity[item.historic]) && (tempAdvFilter.categories || categories[subCategory]) && (tempAdvFilter.forms || forms[item.formName] || @@ -211,6 +225,7 @@ export default function useFilter( generations[item.genId] || item.formTypes.some((x) => types[x]) || rarity[item.rarity] || + historicRarity[item.historic] || forms[item.name] || (forms.altForms && item.formId != item.defaultFormId) || (forms.normalForms && item.formId === item.defaultFormId) || diff --git a/src/services/filtering/genPokemon.js b/src/services/filtering/genPokemon.js index 4dfbb77f3..b091fdc5c 100644 --- a/src/services/filtering/genPokemon.js +++ b/src/services/filtering/genPokemon.js @@ -34,7 +34,8 @@ export default function genPokemon(t, pokemon, categories) { pokeName, formName, formTypes, - rarity: pkmn.rarity, + rarity: form.rarity || pkmn.rarity, + historic: pkmn.historic, genId: `generation_${pkmn.genId}`, perms: ['pokemon', 'raids', 'quests', 'nests'], family: pkmn.family, From fdb77dd909265591c487a17b86145326a7601680 Mon Sep 17 00:00:00 2001 From: TurtIeSocks Date: Sun, 3 Jul 2022 19:03:46 +0000 Subject: [PATCH 2/4] Synced docker env vars with latest config Files changed:\nM server/src/configs/custom-environment-variables.json --- .../configs/custom-environment-variables.json | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/server/src/configs/custom-environment-variables.json b/server/src/configs/custom-environment-variables.json index 0efb11b23..c65ed769f 100644 --- a/server/src/configs/custom-environment-variables.json +++ b/server/src/configs/custom-environment-variables.json @@ -1407,6 +1407,20 @@ } }, "rarity": { + "percents": { + "uncommon": { + "__name": "RARITY_PERCENTS_UNCOMMON", + "__format": "number" + }, + "rare": { + "__name": "RARITY_PERCENTS_RARE", + "__format": "number" + }, + "ultraRare": { + "__name": "RARITY_PERCENTS_ULTRA_RARE", + "__format": "number" + } + }, "common": { "__name": "RARITY_COMMON", "__format": "json" @@ -1430,6 +1444,10 @@ "event": { "__name": "RARITY_EVENT", "__format": "json" + }, + "never": { + "__name": "RARITY_NEVER", + "__format": "json" } }, "manualAreas": { From 80d9eb268c5ef6c613c6217935700eb0a04cd87f Mon Sep 17 00:00:00 2001 From: TurtIeSocks <58572875+TurtIeSocks@users.noreply.github.com> Date: Mon, 4 Jul 2022 08:33:11 -0400 Subject: [PATCH 3/4] Version Bump (and linting) --- package.json | 2 +- server/src/models/Pokemon.js | 4 +++- server/src/services/DbCheck.js | 9 ++++++++- server/src/services/initialization.js | 2 +- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index dcd278f47..f058b10ba 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "reactmap", - "version": "1.3.0", + "version": "1.3.1", "description": "React based frontend map.", "main": "ReactMap.mjs", "author": "TurtIeSocks <58572875+TurtIeSocks@users.noreply.github.com>", diff --git a/server/src/models/Pokemon.js b/server/src/models/Pokemon.js index 7e520467d..b96c2cf49 100644 --- a/server/src/models/Pokemon.js +++ b/server/src/models/Pokemon.js @@ -439,7 +439,9 @@ module.exports = class Pokemon extends Model { return { available: available.map((pkmn) => `${pkmn.pokemon_id}-${pkmn.form}`), - rarity: Object.fromEntries(rarity.map((pkmn) => [`${pkmn.id}-${pkmn.formId}`, pkmn.count])), + rarity: Object.fromEntries( + rarity.map((pkmn) => [`${pkmn.id}-${pkmn.formId}`, pkmn.count]), + ), } } diff --git a/server/src/services/DbCheck.js b/server/src/services/DbCheck.js index 964243114..5870c6982 100644 --- a/server/src/services/DbCheck.js +++ b/server/src/services/DbCheck.js @@ -4,7 +4,14 @@ const { raw } = require('objection') const extend = require('extend') module.exports = class DbCheck { - constructor(validModels, dbSettings, queryDebug, apiSettings, distanceUnit, rarityPercents) { + constructor( + validModels, + dbSettings, + queryDebug, + apiSettings, + distanceUnit, + rarityPercents, + ) { this.validModels = validModels.flatMap((s) => s.useFor) this.singleModels = ['User', 'Badge', 'Session'] this.searchLimit = apiSettings.searchLimit diff --git a/server/src/services/initialization.js b/server/src/services/initialization.js index 0dd56cb3e..a365e699e 100644 --- a/server/src/services/initialization.js +++ b/server/src/services/initialization.js @@ -20,7 +20,7 @@ const Db = new DbCheck( config.devOptions.queryDebug, config.api, config.map.distanceUnit, - config.rarity.percents + config.rarity.percents, ) const Pvp = config.api.pvp.reactMapHandlesPvp ? new PvpWrapper(config.api.pvp) From 18415b04a095f75400d6adb5229c6e1f46208286 Mon Sep 17 00:00:00 2001 From: TurtIeSocks <58572875+TurtIeSocks@users.noreply.github.com> Date: Mon, 4 Jul 2022 18:48:11 -0400 Subject: [PATCH 4/4] fix mad --- server/src/services/DbCheck.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/services/DbCheck.js b/server/src/services/DbCheck.js index 5870c6982..acc573f3b 100644 --- a/server/src/services/DbCheck.js +++ b/server/src/services/DbCheck.js @@ -136,7 +136,7 @@ module.exports = class DbCheck { const results = await Promise.all( this.models.Pokemon.map(async (source) => source.isMad - ? () => [] + ? [] : source.SubModel.query() .select('pokemon_id', raw('SUM(count) as total')) .from('pokemon_stats')