Skip to content

Commit

Permalink
Loiter new meaning (#5697)
Browse files Browse the repository at this point in the history
* Implement loiter option in FollowPath, loitering meaning not moving at all

* More informative progress logging for FollowPath
  • Loading branch information
janpascal authored and solderzzc committed Nov 11, 2016
1 parent 5439a71 commit c772a1c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
16 changes: 15 additions & 1 deletion docs/configuration_files.md
Original file line number Diff line number Diff line change
Expand Up @@ -883,14 +883,28 @@ This task is an upgrade version of the MoveToMapPokemon task. It will fetch poke
### Description
[[back to top](#table-of-contents)]

Walk to the specified locations loaded from .gpx or .json file. It is highly recommended to use website such as [GPSies](http://www.gpsies.com) which allow you to export your created track in JSON file. Note that you'll have to first convert its JSON file into the format that the bot can understand. See [Example of pier39.json] below for the content. I had created a simple python script to do the conversion.
Walk to the specified locations loaded from .gpx or .json file. It is highly
recommended to use website such as [GPSies](http://www.gpsies.com) which allow
you to export your created track in JSON file. Note that you'll have to first
convert its JSON file into the format that the bot can understand. See [Example
of pier39.json] below for the content. I had created a simple python script to
do the conversion.

The `location` fields in the `.json` file can also contain a street address. In
this case the `location` is interpreted by the Google Maps API.

The json file can contain for each point an optional `wander` field. This
indicated the number of seconds the bot should wander after reaching the point.
During this time, the next Task in the configuration file is executed, e.g. a
MoveToFort task. This allows the bot to walk around the waypoint looking for
forts for a limited time.

The `loiter` field, also optional for each point in the json file, works
similarly to the `wander` field. The difference is that with `loiter` the
next `Task` in the configuration file is /not/ executed, meaning the bot
will wait, without moving, at the point in the json file with the `loiter`
option.

### Options
[[back to top](#table-of-contents)]
* `path_mode` - linear, loop, single
Expand Down
27 changes: 17 additions & 10 deletions pokemongo_bot/cell_workers/follow_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
from datetime import datetime as dt, timedelta

STATUS_MOVING = 0
STATUS_WANDERING = 1
STATUS_FINISHED = 2
STATUS_LOITERING = 1
STATUS_WANDERING = 2
STATUS_FINISHED = 3

class FollowPath(BaseTask):
SUPPORTED_TASK_API_VERSION = 1
Expand All @@ -28,7 +29,7 @@ def initialize(self):
self._process_config()
self.points = self.load_path()
self.status = STATUS_MOVING
self.wander_end_time = 0
self.waiting_end_time = 0
self.distance_unit = self.bot.config.distance_unit
self.append_unit = False

Expand Down Expand Up @@ -143,8 +144,11 @@ def work(self):
if self.status == STATUS_FINISHED:
return WorkerResult.SUCCESS

if self.status == STATUS_WANDERING and time.time() < self.wander_end_time:
return WorkerResult.SUCCESS
if time.time() < self.waiting_end_time:
if self.status == STATUS_WANDERING:
return WorkerResult.SUCCESS
elif self.status == STATUS_LOITERING:
return WorkerResult.RUNNING

last_lat, last_lng, last_alt = self.bot.position

Expand Down Expand Up @@ -184,19 +188,22 @@ def work(self):
formatted="Walking from {last_position} to {current_position}, distance left: ({distance} {distance_unit}) ..",
data={
'last_position': (last_lat, last_lng, last_alt),
'current_position': (lat, lng, alt),
'current_position': point["location"],
'distance': format_dist(dist,self.distance_unit,self.append_unit),
'distance_unit': self.distance_unit
}
)

if (self.bot.config.walk_min > 0 and is_at_destination) or (self.status == STATUS_WANDERING and time.time() >= self.wander_end_time):
if "loiter" in point:
self.logger.warning("'loiter' is obsolete, please change to 'wander' in {}".format(self.path_file))
if (self.bot.config.walk_min > 0 and is_at_destination) or (self.status in [STATUS_WANDERING, STATUS_LOITERING] and time.time() >= self.waiting_end_time):
if "loiter" in point and self.status != STATUS_LOITERING:
self.logger.info("Loitering for {} seconds...".format(point["loiter"]))
self.status = STATUS_LOITERING
self.waiting_end_time = time.time() + point["loiter"]
return WorkerResult.RUNNING
if "wander" in point and self.status != STATUS_WANDERING:
self.logger.info("Wandering for {} seconds...".format(point["wander"]))
self.status = STATUS_WANDERING
self.wander_end_time = time.time() + point["wander"]
self.waiting_end_time = time.time() + point["wander"]
return WorkerResult.SUCCESS
if (self.ptr + 1) == len(self.points):
if self.path_mode == 'single':
Expand Down

0 comments on commit c772a1c

Please sign in to comment.