Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update current weather in gym properties #1225

Open
wants to merge 2 commits into
base: legacy
Choose a base branch
from
Open
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
22 changes: 16 additions & 6 deletions mapadroid/db/DbPogoProtoSubmit.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,15 +746,15 @@ def gyms(self, origin: str, map_proto: dict):

query_gym = (
"INSERT INTO gym (gym_id, team_id, guard_pokemon_id, slots_available, enabled, latitude, longitude, "
"total_cp, is_in_battle, last_modified, last_scanned, is_ex_raid_eligible, is_ar_scan_eligible) "
"VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) "
"total_cp, is_in_battle, last_modified, last_scanned, is_ex_raid_eligible, is_ar_scan_eligible, "
"weather_boosted_condition) "
"VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) "
"ON DUPLICATE KEY UPDATE "
"guard_pokemon_id=VALUES(guard_pokemon_id), team_id=VALUES(team_id), "
"slots_available=VALUES(slots_available), last_scanned=VALUES(last_scanned), "
"last_modified=VALUES(last_modified), latitude=VALUES(latitude), longitude=VALUES(longitude), "
"is_ex_raid_eligible=VALUES(is_ex_raid_eligible),"
"is_ar_scan_eligible=VALUES(is_ar_scan_eligible),"
"is_in_battle=VALUES(is_in_battle)"
"is_ex_raid_eligible=VALUES(is_ex_raid_eligible), is_ar_scan_eligible=VALUES(is_ar_scan_eligible), "
"is_in_battle=VALUES(is_in_battle), weather_boosted_condition=VALUES(weather_boosted_condition)"
)
query_gym_details = (
"INSERT INTO gymdetails (gym_id, name, url, last_scanned) "
Expand All @@ -778,6 +778,15 @@ def gyms(self, origin: str, map_proto: dict):
is_ex_raid_eligible = gym["gym_details"]["is_ex_raid_eligible"]
is_ar_scan_eligible = gym["is_ar_scan_eligible"]
is_in_battle = gym['gym_details']['is_in_battle']
s2_cell_id = S2Helper.lat_lng_to_cell_id(latitude, longitude)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've not checked exactly how much of an impact this does on performance, but it strikes me as a very roundabout way to add weather info to gyms, when the current weather information for any gym is always available through doing the same query in front ends or webhook selects.

The issues I have with this solution is

  • Weather updates will not get registered into the gym column when weather changes
  • Calculating s2 cell id for the weather each gym update adds (a very tiny) overhead + the select from weather is 100% not needed, when any front end could do this every time gym info is needed anyhow

sql = "SELECT `gameplay_weather` " \
"FROM weather " \
"WHERE s2_cell_id = {}".format(s2_cell_id)
found = self._db_exec.execute(sql)
if len(found) == 1:
weather_id = found[0][0]
else:
weather_id = 0 # unknown

cache_key = "gym{}{}".format(gymid, last_modified_ts)
if cache.exists(cache_key):
Expand All @@ -793,7 +802,8 @@ def gyms(self, origin: str, map_proto: dict):
last_modified, # last_modified
now, # last_scanned
is_ex_raid_eligible,
is_ar_scan_eligible
is_ar_scan_eligible,
weather_id # weather_boosted_condition
)
)

Expand Down
2 changes: 1 addition & 1 deletion mapadroid/db/DbWebhookReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def get_raids_changed_since(self, timestamp):
"SELECT raid.gym_id, raid.level, raid.spawn, raid.start, raid.end, raid.pokemon_id, "
"raid.cp, raid.move_1, raid.move_2, raid.last_scanned, raid.form, raid.is_exclusive, raid.gender, "
"raid.costume, raid.evolution, gymdetails.name, gymdetails.url, gym.latitude, gym.longitude, "
"gym.team_id, weather_boosted_condition, gym.is_ex_raid_eligible "
"gym.team_id, gym.weather_boosted_condition, gym.is_ex_raid_eligible "
"FROM raid "
"LEFT JOIN gymdetails ON gymdetails.gym_id = raid.gym_id "
"LEFT JOIN gym ON gym.gym_id = raid.gym_id "
Expand Down