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

Move follow path task config #2044

Merged
merged 1 commit into from
Jul 31, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions configs/config.json.path.example
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,18 @@
"type": "MoveToFort"
},
{
"type": "FollowSpiral"
"type": "FollowPath",
"config": {
"path_mode": "loop",
"path_file": "configs/path.example.json"
}
}
],
"max_steps": 5,
"forts": {
"avoid_circles": true,
"max_circle_size": 50
},
"navigator": {
"type": "path",
"path_mode": "loop",
"path_file": "configs/path.example.json"
},
"websocket_server": false,
"walk": 4.16,
"action_wait_min": 1,
Expand Down
27 changes: 16 additions & 11 deletions pokemongo_bot/cell_workers/follow_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,24 @@
class FollowPath(BaseTask):
def initialize(self):
self.ptr = 0
self._process_config()
self.points = self.load_path()

def _process_config(self):
self.path_file = self.config.get("path_file", None)
self.path_mode = self.config.get("path_mode", "linear")

def load_path(self):
if self.bot.config.navigator_path_file == None:
if self.path_file is None:
raise RuntimeError('You need to specify a path file (json or gpx)')

if self.bot.config.navigator_path_file.endswith('.json'):
return self.load_json(self.bot.config.navigator_path_file)
elif self.bot.config.navigator_path_file.endswith('.gpx'):
return self.load_gpx(self.bot.config.navigator_path_file)
if self.path_file.endswith('.json'):
return self.load_json()
elif self.path_file.endswith('.gpx'):
return self.load_gpx()

def load_json(self, file):
with open(file) as data_file:
def load_json(self):
with open(self.path_file) as data_file:
points=json.load(data_file)
# Replace Verbal Location with lat&lng.
logger.log("Resolving Navigation Paths (GeoLocating Strings)")
Expand All @@ -40,8 +45,8 @@ def load_json(self, file):
def lat_lng_tuple_to_dict(self, tpl):
return {'lat': tpl[0], 'lng': tpl[1]}

def load_gpx(self, file):
gpx_file = open(file, 'r')
def load_gpx(self):
gpx_file = open(self.path_file, 'r')
gpx = gpxpy.parse(gpx_file)

if len(gpx.tracks) == 0:
Expand All @@ -53,7 +58,7 @@ def load_gpx(self, file):
for point in segment.points:
points.append({"lat": point.latitude, "lng": point.longitude})

return points;
return points

def work(self):
point = self.points[self.ptr]
Expand Down Expand Up @@ -85,7 +90,7 @@ def work(self):
if dist <= 1 or (self.bot.config.walk > 0 and is_at_destination):
if (self.ptr + 1) == len(self.points):
self.ptr = 0
if self.bot.config.navigator_path_mode == 'linear':
if self.path_mode == 'linear':
self.points = list(reversed(self.points))
else:
self.ptr += 1
Expand Down