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

Improve humanize walking variance #5147

Merged
merged 39 commits into from Sep 4, 2016
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
28bb383
Add bearing parameter
mjmadsen Sep 3, 2016
a454450
Add calc_bearing
mjmadsen Sep 3, 2016
2238376
Fix placement
mjmadsen Sep 3, 2016
8c212ff
Switch to another function
mjmadsen Sep 3, 2016
a99e309
Update step_walker.py
mjmadsen Sep 3, 2016
2edd135
Fix import
mjmadsen Sep 3, 2016
83c6e7e
Merge branch 'dev' into mjmadsen-walker-variance
mjmadsen Sep 3, 2016
23bcca0
Update step_walker.py
mjmadsen Sep 3, 2016
41cf339
Update step_walker.py
mjmadsen Sep 3, 2016
14beb6d
Update step_walker.py
mjmadsen Sep 3, 2016
51ccc01
Update step_walker.py
mjmadsen Sep 3, 2016
3331d56
Update step_walker.py
mjmadsen Sep 3, 2016
85d3ef3
Revert
mjmadsen Sep 3, 2016
7371988
Update step_walker.py
mjmadsen Sep 3, 2016
61a73e2
Update step_walker.py
mjmadsen Sep 3, 2016
bff812f
Update step_walker.py
mjmadsen Sep 3, 2016
adf857b
Update step_walker.py
mjmadsen Sep 3, 2016
f71bba0
Update step_walker.py
mjmadsen Sep 3, 2016
5a3d7f0
Update step_walker.py
mjmadsen Sep 3, 2016
56bbd3d
Update step_walker.py
mjmadsen Sep 3, 2016
f9b25e7
import randrange
mjmadsen Sep 3, 2016
c1e66d5
Update step_walker.py
mjmadsen Sep 3, 2016
2e77752
More fixes :P
mjmadsen Sep 3, 2016
399bb48
Update step_walker.py
mjmadsen Sep 3, 2016
598ee3e
Update step_walker.py
mjmadsen Sep 3, 2016
04e46d6
Update step_walker.py
mjmadsen Sep 3, 2016
e86b848
Update step_walker.py
mjmadsen Sep 3, 2016
5d22c20
Update step_walker.py
mjmadsen Sep 3, 2016
8ec9f62
Update step_walker.py
mjmadsen Sep 3, 2016
b8bcdea
Merge branch 'dev' into mjmadsen-walker-variance
mjmadsen Sep 3, 2016
0c433b7
Update step_walker_test.py
mjmadsen Sep 3, 2016
4714ae9
Update step_walker_test.py
mjmadsen Sep 3, 2016
6044a74
due to bearing calculations the NORMALIZED_LAT_LNG_DISTANCE is now a …
th3w4y Sep 3, 2016
e28dc40
Merge pull request #1 from th3w4y/variance
mjmadsen Sep 3, 2016
ecfd324
handle special values for speed
th3w4y Sep 3, 2016
1381989
Merge pull request #2 from th3w4y/variance
mjmadsen Sep 3, 2016
df1b17f
bearing calculation should use final destination
th3w4y Sep 3, 2016
810ebc4
Update step_walker.py
mjmadsen Sep 3, 2016
744fec0
Merge pull request #3 from th3w4y/variance
mjmadsen Sep 3, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions pokemongo_bot/human_behaviour.py
Expand Up @@ -24,6 +24,9 @@ def random_lat_long_delta():
# Return random value from [-.000025, .000025]. Since 364,000 feet is equivalent to one degree of latitude, this
# should be 364,000 * .000025 = 9.1. So it returns between [-9.1, 9.1]
return ((random() * 0.00001) - 0.000005) * 5

def random_lat_long_delta2(bearing):
return ((random() * 0.00001) - 0.000005) * 5, ((random() * 0.00001) - 0.000005) * 5
Copy link
Contributor

Choose a reason for hiding this comment

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

How do you plan to use bearing in the calculation...?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we're heading at 0/360, we only add variance to latitude. Do some more math between there to scale each respective to that. I'm not sure

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wait I got that backwards. If we're headed north (0/360), we'd change our longitude.

