Skip to content
This repository was archived by the owner on Oct 7, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
8d449b8
Adjust typing
Grennith Dec 2, 2020
fafa6c6
Fix wrong comparison against a tuple in WorkerMITM.py
Grennith Dec 2, 2020
614e37b
Use timestamp of half the way of a walk
Grennith Dec 2, 2020
faadfe0
Adjust wait_for_data to fully respect max distance setting (except fo…
Grennith Dec 2, 2020
4bffdd1
Fix wrong logging of max distance to be respected in wait_for_data
Grennith Dec 2, 2020
c281f35
Adjust the timestamp to use in case of walking to at most wait for da…
Grennith Dec 2, 2020
0ad66ef
Remove check of distance based on data in WorkerMITM::_check_for_data…
Grennith Dec 2, 2020
7c21a51
Remove check of distance based on data in WorkerMITM::_check_for_data…
Grennith Dec 2, 2020
47d172a
Adjust wait_for_data to simply use maximum_valid_distance arg or the …
Grennith Dec 3, 2020
395138e
Remove distance check based on data entirely
Grennith Dec 3, 2020
192e90f
Fix fort ids NOT being int
Grennith Dec 3, 2020
0564aab
Remove counting based on fort IDs / encounter IDs entirely using leng…
Grennith Dec 3, 2020
6ac390a
Adjust location check in WorkerQuests::_current_position_has_spinnabl…
Grennith Dec 3, 2020
74f0cd4
Refactored MITMBase.py, WorkerMITM.py and WorkerQuests.py (extracted …
Grennith Dec 5, 2020
91a48e9
Extracted more methods...
Grennith Dec 5, 2020
03f9c6b
Fix wrong check for distance
Grennith Dec 5, 2020
ed5302a
Add ProtoIdentifier.py enum representing protos being waited for in M…
Grennith Dec 5, 2020
777ccb4
Extract a**s-long cooldown calculation to gamemechanicutil.py
Grennith Dec 5, 2020
3ccb064
Extract walk after teleport
Grennith Dec 5, 2020
1cb7104
Add logging of location to warning message
Grennith Dec 5, 2020
e96fa26
Only update location, timestamp, timestamp_last_data and timestamp_re…
Grennith Dec 5, 2020
2e2bbd0
Update WorkerQuests.py to use ProtoIdentifier.py
Grennith Dec 6, 2020
299cf16
Fix waiting for encounter being used in _try_to_open_pokestop
Grennith Dec 6, 2020
e19bb65
Remove unused import and enrich debug2 logging of stops
Grennith Dec 6, 2020
bc62502
WIP: Automatically move location/delete stops according to GMO during…
Grennith Dec 6, 2020
461346a
Remove ids_iv for quest mode.
Grennith Dec 6, 2020
02b861f
Fix get_stop_ids_and_locations_nearby query statement
Grennith Dec 6, 2020
faddc35
Adjust SELECT of stops nearby
Grennith Dec 6, 2020
ae54301
Adjust max_distance minimum value
Grennith Dec 6, 2020
5b1987c
Check for stops within roughly one kilometer distance
Grennith Dec 6, 2020
aabc51b
Add distance check in meters to deletion/moving routine since DB oper…
Grennith Dec 6, 2020
ef11cf5
Actually delete stop if not within 100m range
Grennith Dec 6, 2020
f405f77
Adjust wrong logging
Grennith Dec 6, 2020
d42c056
Log GMO cells...
Grennith Dec 6, 2020
087aed7
Notify RouteManagerQuests.py of deleted stops
Grennith Dec 6, 2020
0ef6f22
Check for missing URL in quests.html (probably a faulty DB with delet…
Grennith Dec 7, 2020
9b5a457
Add a check for the timestamp that a proto was received last, thus al…
Grennith Dec 7, 2020
e1a302a
Adjust default max_distance for get_stop_ids_and_locations_nearby
Grennith Dec 7, 2020
eec8156
Add last_updated check to only delete stops that have not been update…
Grennith Dec 7, 2020
d42f4f1
Adjust logging of stop deletion
Grennith Dec 8, 2020
ca1f7f6
Adjust logging of stop deletion
Grennith Dec 8, 2020
68d5137
Handle last_updated being null/none
Grennith Dec 8, 2020
2ed1783
Correctly check for None... duh...
Grennith Dec 9, 2020
682429c
Reset last_time_received after the first iteration to break the loop …
Grennith Dec 12, 2020
9e3f63d
Add a check for stops in current (and possibly surrounding) cells in …
Grennith Dec 12, 2020
d8df9a3
Extract constants & adjust sleep in wait_for_data
Grennith Dec 13, 2020
d534904
Fix quest scans failing due to wrong variable used in GMO check for W…
Grennith Dec 13, 2020
53513bc
Extract some more constants in MITMBase.py
Grennith Dec 13, 2020
756b052
Fix linting issues
Expl0dingBanana Dec 16, 2020
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
45 changes: 43 additions & 2 deletions mapadroid/db/DbWrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import time
from datetime import datetime, timedelta, timezone
from functools import reduce
from typing import List, Optional
from typing import List, Optional, Dict, Tuple
from mapadroid.db.DbSchemaUpdater import DbSchemaUpdater
from mapadroid.db.DbPogoProtoSubmit import DbPogoProtoSubmit
from mapadroid.db.DbSanityCheck import DbSanityCheck
Expand Down Expand Up @@ -696,6 +696,15 @@ def get_stops_in_rectangle(self, ne_lat, ne_lon, sw_lat, sw_lon, o_ne_lat=None,
pokestop['has_quest'] = pokestop['pokestop_id'] in quests
return pokestops

def update_pokestop_location(self, fort_id: str, latitude: float, longitude: float) -> None:
query = (
"UPDATE pokestop "
"SET latitude = %s, longitude = %s "
"WHERE pokestop_id = %s"
)
update_vars = (latitude, longitude, fort_id)
self.execute(query, update_vars, commit=True)

def delete_stop(self, latitude: float, longitude: float):
logger.debug3('Deleting stop from db')
query = (
Expand Down Expand Up @@ -975,8 +984,40 @@ def retrieve_next_spawns(self, geofence_helper):
next_up.append((timestamp, Location(latitude, longitude)))
return next_up

def get_stop_ids_and_locations_nearby(self, location: Location, max_distance: int = 0.5) \
-> Dict[str, Tuple[Location, datetime]]:
"""
Fetch the IDs and the stops' locations from DB around the given location with a radius of distance passed
Args:
location:
max_distance: Radius around location to return stops within (in kilometers)

Returns:

"""
if max_distance < 0:
logger.warning("Cannot search for stops at negative range...")
return {}

query = (
"SELECT pokestop_id, latitude, longitude, last_updated "
"FROM pokestop "
"WHERE SQRT(POW(69.1 * (latitude - {}), 2) + POW(69.1 * ({} - longitude), 2)) <= {} "
).format(location.lat, location.lng, max_distance)
res = self.execute(query)

if not res:
logger.warning("No stops found closeby to {} in range of {}m", str(location), max_distance)
return {}

stops: Dict[str, Tuple[Location, datetime]] = dict()
for (pokestop_id, latitude, longitude, last_updated) in res:
stops[pokestop_id] = (Location(latitude, longitude), last_updated)

return stops

def get_nearest_stops_from_position(self, geofence_helper, origin: str, lat, lon, limit: int = 20,
ignore_spinned: bool = True, maxdistance: int = 1):
ignore_spinned: bool = True, maxdistance: int = 1) -> List[Location]:
"""
Retrieve the nearest stops from lat / lon (optional with limit)
:return:
Expand Down
11 changes: 7 additions & 4 deletions mapadroid/mitm_receiver/MitmMapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,13 @@ def update_latest(self, origin: str, key: str, values_dict, timestamp_received_r
if self.__mapping.get(origin) is not None and self.__mapping[origin].get(key) is not None:
del self.__mapping[origin][key]
self.__mapping[origin][key] = {}
self.__mapping[origin]["location"] = location
self.__mapping[origin][key]["timestamp"] = timestamp_received_raw
self.__mapping[origin]["timestamp_last_data"] = timestamp_received_raw
self.__mapping[origin]["timestamp_receiver"] = timestamp_received_receiver
if location is not None:
self.__mapping[origin]["location"] = location
if timestamp_received_raw is not None:
self.__mapping[origin][key]["timestamp"] = timestamp_received_raw
self.__mapping[origin]["timestamp_last_data"] = timestamp_received_raw
if timestamp_received_receiver is not None:
self.__mapping[origin]["timestamp_receiver"] = timestamp_received_receiver
self.__mapping[origin][key]["values"] = values_dict
updated = True
else:
Expand Down
2 changes: 1 addition & 1 deletion mapadroid/route/RouteManagerQuests.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def _check_coords_before_returning(self, lat, lng, origin):
return True
stop = Location(lat, lng)
self.logger.info('Checking Stop with ID {}', stop)
if stop not in self._stoplist:
if stop not in self._stoplist and stop not in self._coords_to_be_ignored:
self.logger.info('Already got this Stop')
return False
self.logger.info('Getting new Stop')
Expand Down
10 changes: 10 additions & 0 deletions mapadroid/utils/ProtoIdentifier.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from enum import IntEnum


class ProtoIdentifier(IntEnum):
INVENTORY = 4
FORT_SEARCH = 101
ENCOUNTER = 102
FORT_DETAILS = 104
GMO = 106
GYM_INFO = 156
89 changes: 89 additions & 0 deletions mapadroid/utils/gamemechanicutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,92 @@ def is_mon_ditto(logger, pokemon_data):
return True
else:
return False


def calculate_cooldown(distance, speed):
if distance >= 1335000:
speed = 180.43 # Speed can be abt 650 km/h
elif distance >= 1100000:
speed = 176.2820513
elif distance >= 1020000:
speed = 168.3168317
elif distance >= 1007000:
speed = 171.2585034
elif distance >= 948000:
speed = 166.3157895
elif distance >= 900000:
speed = 164.8351648
elif distance >= 897000:
speed = 166.1111111
elif distance >= 839000:
speed = 158.9015152
elif distance >= 802000:
speed = 159.1269841
elif distance >= 751000:
speed = 152.6422764
elif distance >= 700000:
speed = 151.5151515
elif distance >= 650000:
speed = 146.3963964
elif distance >= 600000:
speed = 142.8571429
elif distance >= 550000:
speed = 138.8888889
elif distance >= 500000:
speed = 134.4086022
elif distance >= 450000:
speed = 129.3103448
elif distance >= 400000:
speed = 123.4567901
elif distance >= 350000:
speed = 116.6666667
elif distance >= 328000:
speed = 113.8888889
elif distance >= 300000:
speed = 108.6956522
elif distance >= 250000:
speed = 101.6260163
elif distance >= 201000:
speed = 90.54054054
elif distance >= 175000:
speed = 85.78431373
elif distance >= 150000:
speed = 78.125
elif distance >= 125000:
speed = 71.83908046
elif distance >= 100000:
speed = 64.1025641
elif distance >= 90000:
speed = 60
elif distance >= 80000:
speed = 55.55555556
elif distance >= 70000:
speed = 50.72463768
elif distance >= 60000:
speed = 47.61904762
elif distance >= 45000:
speed = 39.47368421
elif distance >= 40000:
speed = 35.0877193
elif distance >= 35000:
speed = 32.40740741
elif distance >= 30000:
speed = 29.41176471
elif distance >= 25000:
speed = 27.77777778
elif distance >= 20000:
speed = 27.77777778
elif distance >= 15000:
speed = 27.77777778
elif distance >= 10000:
speed = 23.80952381
elif distance >= 8000:
speed = 26.66666667
elif distance >= 5000:
speed = 22.34137623
elif distance >= 4000:
speed = 22.22222222
delay_used = distance / speed
if delay_used > 7200: # There's a maximum of 2 hours wait time
delay_used = 7200
return delay_used
Loading