Skip to content

Commit

Permalink
Adding walk_min and walk_max config. Deprecating walk. Making step_wa…
Browse files Browse the repository at this point in the history
…lker speed more random (#3943)

* Switch to walk_min, walk_max

* Switch to walk_min, walk_max

* Switch to walk_min, walk_max

* Switch to walk_min, walk_max

* Switch to walk_min, walk_max

* Switch to walk_min, walk_max

* Switch to walk_min, walk_max

* Switch to walk_min, walk_max

* Switch to walk_min, walk_max

* Switch to walk_min, walk_max

* Switch to walk_min, walk_max

* Switch to walk_min, walk_max

* Switch to walk_min, walk_max

* Switch to walk_min, walk_max

* Fixed error

* Switch to walk_min, walk_max

* Switch to walk_min, walk_max

* Switch to walk_min, walk_max

* Rearranged config and added min/max walk note.

* Fixed error

* Fixed error

* temp fix for min/max walk

* Removed km/hr note

* Added walk back

* Removed km/hr note

* Added walk to deprecated flags

* Changed default value of walk

* Added relative relationship between walk/speed

* Added switch for walk

* Fixed variable reference

* Fix math Remove walk

Adding walk back in made the test files mess up again. Default values for walk_max, walk_min should be fine until folks update their configs.

* Removed add_config for walk

Configs should work fine with default walk_max and walk_min values.

* Changed walk config response
  • Loading branch information
mjmadsen authored and elicwhite committed Aug 15, 2016
1 parent 0937029 commit 603aca6
Show file tree
Hide file tree
Showing 16 changed files with 88 additions and 33 deletions.
3 changes: 2 additions & 1 deletion configs/config.json.cluster.example
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@
"max_circle_size": 50
},
"websocket_server": false,
"walk": 4.16,
"walk_max": 4.16,
"walk_min": 2.16,
"action_wait_min": 1,
"action_wait_max": 4,
"debug": false,
Expand Down
5 changes: 3 additions & 2 deletions configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"location": "SOME_LOCATION",
"gmapkey": "GOOGLE_MAPS_API_KEY",
"encrypt_location": "",
"websocket_server": false,
"tasks": [
{
"type": "HandleSoftBan"
Expand Down Expand Up @@ -108,8 +109,8 @@
"max_circle_size": 50,
"cache_recent_forts": true
},
"websocket_server": false,
"walk": 4.16,
"walk_max": 4.16,
"walk_min": 2.16,
"action_wait_min": 1,
"action_wait_max": 4,
"debug": false,
Expand Down
3 changes: 2 additions & 1 deletion configs/config.json.map.example
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,8 @@
"max_circle_size": 50
},
"websocket_server": false,
"walk": 4.16,
"walk_max": 4.16,
"walk_min": 2.16,
"action_wait_min": 1,
"action_wait_max": 4,
"debug": false,
Expand Down
3 changes: 2 additions & 1 deletion configs/config.json.optimizer.example
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@
"max_circle_size": 50
},
"websocket_server": true,
"walk": 4.16,
"walk_max": 4.16,
"walk_min": 2.16,
"action_wait_min": 1,
"action_wait_max": 4,
"debug": false,
Expand Down
3 changes: 2 additions & 1 deletion configs/config.json.path.example
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@
"max_circle_size": 50
},
"websocket_server": false,
"walk": 4.16,
"walk_max": 4.16,
"walk_min": 2.16,
"action_wait_min": 1,
"action_wait_max": 4,
"debug": false,
Expand Down
3 changes: 2 additions & 1 deletion configs/config.json.pokemon.example
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@
"max_circle_size": 50
},
"websocket_server": false,
"walk": 4.16,
"walk_max": 4.16,
"walk_min": 2.16,
"action_wait_min": 1,
"action_wait_max": 4,
"debug": false,
Expand Down
3 changes: 2 additions & 1 deletion docs/configuration_files.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
| `max_steps` | 5 | The steps around your initial location (DEFAULT 5 mean 25 cells around your location) that will be explored
| `forts.avoid_circles` | False | Set whether the bot should avoid circles |
| `forts.max_circle_size` | 10 | How many forts to keep in ignore list |
| `walk` | 4.16 | Set the walking speed in kilometers per hour. (14 km/h is the maximum speed for egg hatching) |
| `walk_max` | 4.16 | Set the maximum walking speed (1 is about 1.5km/hr)
| `walk_min` | 2.16 | Set the minimum walking speed (1 is about 1.5km/hr)
| `action_wait_min` | 1 | Set the minimum time setting for anti-ban time randomizer
| `action_wait_max` | 4 | Set the maximum time setting for anti-ban time randomizer
| `debug` | false | Let the default value here except if you are developer |
Expand Down
22 changes: 18 additions & 4 deletions pokecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,20 @@ def _json_loader(filename):
add_config(
parser,
load,
short_flag="-w",
long_flag="--walk",
short_flag="-wmax",
long_flag="--walk_max",
help=
"Walk instead of teleport with given speed (meters per second, e.g. 2.5)",
"Walk instead of teleport with given speed",
type=float,
default=2.5
)
add_config(
parser,
load,
short_flag="-wmin",
long_flag="--walk_min",
help=
"Walk instead of teleport with given speed",
type=float,
default=2.5
)
Expand Down Expand Up @@ -521,7 +531,8 @@ def task_configuration_error(flag_name):
""".format(flag_name))

old_flags = ['mode', 'catch_pokemon', 'spin_forts', 'forts_spin', 'hatch_eggs', 'release_pokemon', 'softban_fix',
'longer_eggs_first', 'evolve_speed', 'use_lucky_egg', 'item_filter', 'evolve_all', 'evolve_cp_min', 'max_steps']
'longer_eggs_first', 'evolve_speed', 'use_lucky_egg', 'item_filter', 'evolve_all', 'evolve_cp_min',
'max_steps']
for flag in old_flags:
if flag in load:
task_configuration_error(flag)
Expand All @@ -536,6 +547,9 @@ def task_configuration_error(flag_name):
if "evolve_captured" in load:
logger.warning('The evolve_captured argument is no longer supported. Please use the EvolvePokemon task instead')

if "walk" in load:
logger.warning('The walk argument is no longer supported. Please use the walk_max and walk_min variables instead')

if not (config.location or config.location_cache):
parser.error("Needs either --use-location-cache or --location.")
return None
Expand Down
3 changes: 1 addition & 2 deletions pokemongo_bot/cell_workers/follow_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,9 @@ def work(self):

self.announced = False

if self.bot.config.walk > 0:
if self.bot.config.walk_max > 0:
step_walker = StepWalker(
self.bot,
self.bot.config.walk,
lat,
lng
)
Expand Down
3 changes: 1 addition & 2 deletions pokemongo_bot/cell_workers/follow_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,9 @@ def work(self):
lat = float(point['lat'])
lng = float(point['lng'])

if self.bot.config.walk > 0:
if self.bot.config.walk_max > 0:
step_walker = StepWalker(
self.bot,
self.bot.config.walk,
lat,
lng
)
Expand Down
3 changes: 1 addition & 2 deletions pokemongo_bot/cell_workers/follow_spiral.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,9 @@ def work(self):
point['lng']
)

if self.bot.config.walk > 0:
if self.bot.config.walk_max > 0:
step_walker = StepWalker(
self.bot,
self.bot.config.walk,
point['lat'],
point['lng']
)
Expand Down
1 change: 0 additions & 1 deletion pokemongo_bot/cell_workers/move_to_fort.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ def work(self):

step_walker = StepWalker(
self.bot,
self.bot.config.walk,
lat,
lng
)
Expand Down
1 change: 0 additions & 1 deletion pokemongo_bot/cell_workers/move_to_map_pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,6 @@ def _move_to(self, pokemon):
)
return StepWalker(
self.bot,
self.bot.config.walk,
pokemon['latitude'],
pokemon['longitude']
)
13 changes: 7 additions & 6 deletions pokemongo_bot/step_walker.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from math import sqrt

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


class StepWalker(object):

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

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

self.speed = speed
self.speed = self.bot.config.walk_max - random() * (self.bot.config.walk_max - self.bot.config.walk_min)

self.destLat = dest_lat
self.destLng = dest_lng
self.totalDist = max(1, self.dist)

if speed == 0:
if self.speed == 0:
self.steps = 1
else:
self.steps = (self.dist + 0.0) / (speed + 0.0)
self.steps = (self.dist + 0.0) / (self.speed + 0.0)

if self.dist < speed or int(self.steps) <= 1:
if self.dist < self.speed or int(self.steps) <= 1:
self.dLat = 0
self.dLng = 0
self.magnitude = 0
Expand All @@ -41,7 +42,7 @@ def __init__(self, bot, speed, dest_lat, dest_lng):

def step(self):
if (self.dLat == 0 and self.dLng == 0) or self.dist < self.speed:
self.api.set_position(self.destLat, self.destLng, 0)
self.api.set_position(self.destLat + random_lat_long_delta(), self.destLng + random_lat_long_delta(), 0)
self.bot.event_manager.emit(
'position_update',
sender=self,
Expand Down
6 changes: 4 additions & 2 deletions pokemongo_bot/test/follow_cluster_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ def testWorkAway(self, mock_pokemongo_bot):
ex_forts = pickle.load(forts)
config = {'radius': 50, 'lured': False}
mock_pokemongo_bot.position = (37.396787, -5.994587)
mock_pokemongo_bot.config.walk = 4.16
mock_pokemongo_bot.config.walk_max = 4.16
mock_pokemongo_bot.config.walk_min = 2.16
mock_pokemongo_bot.get_forts.return_value = ex_forts
follow_cluster = FollowCluster(mock_pokemongo_bot, config)

Expand All @@ -30,7 +31,8 @@ def testWorkArrived(self, mock_pokemongo_bot):
ex_forts = pickle.load(forts)
config = {'radius': 50, 'lured': False}
mock_pokemongo_bot.position = (37.39718375014263, -5.9932912500000013)
mock_pokemongo_bot.config.walk = 4.16
mock_pokemongo_bot.config.walk_max = 4.16
mock_pokemongo_bot.config.walk_min = 2.16
mock_pokemongo_bot.get_forts.return_value = ex_forts
follow_cluster = FollowCluster(mock_pokemongo_bot, config)

Expand Down
46 changes: 41 additions & 5 deletions tests/step_walker_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ def tearDown(self):
self.patcherRandomLat.stop()

def test_normalized_distance(self):
sw = StepWalker(self.bot, 1, 0.1, 0.1)
walk_max = self.bot.config.walk_max
walk_min = self.bot.config.walk_min

self.bot.config.walk_max = 1
self.bot.config.walk_min = 1

sw = StepWalker(self.bot, 0.1, 0.1)
self.assertGreater(sw.dLat, 0)
self.assertGreater(sw.dLng, 0)

Expand All @@ -39,8 +45,17 @@ def test_normalized_distance(self):
self.assertTrue(float_equal(self.lat, NORMALIZED_LAT_LNG_DISTANCE_STEP))
self.assertTrue(float_equal(self.lng, NORMALIZED_LAT_LNG_DISTANCE_STEP))

self.bot.config.walk_max = walk_max
self.bot.config.walk_min = walk_min

def test_normalized_distance_times_2(self):
sw = StepWalker(self.bot, 2, 0.1, 0.1)
walk_max = self.bot.config.walk_max
walk_min = self.bot.config.walk_min

self.bot.config.walk_max = 2
self.bot.config.walk_min = 2

sw = StepWalker(self.bot, 0.1, 0.1)
self.assertTrue(sw.dLat > 0)
self.assertTrue(sw.dLng > 0)

Expand All @@ -50,24 +65,45 @@ def test_normalized_distance_times_2(self):
self.assertTrue(float_equal(self.lat, NORMALIZED_LAT_LNG_DISTANCE_STEP * 2))
self.assertTrue(float_equal(self.lng, NORMALIZED_LAT_LNG_DISTANCE_STEP * 2))

self.bot.config.walk_max = walk_max
self.bot.config.walk_min = walk_min

def test_small_distance_same_spot(self):
sw = StepWalker(self.bot, 1, 0, 0)
walk_max = self.bot.config.walk_max
walk_min = self.bot.config.walk_min

self.bot.config.walk_max = 1
self.bot.config.walk_min = 1

sw = StepWalker(self.bot, 0, 0)
self.assertEqual(sw.dLat, 0, 'dLat should be 0')
self.assertEqual(sw.dLng, 0, 'dLng should be 0')

self.assertTrue(sw.step(), 'step should return True')
self.assertTrue(self.lat == self.bot.position[0])
self.assertTrue(self.lng == self.bot.position[1])

self.bot.config.walk_max = walk_max
self.bot.config.walk_min = walk_min

def test_small_distance_small_step(self):
sw = StepWalker(self.bot, 1, 1e-5, 1e-5)
walk_max = self.bot.config.walk_max
walk_min = self.bot.config.walk_min

self.bot.config.walk_max = 1
self.bot.config.walk_min = 1

sw = StepWalker(self.bot, 1e-5, 1e-5)
self.assertEqual(sw.dLat, 0)
self.assertEqual(sw.dLng, 0)

self.bot.config.walk_max = walk_max
self.bot.config.walk_min = walk_min

@unittest.skip('This behavior is To Be Defined')
def test_big_distances(self):
# FIXME currently the StepWalker acts like it won't move if big distances gives as input
# see args below
# with self.assertRaises(RuntimeError):
sw = StepWalker(self.bot, 1, 10, 10)
sw = StepWalker(self.bot, 10, 10)
sw.step() # equals True i.e act like the distance is too short for a step

0 comments on commit 603aca6

Please sign in to comment.