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

Improve humanize walking variance #5147

merged 39 commits into from Sep 4, 2016

Conversation

mjmadsen
Copy link
Contributor

@mjmadsen mjmadsen commented Sep 3, 2016

  • Account for bearing when adding in walking "sway"
  • We now only sway "left" and "right" as we head towards our destination

@mention-bot
Copy link

@mjmadsen, thanks for your PR! By analyzing the annotation information on this pull request, we identified @douglascamata, @sinap and @alexyaoyang to be potential reviewers

@@ -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.

@@ -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

@@ -109,7 +109,7 @@ def step(self):
# alt, False)

def _pythagorean(self, lat, lng):
return sqrt((lat ** 2) + (lng ** 2))
return math.sqrt((lat ** 2) + (lng ** 2))

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)

@th3w4y
Copy link
Contributor

th3w4y commented Sep 3, 2016

@mjmadsen I am afraid that the travis build is failing due to non-ASCII carracters

θ = atan2(sin(Δlong).cos(lat2),


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?

@th3w4y
Copy link
Contributor

th3w4y commented Sep 3, 2016

I don't think that adding a random value to only latitude or only longitude based on bearing adds much extra...

@mjmadsen
Copy link
Contributor Author

mjmadsen commented Sep 3, 2016

@th3w4y this is for our discussion in #5140

We're adding in a bit of variance to simulate human walking. We want it to only move us "left" or "right".

return sqrt((lat ** 2) + (lng ** 2))
return math.sqrt((lat ** 2) + (lng ** 2))

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.

make

def _calc_bearing(self, start_lat, start_lng, dest_lat, dest_lng)

or make it static

@staticmethod
def calc_bearing(start_lat, start_lng, dest_lat, dest_lng)

self.calc_bearing(self.initLat, self.initLng, self.dLat, self.dLng)
#self.calc_bearing(self.initLat, self.initLng, self.dLat, self.dLng)

@sohje
Copy link
Contributor

sohje commented Sep 3, 2016

Works for me.
pnds

@th3w4y
Copy link
Contributor

th3w4y commented Sep 3, 2016

@sohje @mjmadsen I agreed with the idea... but the calculation doesn't seem to do that yet...

it doesn't even use bearing in the calculation.. thus it did not change anything yet...

@@ -4,7 +4,7 @@

from random import uniform
from pokemongo_bot.cell_workers.utils import distance
from pokemongo_bot.human_behaviour import random_lat_long_delta2, sleep, random_alt_delta
from pokemongo_bot.human_behaviour import random_lat_long_delta, random_lat_long_delta2, sleep, random_alt_delta
Copy link
Contributor

Choose a reason for hiding this comment

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

Any usage of random_lat_long_delta?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The test files use it still. I'll update those too if I can get this working :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually the CI still fails because of how the test files are setup.

@mjmadsen
Copy link
Contributor Author

mjmadsen commented Sep 3, 2016

@th3w4y Yeah, I still need to figure out the important part :)

@sohje
Copy link
Contributor

sohje commented Sep 3, 2016

@th3w4y @mjmadsen Just to make sure bot not crashing ;]

@BreezeRo
Copy link
Contributor

BreezeRo commented Sep 3, 2016

looks good 💃 might have to edit pokemongo_bot/test/step_walker_test.py to pass CI

@th3w4y
Copy link
Contributor

th3w4y commented Sep 3, 2016

My proposal:

We only specify an effect in degrees from the bearing.. where we would want to be at

IIn [209]: from geopy.distance import VincentyDistance

In [210]: 

In [210]: from geopy import Point
In [225]: def get_next_pos(lat, lon, bearing, speed, offset_angle):
     ...:     origin = Point(lat, lon)
     ...:     lat, lon, _ = VincentyDistance(kilometers=speed*1e-3).destination(origin, bearing+random.randrange(-offset_angle, offset_angle))
     ...:     return lat, lon
     ...:     
     ...:     
     ...: 

In [226]: 

In [226]:  get_next_pos(ex_orig[0], ex_orig[1], 180, 3, 5)
Out[226]: (47.170610881050735, 8.516737739683606)

In [227]:  get_next_pos(ex_orig[0], ex_orig[1], 180, 3, 5)
Out[227]: (47.170610819427246, 8.516741190604915)

In [228]:  get_next_pos(ex_orig[0], ex_orig[1], 180, 3, 5)
Out[228]: (47.170610831755695, 8.516741880999465)

In [229]: 

@th3w4y
Copy link
Contributor

th3w4y commented Sep 3, 2016

This above obviously can replace the whole pythagorean.. magnitude.. the big convoluted part in StepWalker

@th3w4y
Copy link
Contributor

th3w4y commented Sep 3, 2016

@sohje one explanation would be:

pokestops are too close... google maps does not have walking directions in between them

but your picture shows that you were automatically fallback to classic behaviour... waking through buildings

to confirm that 💯 % do you have the coordinates of those pokestops from your fort files?

@mjmadsen
Copy link
Contributor Author

mjmadsen commented Sep 3, 2016

I'm running through all the walkers. Might not finish before I go to bed.

