From ac3c3ec1aafb71434573ac5d3d752b7c99b4b417 Mon Sep 17 00:00:00 2001 From: Jaap Moolenaar Date: Tue, 9 Aug 2016 14:03:22 +0200 Subject: [PATCH 1/4] Upstream update and merge, with path_startmode configuration --- CONTRIBUTORS.md | 1 + configs/config.json.path.example | 1 + pokemongo_bot/cell_workers/follow_path.py | 43 +++++++++++++++++++++-- 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index fd219fe470..c8183d5345 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -57,3 +57,4 @@ * nikofil * bigkraig * nikhil-pandey + * JaapMoolenaar diff --git a/configs/config.json.path.example b/configs/config.json.path.example index dec7457246..90da67328f 100644 --- a/configs/config.json.path.example +++ b/configs/config.json.path.example @@ -60,6 +60,7 @@ "type": "FollowPath", "config": { "path_mode": "loop", + "path_startmode": "first", "path_file": "configs/path.example.json" } } diff --git a/pokemongo_bot/cell_workers/follow_path.py b/pokemongo_bot/cell_workers/follow_path.py index 6e183ed1d7..074d123f96 100644 --- a/pokemongo_bot/cell_workers/follow_path.py +++ b/pokemongo_bot/cell_workers/follow_path.py @@ -3,7 +3,8 @@ import gpxpy import gpxpy.gpx import json -from pokemongo_bot.base_task import BaseTask +import pokemongo_bot.logger as logger +from pokemongo_bot.cell_workers.base_task import BaseTask from pokemongo_bot.cell_workers.utils import distance, i2f, format_dist from pokemongo_bot.human_behaviour import sleep from pokemongo_bot.step_walker import StepWalker @@ -14,13 +15,19 @@ class FollowPath(BaseTask): SUPPORTED_TASK_API_VERSION = 1 def initialize(self): - self.ptr = 0 self._process_config() self.points = self.load_path() + if self.path_startmode == 'closest': + self.ptr = self.find_closest_point_idx(self.points) + + else: + self.ptr = 0 + def _process_config(self): self.path_file = self.config.get("path_file", None) self.path_mode = self.config.get("path_mode", "linear") + self.path_startmode = self.config.get("path_startmode", "first") def load_path(self): if self.path_file is None: @@ -67,6 +74,36 @@ def load_gpx(self): return points + def find_closest_point_idx(self, points): + logger.log("Finding closest point in path") + + return_idx = 0 + min_distance = float("inf"); + for index in range(len(points)): + point = points[index] + botlat = self.bot.api._position_lat + botlng = self.bot.api._position_lng + lat = float(point['lat']) + lng = float(point['lng']) + + if self.bot.config.debug: + logger.log("Checking if point {}, {} is closest to {}, {}".format(lat, lng, botlat, botlng)) + + dist = distance( + botlat, + botlng, + lat, + lng + ) + + if dist < min_distance: + min_distance = dist + return_idx = index + + logger.log("Chose closest point in path #{}: {}, {}".format(return_idx+1, points[return_idx]['lat'], points[return_idx]['lng'])) + + return return_idx + def work(self): point = self.points[self.ptr] lat = float(point['lat']) @@ -102,4 +139,6 @@ def work(self): else: self.ptr += 1 + logger.log("Moving to next point in path #{}".format(self.ptr+1)) + return [lat, lng] From 9ac270d8117a79fcb9f8c04bf741a1f15f64a3b2 Mon Sep 17 00:00:00 2001 From: Jaap Moolenaar Date: Tue, 9 Aug 2016 14:28:37 +0200 Subject: [PATCH 2/4] Removed logger and fixed base task path --- pokemongo_bot/cell_workers/follow_path.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pokemongo_bot/cell_workers/follow_path.py b/pokemongo_bot/cell_workers/follow_path.py index 074d123f96..164ce33868 100644 --- a/pokemongo_bot/cell_workers/follow_path.py +++ b/pokemongo_bot/cell_workers/follow_path.py @@ -3,8 +3,7 @@ import gpxpy import gpxpy.gpx import json -import pokemongo_bot.logger as logger -from pokemongo_bot.cell_workers.base_task import BaseTask +from pokemongo_bot.base_task import BaseTask from pokemongo_bot.cell_workers.utils import distance, i2f, format_dist from pokemongo_bot.human_behaviour import sleep from pokemongo_bot.step_walker import StepWalker @@ -139,6 +138,4 @@ def work(self): else: self.ptr += 1 - logger.log("Moving to next point in path #{}".format(self.ptr+1)) - return [lat, lng] From 01346fb2487191b6efd9053ab4b90307e914da09 Mon Sep 17 00:00:00 2001 From: Jaap Moolenaar Date: Tue, 9 Aug 2016 15:22:32 +0200 Subject: [PATCH 3/4] As per request, path_startmode is now path_start_mode --- configs/config.json.path.example | 2 +- pokemongo_bot/cell_workers/follow_path.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/configs/config.json.path.example b/configs/config.json.path.example index 90da67328f..6f7b04c305 100644 --- a/configs/config.json.path.example +++ b/configs/config.json.path.example @@ -60,7 +60,7 @@ "type": "FollowPath", "config": { "path_mode": "loop", - "path_startmode": "first", + "path_start_mode": "first", "path_file": "configs/path.example.json" } } diff --git a/pokemongo_bot/cell_workers/follow_path.py b/pokemongo_bot/cell_workers/follow_path.py index 164ce33868..7955753734 100644 --- a/pokemongo_bot/cell_workers/follow_path.py +++ b/pokemongo_bot/cell_workers/follow_path.py @@ -17,7 +17,7 @@ def initialize(self): self._process_config() self.points = self.load_path() - if self.path_startmode == 'closest': + if self.path_start_mode == 'closest': self.ptr = self.find_closest_point_idx(self.points) else: @@ -26,7 +26,7 @@ def initialize(self): def _process_config(self): self.path_file = self.config.get("path_file", None) self.path_mode = self.config.get("path_mode", "linear") - self.path_startmode = self.config.get("path_startmode", "first") + self.path_start_mode = self.config.get("path_start_mode", "first") def load_path(self): if self.path_file is None: From 55633e80744f6ed3ad5ec3f26d6a9a00dddd7af1 Mon Sep 17 00:00:00 2001 From: Jaap Moolenaar Date: Tue, 9 Aug 2016 15:30:45 +0200 Subject: [PATCH 4/4] Removed all logging --- pokemongo_bot/cell_workers/follow_path.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/pokemongo_bot/cell_workers/follow_path.py b/pokemongo_bot/cell_workers/follow_path.py index 7955753734..1532695bd8 100644 --- a/pokemongo_bot/cell_workers/follow_path.py +++ b/pokemongo_bot/cell_workers/follow_path.py @@ -74,7 +74,6 @@ def load_gpx(self): return points def find_closest_point_idx(self, points): - logger.log("Finding closest point in path") return_idx = 0 min_distance = float("inf"); @@ -84,9 +83,6 @@ def find_closest_point_idx(self, points): botlng = self.bot.api._position_lng lat = float(point['lat']) lng = float(point['lng']) - - if self.bot.config.debug: - logger.log("Checking if point {}, {} is closest to {}, {}".format(lat, lng, botlat, botlng)) dist = distance( botlat, @@ -99,8 +95,6 @@ def find_closest_point_idx(self, points): min_distance = dist return_idx = index - logger.log("Chose closest point in path #{}: {}, {}".format(return_idx+1, points[return_idx]['lat'], points[return_idx]['lng'])) - return return_idx def work(self):