Skip to content

Commit

Permalink
Merge pull request #871 from WatWowMap/wayfarer-enhancements
Browse files Browse the repository at this point in the history
feat: Wayfarer enhancements
  • Loading branch information
TurtIeSocks authored Nov 2, 2023
2 parents 9ebafb1 + 8636c2d commit 85f7833
Show file tree
Hide file tree
Showing 17 changed files with 161 additions and 70 deletions.
3 changes: 3 additions & 0 deletions packages/locales/lib/human/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -672,5 +672,8 @@
"fast": "Fast",
"charged": "Charged",
"offline_mode": "Offline Mode",
"include_sponsored": "Include Sponsored",
"showcase_color": "Showcase Color",
"partner_color": "Partner Color",
"disable": "Disable {{- name}}"
}
2 changes: 2 additions & 0 deletions packages/types/lib/general.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export interface PoI {
id: string
lat: number
lon: number
showcase: boolean
partner: boolean
}

export interface BaseCell {
Expand Down
6 changes: 6 additions & 0 deletions packages/types/lib/scanner.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export interface Gym {
total_cp: number
first_seen_timestamp: number
sponsor_id: number
partner_id: number
raid_pokemon_costume: number
raid_pokemon_gender: number
raid_pokemon_evolution: number
Expand Down Expand Up @@ -161,13 +162,18 @@ export interface Pokestop {
pokestop_display: number
first_seen_timestamp: number
sponsor_id: number
partner_id: number
ar_scan_eligible: boolean
quests: Quest[]
invasions: Invasion[]
events: Event[]
power_up_level: number
power_up_points: number
power_up_end_timestamp: number
showcase_expiry?: number
showcase_pokemon_id?: number
showcase_ranking_standard?: number
showcase_rankings?: ShowcaseDetails | string
}

export type FullPokestop = FullModel<Pokestop, PokestopModel>
Expand Down
5 changes: 4 additions & 1 deletion server/src/configs/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@
"darkMapBorder": "#ff0000",
"cellBlocked": "#000000",
"poiColor": "#03ffff",
"showcaseColor": "#D365F5",
"partnerColor": "#F60042",
"enablePortalPopupCoords": false
},
"s2cells": {
Expand Down Expand Up @@ -554,7 +556,8 @@
"enabled": false,
"rings": true,
"s17Cells": true,
"s14Cells": true
"s14Cells": true,
"includeSponsored": true
},
"s2cells": {
"enabled": false,
Expand Down
2 changes: 2 additions & 0 deletions server/src/graphql/typeDefs/map.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ type PoI {
id: ID
lat: Float
lon: Float
showcase: Boolean
partner: Boolean
}

type SubmissionCell {
Expand Down
2 changes: 2 additions & 0 deletions server/src/graphql/typeDefs/scanner.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type Gym {
total_cp: Int
first_seen_timestamp: Int
sponsor_id: Int
partner_id: Int
raid_pokemon_costume: Int
raid_pokemon_gender: Int
raid_pokemon_evolution: Int
Expand Down Expand Up @@ -140,6 +141,7 @@ type Pokestop {
pokestop_display: Int
first_seen_timestamp: Int
sponsor_id: Int
partner_id: Int
ar_scan_eligible: Boolean
quests: [Quest]
invasions: [Invasion]
Expand Down
48 changes: 34 additions & 14 deletions server/src/models/Gym.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ class Gym extends Model {
return 'gym'
}

/**
*
* @param {import('objection').QueryBuilder<Gym, Gym[]>} query
* @param {boolean} isMad
*/
static onlyValid(query, isMad) {
query.andWhere('enabled', true)
if (!isMad) {
query.andWhere('deleted', false)
}
}

static async getAll(perms, args, { isMad, availableSlotsCol }, userId) {
const {
gyms: gymPerms,
Expand Down Expand Up @@ -118,7 +130,7 @@ class Gym extends Model {
query
.whereBetween(isMad ? 'latitude' : 'lat', [args.minLat, args.maxLat])
.andWhereBetween(isMad ? 'longitude' : 'lon', [args.minLon, args.maxLon])
.andWhere(isMad ? 'enabled' : 'deleted', isMad)
Gym.onlyValid(query, isMad)

const raidBosses = new Set()
const raidForms = new Set()
Expand Down Expand Up @@ -459,7 +471,6 @@ class Gym extends Model {
'url',
distance,
])
.where(isMad ? 'enabled' : 'deleted', isMad)
.whereRaw(`LOWER(name) LIKE '%${search}%'`)
.limit(searchResultsLimit)
.orderBy('distance')
Expand All @@ -469,6 +480,8 @@ class Gym extends Model {
if (!getAreaSql(query, areaRestrictions, onlyAreas, isMad)) {
return []
}
Gym.onlyValid(query, isMad)

return query
}

Expand Down Expand Up @@ -507,7 +520,6 @@ class Gym extends Model {
'>=',
isMad ? this.knex().fn.now() : ts,
)
.andWhere(isMad ? 'enabled' : 'deleted', isMad)
if (isMad) {
query
.leftJoin('gymdetails', 'gym.gym_id', 'gymdetails.gym_id')
Expand All @@ -519,6 +531,8 @@ class Gym extends Model {
if (!getAreaSql(query, perms.areaRestrictions, onlyAreas, isMad)) {
return []
}
Gym.onlyValid(query, isMad)

return query
}

Expand Down Expand Up @@ -567,36 +581,42 @@ class Gym extends Model {
.first()
}

static getSubmissions(perms, args, { isMad }) {
static async getSubmissions(perms, args, { isMad }) {
const {
filters: { onlyAreas = [] },
filters: { onlyAreas = [], onlyIncludeSponsored = true },
minLat,
minLon,
maxLat,
maxLon,
} = args
const wiggle = 0.025
const query = this.query()
.whereBetween(`lat${isMad ? 'itude' : ''}`, [
minLat - 0.025,
maxLat + 0.025,
minLat - wiggle,
maxLat + wiggle,
])
.andWhereBetween(`lon${isMad ? 'gitude' : ''}`, [
minLon - 0.025,
maxLon + 0.025,
minLon - wiggle,
maxLon + wiggle,
])
.andWhere(isMad ? 'enabled' : 'deleted', isMad)
if (isMad) {
query.select(['gym_id AS id', 'latitude AS lat', 'longitude AS lon'])
} else {
query.select(['id', 'lat', 'lon']).andWhere((poi) => {
poi.whereNull('sponsor_id').orWhere('sponsor_id', 0)
})
query.select(['id', 'lat', 'lon', 'partner_id'])

if (!onlyIncludeSponsored) {
query.andWhere((poi) => {
poi.whereNull('partner_id').orWhere('partner_id', 0)
})
}
}
if (!getAreaSql(query, perms.areaRestrictions, onlyAreas, isMad)) {
return []
}
Gym.onlyValid(query, isMad)

return query
const results = await query
return results
}
}

Expand Down
6 changes: 5 additions & 1 deletion server/src/models/PoI.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ class PoI {
* @param {string} id
* @param {number} lat
* @param {number} lon
* @param {boolean} [partner]
* @param {boolean} [showcase]
*/
constructor(id, lat, lon) {
constructor(id, lat, lon, partner = false, showcase = false) {
this.id = id
this.lat = lat
this.lon = lon
this.partner = partner
this.showcase = showcase
}
}

Expand Down
42 changes: 32 additions & 10 deletions server/src/models/Pokestop.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ class Pokestop extends Model {
return 'pokestop'
}

/**
*
* @param {import('objection').QueryBuilder<Pokestop, Pokestop[]>} query
* @param {boolean} isMad
*/
static onlyValid(query, isMad) {
query.andWhere('enabled', true)
if (!isMad) {
query.andWhere('deleted', false)
}
}

static async getAll(
perms,
args,
Expand Down Expand Up @@ -176,7 +188,8 @@ class Pokestop extends Model {
query
.whereBetween(isMad ? 'latitude' : 'lat', [args.minLat, args.maxLat])
.andWhereBetween(isMad ? 'longitude' : 'lon', [args.minLon, args.maxLon])
.andWhere(isMad ? 'enabled' : 'deleted', isMad)

Pokestop.onlyValid(query, isMad)
if (!getAreaSql(query, areaRestrictions, onlyAreas, isMad)) {
return []
}
Expand Down Expand Up @@ -1557,13 +1570,13 @@ class Pokestop extends Model {
isMad ? 'image AS url' : 'url',
distance,
])
.where(isMad ? 'enabled' : 'deleted', isMad)
.whereRaw(`LOWER(name) LIKE '%${search}%'`)
.limit(searchResultsLimit)
.orderBy('distance')
if (!getAreaSql(query, perms.areaRestrictions, onlyAreas, isMad)) {
return []
}
Pokestop.onlyValid(query, isMad)
return query
}

Expand Down Expand Up @@ -1606,7 +1619,6 @@ class Pokestop extends Model {
isMad ? 'quest_reward AS quest_rewards' : 'quest_rewards',
distance,
])
.where(isMad ? 'enabled' : 'deleted', isMad)
.andWhere('quest_timestamp', '>=', midnight || 0)
.andWhere((quests) => {
quests
Expand All @@ -1628,6 +1640,8 @@ class Pokestop extends Model {
if (!getAreaSql(query, perms.areaRestrictions, onlyAreas, isMad)) {
return []
}
Pokestop.onlyValid(query, isMad)

const results = await query
const mapped = results.map((q) => ({ ...q, with_ar: q.with_ar ?? true }))

Expand Down Expand Up @@ -1697,7 +1711,6 @@ class Pokestop extends Model {
: 'lure_expire_timestamp',
distance,
])
.where(isMad ? 'enabled' : 'deleted', isMad)
.andWhere(
isMad ? 'lure_expiration' : 'lure_expire_timestamp',
'>=',
Expand All @@ -1709,6 +1722,8 @@ class Pokestop extends Model {
if (!getAreaSql(query, perms.areaRestrictions, onlyAreas, isMad)) {
return []
}
Pokestop.onlyValid(query, isMad)

const results = await query
return results
}
Expand All @@ -1723,9 +1738,9 @@ class Pokestop extends Model {
.first()
}

static getSubmissions(perms, args, { isMad }) {
static getSubmissions(perms, args, { isMad, hasShowcaseData }) {
const {
filters: { onlyAreas = [] },
filters: { onlyAreas = [], onlyIncludeSponsored = true },
minLat,
minLon,
maxLat,
Expand All @@ -1740,17 +1755,24 @@ class Pokestop extends Model {
minLon - 0.025,
maxLon + 0.025,
])
.andWhere(isMad ? 'enabled' : 'deleted', isMad)
if (isMad) {
query.select(['pokestop_id AS id', 'latitude AS lat', 'longitude AS lon'])
} else {
query.select(['id', 'lat', 'lon']).andWhere((poi) => {
poi.whereNull('sponsor_id').orWhere('sponsor_id', 0)
})
query.select(['id', 'lat', 'lon', 'partner_id'])
if (!onlyIncludeSponsored) {
query.andWhere((poi) => {
poi.whereNull('partner_id').orWhere('partner_id', 0)
})
}
if (hasShowcaseData) {
query.select('showcase_expiry')
}
}
if (!getAreaSql(query, perms.areaRestrictions, onlyAreas, isMad)) {
return []
}
Pokestop.onlyValid(query, isMad)

return query
}
}
Expand Down
1 change: 1 addition & 0 deletions server/src/services/filters/builder/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ function buildDefaultFilters(perms, database) {
rings: defaultFilters.submissionCells.rings,
s17Cells: defaultFilters.submissionCells.s17Cells,
s14Cells: defaultFilters.submissionCells.s14Cells,
includeSponsored: defaultFilters.submissionCells.includeSponsored,
filter: { global: new BaseFilter() },
}
: undefined,
Expand Down
11 changes: 10 additions & 1 deletion server/src/services/functions/getPlacementCells.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,16 @@ function getPlacementCells(filters, pokestops, gyms) {
? Object.values(indexedCells)
: [],
pois: filters.filters.onlyRings
? allCoords.map((poi) => new PoI(poi.id, poi.lat, poi.lon))
? allCoords.map(
(poi) =>
new PoI(
poi.id,
poi.lat,
poi.lon,
!!poi.partner_id,
'showcase_expiry' in poi ? !!poi.showcase_expiry : false,
),
)
: [],
}
}
Expand Down
2 changes: 2 additions & 0 deletions server/src/services/ui/clientOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ function clientOptions(perms) {
darkMapBorder: { type: 'color', perm: ['submissionCells'] },
cellBlocked: { type: 'color', perm: ['submissionCells'] },
poiColor: { type: 'color', perm: ['submissionCells'] },
partnerColor: { type: 'color', perm: ['submissionCells'] },
showcaseColor: { type: 'color', perm: ['submissionCells'] },
},
s2cells: {
lightMapBorder: { type: 'color', perm: ['s2cells'] },
Expand Down
Loading

0 comments on commit 85f7833

Please sign in to comment.