@anakin5 does this seem to give your poly the results you're looking for? If we seal this portion down, we don't have to mess with it for a long ass time!

@sohje
Copy link
Contributor

sohje commented Sep 3, 2016

@th3w4y according to google maps there are 1-3 routes between pokestops on that coords.

handle special values for speed
@th3w4y
Copy link
Contributor

th3w4y commented Sep 3, 2016

@mjmadsen one more commit:

https://github.com/mjmadsen/PokemonGo-Bot/pull/2
To make the function complete...(i don't want to see divisions by zero of walking of planet)

@th3w4y
Copy link
Contributor

th3w4y commented Sep 3, 2016

@mjmadsen i know that we'll not see 0.0 or infinite but it make the function complete and protected from ZeroDivizion

@th3w4y
Copy link
Contributor

th3w4y commented Sep 3, 2016

@mjmadsen I found a bug...

bearing should be towards the final destination to towards something calculated...

https://github.com/mjmadsen/PokemonGo-Bot/blob/13819891d3d0df4ec91fbe4bfeefcb7d64a1fbab/pokemongo_bot/walkers/step_walker.py#L58

@th3w4y
Copy link
Contributor

th3w4y commented Sep 3, 2016

This is incorrect

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

@sohje
Copy link
Contributor

sohje commented Sep 3, 2016

still moving straight ;]

[2016-09-03 20:31:12] [MoveToFort] Moving towards pokestop XX - 0.13km
[2016-09-03 20:31:17] [MoveToFort] Moving towards pokestop  XX - 0.11km
[2016-09-03 20:31:23] [MoveToFort] Moving towards pokestop XX - 0.10km
[2016-09-03 20:31:29] [MoveToFort] Moving towards pokestop  XX - 0.10km
[2016-09-03 20:31:35] [MoveToFort] Moving towards pokestop  XX - 0.11km
[2016-09-03 20:31:42] [MoveToFort] towards pokestop  XX - 0.12km

@th3w4y
Copy link
Contributor

th3w4y commented Sep 3, 2016

Should be:

self.bearing = self._calc_bearing(self.initLat, self.initLng, self.destLat, self.destLng)

@sohje
Copy link
Contributor

sohje commented Sep 3, 2016

yeap, with destLat and destLng works fine.

@th3w4y
Copy link
Contributor

th3w4y commented Sep 3, 2016

@mjmadsen bearing calculation should use final destination https://github.com/mjmadsen/PokemonGo-Bot/pull/3

bearing calculation should use final destination
@mjmadsen
Copy link
Contributor Author

mjmadsen commented Sep 3, 2016

@sohje This should be a very unnoticeable change to look like strafing while walking.

@th3w4y
Copy link
Contributor

th3w4y commented Sep 3, 2016

@sohje so is working now?

screenshot please :)

@sohje
Copy link
Contributor

sohje commented Sep 3, 2016

@th3w4y yeap, with bearing fix works fine. Wait a sec, i'll make pull - edited manually.

@sohje
Copy link
Contributor

sohje commented Sep 3, 2016

hmm, i dont see on the map any strafing ;[

@mjmadsen
Copy link
Contributor Author

mjmadsen commented Sep 3, 2016

@sohje me too

https://s15.postimg.org/4extwtzjf/test4.jpg

  {
    "type": "SpinFort",
    "config": {
      "enabled": true,
      "spin_wait_min": 3,
      "spin_wait_max": 5,
      "daily_spin_limit": 1900
    }
  },
  {
    "type": "MoveToFort",
    "config": {
      "enabled": true,
      "lure_attraction": true,
      "lure_max_distance": 2000,
      "walker": "PolylineWalker",
      "log_interval": 5
    }
  }
],
"map_object_cache_time": 5,
"forts": {
  "avoid_circles": false,
  "max_circle_size": 6,
  "cache_recent_forts": true
},

Turned catching pokemon off for testing

@sohje
Copy link
Contributor

sohje commented Sep 3, 2016

Seems we have to implement some sort of speed acceleration and deceleration.

@th3w4y
Copy link
Contributor

th3w4y commented Sep 3, 2016

@sohje for the polyline... that would be hard...

@sohje
Copy link
Contributor

sohje commented Sep 3, 2016

@th3w4y yeap...

@th3w4y
Copy link
Contributor

th3w4y commented Sep 3, 2016

@sohje i take the challenge then !
i'll need to add a dictionary or something to the Polyline class and modify all the position calculations based on all previous speeds at each previous .get_pos() call.

but i think i can do that if i also refactor the Polyline to use headings and bearings calculation...

will take few days...

@th3w4y
Copy link
Contributor

th3w4y commented Sep 3, 2016

but this does not need to wait for that refactoring...

@BreezeRo
Copy link
Contributor

BreezeRo commented Sep 3, 2016

Tried, testing and working on my end - can confirm speed variance issue mentioned by @sohje

I'm approving this for now, will check in a moment before merging

@solderzzc solderzzc merged commit 6a30984 into PokemonGoF:dev Sep 4, 2016
@th3w4y th3w4y mentioned this pull request Sep 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants