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

Step walker changes altitude gradually #4581

Merged
merged 5 commits into from
Aug 22, 2016
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
2 changes: 1 addition & 1 deletion configs/path.json.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[
{"location": "32.087504, 34.806118"},
{"location": "32.087504, 34.806118, 4.810"},
{"location": "Bialik 150, Ramat Gan"},
{"location": "Ayalon Highway, Ramat Gan"},
{"location": "32.091280, 34.795261"}
Expand Down
4 changes: 2 additions & 2 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1059,14 +1059,14 @@ def get_pos_by_name(self, location_name):
possible_coordinates = re.findall(
"[-]?\d{1,3}[.]\d{3,7}", location_name
)
if len(possible_coordinates) == 2:
if len(possible_coordinates) >= 2:
# 2 matches, this must be a coordinate. We'll bypass the Google
# geocode so we keep the exact location.
self.logger.info(
'[x] Coordinates found in passed in location, '
'not geocoding.'
)
return float(possible_coordinates[0]), float(possible_coordinates[1]), self.alt
return float(possible_coordinates[0]), float(possible_coordinates[1]), (float(possible_coordinates[2]) if len(possible_coordinates) == 3 else self.alt)

geolocator = GoogleV3(api_key=self.config.gmapkey)
loc = geolocator.geocode(location_name, timeout=10)
Expand Down
13 changes: 8 additions & 5 deletions pokemongo_bot/cell_workers/follow_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ def load_json(self):
'position': point_tuple
}
)
points[index] = self.lat_lng_tuple_to_dict(point_tuple)
points[index] = self.point_tuple_to_dict(point_tuple)
return points

def lat_lng_tuple_to_dict(self, tpl):
return {'lat': tpl[0], 'lng': tpl[1]}
def point_tuple_to_dict(self, tpl):
return {'lat': tpl[0], 'lng': tpl[1], 'alt': tpl[2]}

def load_gpx(self):
gpx_file = open(self.path_file, 'r')
Expand Down Expand Up @@ -133,15 +133,18 @@ def work(self):
point = self.points[self.ptr]
lat = float(point['lat'])
lng = float(point['lng'])
alt = uniform(self.bot.config.alt_min, self.bot.config.alt_max)

if 'alt' in point:
alt = float(point['alt'])
else:
alt = uniform(self.bot.config.alt_min, self.bot.config.alt_max)

if self.bot.config.walk_max > 0:
step_walker = StepWalker(
self.bot,
lat,
lng
lng,
alt
)

is_at_destination = False
Expand Down
5 changes: 5 additions & 0 deletions pokemongo_bot/human_behaviour.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ def random_lat_long_delta():
# should be 364,000 * .000025 = 9.1. So it returns between [-9.1, 9.1]
return ((random() * 0.00001) - 0.000005) * 5

def random_alt_delta():
# Return random value from [-0.2, 0.2]. Altitude is measured in meters. A delta of 0.4 could for example
# represent a phone near chest level vs in pants pocket level
return uniform(-0.2,0.2)

def gps_noise_rng(radius):
'''
Simulates gps noise.
Expand Down
24 changes: 16 additions & 8 deletions pokemongo_bot/walkers/step_walker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

from random import uniform
from pokemongo_bot.cell_workers.utils import distance
from pokemongo_bot.human_behaviour import random_lat_long_delta, sleep

from pokemongo_bot.human_behaviour import random_lat_long_delta, sleep, random_alt_delta

class StepWalker(object):

def __init__(self, bot, dest_lat, dest_lng):
def __init__(self, bot, dest_lat, dest_lng, dest_alt = None):
self.bot = bot
self.api = bot.api

Expand All @@ -19,10 +18,17 @@ def __init__(self, bot, dest_lat, dest_lng):
dest_lat,
dest_lng
)

self.alt = uniform(self.bot.config.alt_min, self.bot.config.alt_max)
if dest_alt == None:
self.alt = uniform(self.bot.config.alt_min, self.bot.config.alt_max)
else:
self.alt = dest_alt
self.speed = uniform(self.bot.config.walk_min, self.bot.config.walk_max)

if len(self.bot.position) == 3:
self.initAlt = self.bot.position[2]
else:
self.initAlt = self.alt;

self.destLat = dest_lat
self.destLng = dest_lng
self.totalDist = max(1, self.dist)
Expand All @@ -40,6 +46,7 @@ def __init__(self, bot, dest_lat, dest_lng):
self.dLat = (dest_lat - self.initLat) / int(self.steps)
self.dLng = (dest_lng - self.initLng) / int(self.steps)
self.magnitude = self._pythagorean(self.dLat, self.dLng)
self.unitAlt = (self.alt - self.initAlt) / int(self.steps)

def step(self):
if (self.dLat == 0 and self.dLng == 0) or self.dist < self.speed:
Expand Down Expand Up @@ -69,15 +76,16 @@ def step(self):

cLat = self.initLat + scaledDLat + random_lat_long_delta()
cLng = self.initLng + scaledDLng + random_lat_long_delta()
cAlt = self.initAlt + self.unitAlt + random_alt_delta()

self.api.set_position(cLat, cLng, self.alt)
self.api.set_position(cLat, cLng, cAlt)
self.bot.event_manager.emit(
'position_update',
sender=self,
level='debug',
data={
'current_position': (cLat, cLng),
'last_position': (self.initLat, self.initLng),
'current_position': (cLat, cLng, cAlt),
'last_position': (self.initLat, self.initLng, self.initAlt),
'distance': '',
'distance_unit': ''
}
Expand Down