Copy link
Contributor

Choose a reason for hiding this comment

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

The Delta applies to the destination. So as long as the Delta is smaller than the (destination - origin), you will never walk backward.
And as it is now, it is small enough for that. So not sure you need to change anything.


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
Expand Down
52 changes: 48 additions & 4 deletions pokemongo_bot/walkers/step_walker.py
@@ -1,4 +1,4 @@
from math import sqrt
import math

from random import uniform
from pokemongo_bot.cell_workers.utils import distance
Expand Down Expand Up @@ -54,10 +54,14 @@ def __init__(self, bot, dest_lat, dest_lng, dest_alt=None, fixed_speed=None):
self.dLng = (dest_lng - self.initLng) / int(self.steps)
self.magnitude = self._pythagorean(self.dLat, self.dLng)
Copy link
Contributor

Choose a reason for hiding this comment

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

method was removed...

self.unitAlt = (self.alt - self.initAlt) / int(self.steps)

self.bearing = calc_bearing(self.initLat, self.initLng, self.dLat, self.dLng)

def step(self):
walk_sway = random_lat_long_delta2(self.bearing)
Copy link
Contributor

Choose a reason for hiding this comment

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

random_lat_long_delta2 import missed?


if (self.dLat == 0 and self.dLng == 0) or self.dist < self.speed:
self.api.set_position(self.destLat + random_lat_long_delta(), self.destLng + random_lat_long_delta(), self.alt)
self.api.set_position(self.destLat + walk_sway[0], self.destLng + walk_sway[1], self.alt)
self.bot.event_manager.emit(
'position_update',
sender=self,
Expand All @@ -81,8 +85,8 @@ def step(self):
scaledDLat = unitLat * self.magnitude
scaledDLng = unitLng * self.magnitude

cLat = self.initLat + scaledDLat + random_lat_long_delta()
cLng = self.initLng + scaledDLng + random_lat_long_delta()
cLat = self.initLat + scaledDLat + walk_sway[0]
cLng = self.initLng + scaledDLng + walk_sway[1]
cAlt = self.initAlt + self.unitAlt + random_alt_delta()

self.api.set_position(cLat, cLng, cAlt)
Expand All @@ -106,3 +110,43 @@ def step(self):

def _pythagorean(self, lat, lng):
return sqrt((lat ** 2) + (lng ** 2))
Copy link
Contributor

Choose a reason for hiding this comment

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

If you import math

then this should become

math.sqrt


def calc_bearing(start_lat, start_lng, dest_lat, dest_lng):
Copy link
Contributor

@sohje sohje Sep 3, 2016

Choose a reason for hiding this comment

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

Should it be static method? calc_bearing(self...) ? Or you forget @static decorator?
upd: i'm about calc_bearing()

@static # ??
def calc_bearing(start_lat, start_lng, dest_lat, dest_lng)

"""
Calculates the bearing between two points.

The formulae used is the following:
θ = atan2(sin(Δlong).cos(lat2),
cos(lat1).sin(lat2) − sin(lat1).cos(lat2).cos(Δlong))

:Parameters:
- `start_lat in decimal degrees
- `start_lng in decimal degrees
- `dest_lat in decimal degrees
- `dest_lng in decimal degrees

:Returns:
The bearing in degrees

:Returns Type:
float
"""

lat1 = math.radians(start_lat)
lat2 = math.radians(dest_lat)

diffLong = math.radians(dest_lng - start_lng)

x = math.sin(diffLong) * math.cos(lat2)
y = math.cos(lat1) * math.sin(lat2) - (math.sin(lat1)
* math.cos(lat2) * math.cos(diffLong))

initial_bearing = math.atan2(x, y)

# Now we have the initial bearing but math.atan2 return values
# from -180° to + 180° which is not what we want for a compass bearing
# The solution is to normalize the initial bearing as shown below
initial_bearing = math.degrees(initial_bearing)
compass_bearing = (initial_bearing + 360) % 360

return compass_bearing