Skip to content

Commit

Permalink
fix divide by zero bug; add distance logging when speed == 0 (#3819)
Browse files Browse the repository at this point in the history
* fix divide by zero bug; add distance logging when speed == 0

* refactor last position distance; add rules to .gitignore

* remove file user_web_catchable that was added by mistake
  • Loading branch information
leanhdaovn authored and TheSavior committed Aug 14, 2016
1 parent d54c256 commit d6c5bb3
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 20 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -109,6 +109,8 @@ web/
data/last-location*.json
data/cells-*.json
data/map-caught-*.json
data/recent-forts-*.json
user_web_catchable

# Multiple config
configs/*
Expand Down
19 changes: 16 additions & 3 deletions pokemongo_bot/cell_workers/follow_path.py
Expand Up @@ -98,6 +98,9 @@ def find_closest_point_idx(self, points):
return return_idx

def work(self):
last_lat = self.bot.api._position_lat
last_lng = self.bot.api._position_lng

point = self.points[self.ptr]
lat = float(point['lat'])
lng = float(point['lng'])
Expand All @@ -115,11 +118,11 @@ def work(self):
is_at_destination = True

else:
self.bot.api.set_position(lat, lng)
self.bot.api.set_position(lat, lng, 0)

dist = distance(
self.bot.api._position_lat,
self.bot.api._position_lng,
last_lat,
last_lng,
lat,
lng
)
Expand All @@ -132,4 +135,14 @@ def work(self):
else:
self.ptr += 1

self.emit_event(
'position_update',
formatted="Teleported from {last_position} to {current_position} ({distance} {distance_unit})",
data={
'last_position': (last_lat, last_lng, 0),
'current_position': (lat, lng, 0),
'distance': dist,
'distance_unit': 'm'
}
)
return [lat, lng]
41 changes: 25 additions & 16 deletions pokemongo_bot/cell_workers/follow_spiral.py
Expand Up @@ -66,9 +66,19 @@ def _generate_spiral(starting_lat, starting_lng, step_size, step_limit):
return coords

def work(self):
last_lat = self.bot.api._position_lat
last_lng = self.bot.api._position_lng

point = self.points[self.ptr]
self.cnt += 1

dist = distance(
last_lat,
last_lng,
point['lat'],
point['lng']
)

if self.bot.config.walk > 0:
step_walker = StepWalker(
self.bot,
Expand All @@ -77,19 +87,12 @@ def work(self):
point['lng']
)

dist = distance(
self.bot.api._position_lat,
self.bot.api._position_lng,
point['lat'],
point['lng']
)

if self.cnt == 1:
self.emit_event(
'position_update',
formatted="Walking from {last_position} to {current_position} ({distance} {distance_unit})",
data={
'last_position': self.bot.position,
'last_position': (last_lat, last_lng, 0),
'current_position': (point['lat'], point['lng'], 0),
'distance': dist,
'distance_unit': 'm'
Expand All @@ -99,14 +102,20 @@ def work(self):
if step_walker.step():
step_walker = None
else:
self.bot.api.set_position(point['lat'], point['lng'])

if distance(
self.bot.api._position_lat,
self.bot.api._position_lng,
point['lat'],
point['lng']
) <= 1 or (self.bot.config.walk > 0 and step_walker == None):
self.bot.api.set_position(point['lat'], point['lng'], 0)

self.emit_event(
'position_update',
formatted="Teleported from {last_position} to {current_position} ({distance} {distance_unit})",
data={
'last_position': (last_lat, last_lng, 0),
'current_position': (point['lat'], point['lng'], 0),
'distance': dist,
'distance_unit': 'm'
}
)

if dist <= 1 or (self.bot.config.walk > 0 and step_walker == None):
if self.ptr + self.direction >= len(self.points) or self.ptr + self.direction <= -1:
self.direction *= -1
if len(self.points) != 1:
Expand Down
5 changes: 4 additions & 1 deletion pokemongo_bot/step_walker.py
Expand Up @@ -25,7 +25,10 @@ def __init__(self, bot, speed, dest_lat, dest_lng):
self.destLng = dest_lng
self.totalDist = max(1, self.dist)

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

if self.dist < speed or int(self.steps) <= 1:
self.dLat = 0
Expand Down

0 comments on commit d6c5bb3

Please sign in to comment.