Skip to content

Commit

Permalink
Merge branch 'walker' of https://github.com/Anakin5/PokemonGo-Bot int…
Browse files Browse the repository at this point in the history
…o Anakin5-walker
  • Loading branch information
th3w4y committed Sep 8, 2016
2 parents b66fc88 + 5caf16b commit eb3861e
Show file tree
Hide file tree
Showing 11 changed files with 588 additions and 338 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pickle binary
31 changes: 13 additions & 18 deletions pokemongo_bot/cell_workers/camp_fort.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import math
import time

Expand Down Expand Up @@ -59,12 +62,14 @@ def work(self):
if self.config_moving_time > 0:
return WorkerResult.SUCCESS

forts = self.get_forts()

if self.destination is None:
forts = self.get_forts()
forts_clusters = self.get_forts_clusters(forts)

if len(forts_clusters) > 0:
self.destination = forts_clusters[0]
self.walker = PolylineWalker(self.bot, self.destination[0], self.destination[1])
self.logger.info("New destination at %s meters: %s forts, %s lured.", int(self.destination[4]), self.destination[3], self.destination[2])
else:
# forts = [f for f in forts if f.get("cooldown_complete_timestamp_ms", 0) < now * 1000]
Expand All @@ -77,24 +82,14 @@ def work(self):
else:
self.last_position_update = now

if self.stay_until >= now:
lat = self.destination[0] + random_lat_long_delta() / 5
lon = self.destination[1] + random_lat_long_delta() / 5
alt = self.walker.pol_alt + random_alt_delta() / 2
self.bot.api.set_position(lat, lon, alt)
else:
self.walker = PolylineWalker(self.bot, self.destination[0], self.destination[1])
self.walker.step()
circle = (self.destination[0], self.destination[1], Constants.MAX_DISTANCE_FORT_IS_REACHABLE)
cluster = self.get_cluster(forts, circle)

dst = distance(self.bot.position[0], self.bot.position[1], self.destination[0], self.destination[1])

if dst < 1:
forts = self.get_forts()
circle = (self.destination[0], self.destination[1], Constants.MAX_DISTANCE_FORT_IS_REACHABLE)
cluster = self.get_cluster(forts, circle)

self.logger.info("Arrived at destination: %s forts, %s lured.", cluster[3], cluster[2])
self.stay_until = now + self.config_camping_time
if self.stay_until >= now:
self.walker.step(speed=0)
elif self.walker.step():
self.logger.info("Arrived at destination: %s forts, %s lured.", cluster[3], cluster[2])
self.stay_until = now + self.config_camping_time

return WorkerResult.RUNNING

Expand Down
4 changes: 2 additions & 2 deletions pokemongo_bot/test/follow_cluster_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def testWorkAway(self, mock_pokemongo_bot):
with open(forts_path, 'rb') as forts:
ex_forts = pickle.load(forts)
config = {'radius': 50, 'lured': False}
mock_pokemongo_bot.position = (37.396787, -5.994587)
mock_pokemongo_bot.position = (37.396787, -5.994587, 0)
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
Expand All @@ -30,7 +30,7 @@ def testWorkArrived(self, mock_pokemongo_bot):
with open(forts_path, 'rb') as forts:
ex_forts = pickle.load(forts)
config = {'radius': 50, 'lured': False}
mock_pokemongo_bot.position = (37.39718375014263, -5.9932912500000013)
mock_pokemongo_bot.position = (37.39718375014263, -5.9932912500000013, 0)
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
Expand Down
21 changes: 0 additions & 21 deletions pokemongo_bot/test/polyline_generator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,6 @@ def test_first_point(self):
def test_last_point(self):
self.assertEqual(self.polyline._points[-1], ex_dest)

def test_pos_and_alt_at_time_mock_start(self):
self.polyline.set_speed(0)
lat, lng = self.polyline.get_pos()
self.assertAlmostEqual(lat, ex_orig[0], places=5)
self.assertAlmostEqual(lng, ex_orig[1], places=5)
self.assertEquals(self.polyline.get_alt(), 429.5892333984375)

def test_pos_and_alt_at_time_mock_seven_sec(self):
self.polyline.set_speed(self.polyline.speed*7)
lat, lng = self.polyline.get_pos()
self.assertAlmostEqual(lat, 47.17048865309, places=5)
self.assertAlmostEqual(lng, 8.516689707618, places=5)
self.assertAlmostEqual(self.polyline.get_alt(), 428.65, places=1)

def test_pos_and_alt_at_time_mock_end(self):
self.polyline.set_speed(300)
lat, lng = self.polyline.get_pos()
self.assertAlmostEqual(lat, ex_dest[0], places=5)
self.assertAlmostEqual(lng, ex_dest[1], places=5)
self.assertEquals(self.polyline.get_alt(), 437.9155883789062)

def test_nr_of_elevations_returned(self):
total_seconds = self.polyline.get_total_distance() / self.polyline.speed
self.assertAlmostEqual(total_seconds, ex_nr_samples, places=0)
Expand Down
Loading

0 comments on commit eb3861e

Please sign in to comment.