Esempio n. 1
0
 def navigator(cells):  # pylint: disable=unused-argument
     destinations = [
         Destination(51.504601, -0.075964, 10),
         Destination(51.505356, -0.075481, 11)
     ]
     for destination in destinations:
         yield destination
    def test_set_steps():
        destination = Destination(1,
                                  2,
                                  0,
                                  name="test_destination",
                                  exact_location=False)

        destination.set_steps([(1, 2, 0), (2, 3, 0), (3, 4, 0)])

        assert destination.get_step_count() == 3
    def test_set_steps():
        destination = Destination(1, 2, 0, name="test_destination", exact_location=False)

        destination.set_steps([
            (1, 2, 0),
            (2, 3, 0),
            (3, 4, 0)
        ])

        assert destination.get_step_count() == 3
Esempio n. 4
0
    def test_step():
        config = create_core_test_config({
            "movement": {
                "walk_speed": 5,
                "path_finder": "direct",
                "distance_unit": "m"
            }
        })
        api_wrapper = create_mock_api_wrapper(config)
        path_finder = DirectPathFinder(config)
        logger = Mock()
        logger.log = Mock(return_value=None)
        stepper = Stepper(config, api_wrapper, path_finder, logger)
        stepper.start(51.50451, -0.07607, 10)

        destination = Destination(51.506000,
                                  -0.075049,
                                  11,
                                  name="Test Destination",
                                  exact_location=False)
        steps = [(51.504778, -0.075838, 10), (51.505092, -0.075650, 11),
                 (51.505436, -0.075446, 11)]
        destination.set_steps(steps)

        pgo = api_wrapper.get_api()

        # This route is being walked: http://www.darrinward.com/lat-long/?id=2163411
        # pre-calculated distance is 17.8 meters
        pointer = 0
        for _ in stepper.step(destination):
            target_lat, target_lng, target_alt = steps[pointer]
            assert stepper.current_lat == target_lat
            assert stepper.current_lng == target_lng
            assert stepper.current_alt == target_alt

            bot_lat, bot_lng, bot_alt = pgo.get_position()
            assert bot_lat == target_lat
            assert bot_lng == target_lng
            assert bot_alt == target_alt

            pointer += 1

        assert pointer == 3

        bot_lat, bot_lng, bot_alt = pgo.get_position()
        assert bot_lat == 51.505436
        assert bot_lng == -0.075446
        assert bot_alt == 11
        assert stepper.current_lat == 51.505436
        assert stepper.current_lng == -0.075446
        assert stepper.current_alt == 11
Esempio n. 5
0
    def test_step():
        config = create_core_test_config({
            "movement": {
                "walk_speed": 5,
                "path_finder": "direct",
                "distance_unit": "m"
            }
        })
        api_wrapper = create_mock_api_wrapper(config)
        path_finder = DirectPathFinder(config)
        logger = Mock()
        logger.log = Mock(return_value=None)
        stepper = Stepper(config, api_wrapper, path_finder, logger)
        stepper.start(51.50451, -0.07607, 10)

        destination = Destination(51.506000, -0.075049, 11, name="Test Destination", exact_location=False)
        steps = [
            (51.504778, -0.075838, 10),
            (51.505092, -0.075650, 11),
            (51.505436, -0.075446, 11)
        ]
        destination.set_steps(steps)

        pgo = api_wrapper.get_api()

        # This route is being walked: http://www.darrinward.com/lat-long/?id=2163411
        # pre-calculated distance is 17.8 meters
        pointer = 0
        for _ in stepper.step(destination):
            target_lat, target_lng, target_alt = steps[pointer]
            assert stepper.current_lat == target_lat
            assert stepper.current_lng == target_lng
            assert stepper.current_alt == target_alt

            bot_lat, bot_lng, bot_alt = pgo.get_position()
            assert bot_lat == target_lat
            assert bot_lng == target_lng
            assert bot_alt == target_alt

            pointer += 1

        assert pointer == 3

        bot_lat, bot_lng, bot_alt = pgo.get_position()
        assert bot_lat == 51.505436
        assert bot_lng == -0.075446
        assert bot_alt == 11
        assert stepper.current_lat == 51.505436
        assert stepper.current_lng == -0.075446
        assert stepper.current_alt == 11
Esempio n. 6
0
    def test_step():
        calls = []
        bot = create_mock_bot({
            "walk": 5,
            "path_finder": "direct",
            "distance_unit": "m"
        })
        bot.position = (51.50451, -0.07607, 10)
        bot.fire = Mock(return_value=None)
        bot.heartbeat = Mock(return_value=None)

        destination = Destination(51.506000, -0.075049, 11, name="Test Destination", exact_location=False)
        steps = [
            (51.504778, -0.075838, 10),
            (51.505092, -0.075650, 11),
            (51.505436, -0.075446, 11)
        ]
        destination.set_steps(steps)

        stepper = Stepper(bot)
        stepper.start()

        pgo = bot.api_wrapper._api  # pylint: disable=protected-access

        # This route is being walked: http://www.darrinward.com/lat-long/?id=2163411
        calls.append(call("walking_started", coords=(51.506000, -0.075049, 11)))
        pointer = 0
        for step in stepper.step(destination):
            calls.append(call("position_updated", coordinates=step))

            target_lat, target_lng, target_alt = steps[pointer]
            assert stepper.current_lat == target_lat
            assert stepper.current_lng == target_lng
            assert stepper.current_alt == target_alt

            bot_lat, bot_lng, bot_alt = pgo.get_position()
            assert bot_lat == target_lat
            assert bot_lng == target_lng
            assert bot_alt == target_alt

            pointer += 1

        calls.append(call("walking_finished", coords=(51.506000, -0.075049, 11)))

        assert bot.fire.call_count == 5
        bot.fire.assert_has_calls(calls, any_order=False)

        assert bot.heartbeat.call_count == 3
Esempio n. 7
0
    def test_step():
        calls = []
        bot = create_mock_bot({
            "walk": 5,
            "path_finder": "direct",
            "distance_unit": "m"
        })
        bot.position = (51.50451, -0.07607, 10)
        bot.fire = Mock(return_value=None)
        bot.heartbeat = Mock(return_value=None)

        destination = Destination(51.50436, -0.07616, 11, name="Test Destination", exact_location=False)
        steps = [
            (51.50442, -0.07612, 10),
            (51.50448, -0.07609, 11),
            (51.50436, -0.07616, 11)
        ]
        destination.set_steps(steps)

        stepper = Stepper(bot)
        stepper.start()

        pgo = bot.api_wrapper._api  # pylint: disable=protected-access

        calls.append(call("walking_started", coords=(51.50436, -0.07616, 11)))
        # pre-calculated distance is 17.8 meters
        pointer = 0
        for step in stepper.step(destination):
            calls.append(call("position_updated", coordinates=step))

            target_lat, target_lng, target_alt = steps[pointer]
            assert stepper.current_lat == target_lat
            assert stepper.current_lng == target_lng
            assert stepper.current_alt == target_alt

            bot_lat, bot_lng, bot_alt = pgo.get_position()
            assert bot_lat == target_lat
            assert bot_lng == target_lng
            assert bot_alt == target_alt

            pointer += 1

        calls.append(call("walking_finished", coords=(51.50436, -0.07616, 11)))

        assert bot.fire.call_count == 5
        bot.fire.assert_has_calls(calls, any_order=False)

        assert bot.heartbeat.call_count == 3
    def test_step():
        destination = Destination(1, 2, 0, name="test_destination", exact_location=False)

        steps = [
            (1, 2, 0),
            (2, 3, 0),
            (3, 4, 0)
        ]
        destination.set_steps(steps)

        step_values = []
        for step in destination.step():
            assert step in steps
            step_values.append(step)

        assert len(step_values) == 3
    def test_step():
        destination = Destination(1,
                                  2,
                                  0,
                                  name="test_destination",
                                  exact_location=False)

        steps = [(1, 2, 0), (2, 3, 0), (3, 4, 0)]
        destination.set_steps(steps)

        step_values = []
        for step in destination.step():
            assert step in steps
            step_values.append(step)

        assert len(step_values) == 3
Esempio n. 10
0
    def test_step_already_near_fort():
        calls = []
        bot = create_mock_bot({
            "walk": 5,
            "path_finder": "direct",
            "distance_unit": "m"
        })
        bot.position = (51.50451, -0.07607, 10)
        bot.fire = Mock(return_value=None)
        bot.heartbeat = Mock(return_value=None)

        destination = Destination(51.50436, -0.07616, 11, name="Test Destination", exact_location=False)
        steps = [
            (51.50442, -0.07612, 10),
            (51.50448, -0.07609, 11),
            (51.50436, -0.07616, 11)
        ]
        destination.set_steps(steps)

        stepper = Stepper(bot)
        stepper.start()

        pgo = bot.api_wrapper._api  # pylint: disable=protected-access

        # This route is being walked: http://www.darrinward.com/lat-long/?id=2163408
        calls.append(call("walking_started", coords=(51.50436, -0.07616, 11)))
        pointer = 0
        for _ in stepper.step(destination):
            pointer += 1

        assert pointer == 0

        bot_lat, bot_lng, bot_alt = pgo.get_position()
        assert bot_lat == 51.50451
        assert bot_lng == -0.07607
        assert bot_alt == 10
        assert stepper.current_lat == 51.50451
        assert stepper.current_lng == -0.07607
        assert stepper.current_alt == 10

        calls.append(call("walking_finished", coords=(51.50436, -0.07616, 11)))

        assert bot.fire.call_count == 2
        bot.fire.assert_has_calls(calls, any_order=False)

        assert bot.heartbeat.call_count == 0
Esempio n. 11
0
    def test_step_exact():
        destination = Destination(4, 5, 6, name="test_destination", exact_location=True)

        steps = [
            (1, 2, 0),
            (2, 3, 0),
            (3, 4, 0)
        ]
        destination.set_steps(steps)

        step_values = []
        for step in destination.step():
            if len(step_values) < 3:
                assert step in steps
            else:
                assert step == (4, 5, 6)
            step_values.append(step)

        assert len(step_values) == 4
Esempio n. 12
0
    def test_step_exact():
        destination = Destination(4,
                                  5,
                                  6,
                                  name="test_destination",
                                  exact_location=True)

        steps = [(1, 2, 0), (2, 3, 0), (3, 4, 0)]
        destination.set_steps(steps)

        step_values = []
        for step in destination.step():
            if len(step_values) < 3:
                assert step in steps
            else:
                assert step == (4, 5, 6)
            step_values.append(step)

        assert len(step_values) == 4
Esempio n. 13
0
    def test_step_already_near_fort():
        calls = []
        config = create_core_test_config({
            "movement": {
                "walk_speed": 5,
                "path_finder": "direct",
                "distance_unit": "m"
            }
        })
        api_wrapper = create_mock_api_wrapper(config)
        path_finder = DirectPathFinder(config)

        destination = Destination(51.50436,
                                  -0.07616,
                                  11,
                                  name="Test Destination",
                                  exact_location=False)
        steps = [(51.50442, -0.07612, 10), (51.50448, -0.07609, 11),
                 (51.50436, -0.07616, 11)]
        destination.set_steps(steps)

        logger = Mock()
        logger.log = Mock(return_value=None)
        stepper = Stepper(config, api_wrapper, path_finder, logger)
        stepper.start(51.50451, -0.07607, 10)

        pgo = api_wrapper.get_api()

        # This route is being walked: http://www.darrinward.com/lat-long/?id=2163408
        calls.append(call("walking_started", coords=(51.50436, -0.07616, 11)))
        pointer = 0
        for _ in stepper.step(destination):
            pointer += 1

        assert pointer == 0

        bot_lat, bot_lng, bot_alt = pgo.get_position()
        assert bot_lat == 51.50451
        assert bot_lng == -0.07607
        assert bot_alt == 10
        assert stepper.current_lat == 51.50451
        assert stepper.current_lng == -0.07607
        assert stepper.current_alt == 10
Esempio n. 14
0
    def test_step_already_near_fort():
        calls = []
        config = create_core_test_config({
            "movement": {
                "walk_speed": 5,
                "path_finder": "direct",
                "distance_unit": "m"
            }
        })
        api_wrapper = create_mock_api_wrapper(config)
        path_finder = DirectPathFinder(config)

        destination = Destination(51.50436, -0.07616, 11, name="Test Destination", exact_location=False)
        steps = [
            (51.50442, -0.07612, 10),
            (51.50448, -0.07609, 11),
            (51.50436, -0.07616, 11)
        ]
        destination.set_steps(steps)

        logger = Mock()
        logger.log = Mock(return_value=None)
        stepper = Stepper(config, api_wrapper, path_finder, logger)
        stepper.start(51.50451, -0.07607, 10)

        pgo = api_wrapper.get_api()

        # This route is being walked: http://www.darrinward.com/lat-long/?id=2163408
        calls.append(call("walking_started", coords=(51.50436, -0.07616, 11)))
        pointer = 0
        for _ in stepper.step(destination):
            pointer += 1

        assert pointer == 0

        bot_lat, bot_lng, bot_alt = pgo.get_position()
        assert bot_lat == 51.50451
        assert bot_lng == -0.07607
        assert bot_alt == 10
        assert stepper.current_lat == 51.50451
        assert stepper.current_lng == -0.07607
        assert stepper.current_alt == 10
Esempio n. 15
0
 def test_init():
     destination = Destination(1,
                               2,
                               0,
                               name="test_destination",
                               exact_location=False)
     assert destination.target_lat == 1
     assert destination.target_lng == 2
     assert destination.target_alt == 0
     assert destination.name == "test_destination"
     assert destination.exact_location is False
Esempio n. 16
0
    def navigate(self, map_cells):
        # type: (List[Cell]) -> List[Direction]
        if not len(self.camping_sites):
            current_lat, current_lng, _ = self.api_wrapper.get_position()
            self.camping_sites.append((current_lat, current_lng))

        try:
            lat, lng = self.camping_sites[self.pointer]
            position = (lat, lng, 0.0)

            yield Destination(*position, name="Camping position at {},{}".format(lat, lng), exact_location=True)

            sleep(5)
        except IndexError:
            self.logger.log("No campsite location found", color="red", prefix="Camper")
Esempio n. 17
0
    def navigate(self, map_cells):
        # type: (List[Cell]) -> None
        try:
            camp_site = self.camping_sites[self.pointer]

            lat, lng = camp_site
            position = (lat, lng, 0.0)

            yield Destination(*position,
                              name="camping position at {},{}".format(
                                  lat, lng),
                              exact_location=True)

            sleep(5)

        except KeyError:
            logger.log("[#] No campsite location found", color="red")
Esempio n. 18
0
    def navigate(self, map_cells):
        # type: (List[Cell]) -> List[Destination]
        while self.pointer < len(self.waypoints):
            waypoint = self.waypoints[self.pointer]

            if waypoint is None:
                self.pointer += 1
                continue

            if len(waypoint) == 2:
                waypoint.append(0.0)

            lat, lng, alt = waypoint
            yield Destination(lat, lng, alt, name="Waypoint at {},{}".format(lat, lng))

            self.pointer += 1

        self.pointer = 0
Esempio n. 19
0
    def navigate(self, map_cells):
        # type: (List[Cell]) -> None

        for cell in map_cells:
            pokestops = [
                pokestop for pokestop in cell.pokestops
                if pokestop.latitude is not None
                and pokestop.longitude is not None
            ]
            # gyms = [gym for gym in cell['forts'] if 'gym_points' in gym]

            # Sort all by distance from current pos- eventually this should
            # build graph & A* it
            pokestops.sort(
                key=lambda x: distance(self.stepper.current_lat, self.stepper.
                                       current_lng, x.latitude, x.longitude))

            for fort in pokestops:

                response_dict = self.api_wrapper.fort_details(
                    fort_id=fort.fort_id,
                    latitude=fort.latitude,
                    longitude=fort.longitude).call()

                if response_dict is None:
                    fort_name = fort.fort_id
                else:
                    fort_name = response_dict["fort"].fort_name

                yield Destination(fort.latitude,
                                  fort.longitude,
                                  0.0,
                                  name="PokeStop \"{}\"".format(fort_name))

                self.api_wrapper.player_update(latitude=fort.latitude,
                                               longitude=fort.longitude)
                sleep(2)
Esempio n. 20
0
    def navigate(self, map_cells):
        # type: (List[Cell]) -> List([Destination])

        for cell in map_cells:
            pokestops = [
                pokestop for pokestop in cell.pokestops
                if pokestop.latitude is not None
                and pokestop.longitude is not None
            ]
            # gyms = [gym for gym in cell['forts'] if 'gym_points' in gym]

            # Sort all by distance from current pos- eventually this should
            # build graph & A* it
            current_lat, current_lng, _ = self.api_wrapper.get_position()
            pokestops.sort(key=lambda x, lat=current_lat, lng=current_lng:
                           distance(lat, lng, x.latitude, x.longitude))

            for fort in pokestops:

                response_dict = self.api_wrapper.fort_details(
                    fort_id=fort.fort_id,
                    latitude=fort.latitude,
                    longitude=fort.longitude)

                if response_dict is None:
                    fort_name = fort.fort_id
                else:
                    fort_name = response_dict["fort"].fort_name

                if isinstance(fort_name, bytes):
                    fort_name = fort_name.decode()

                yield Destination(fort.latitude,
                                  fort.longitude,
                                  0.0,
                                  name="PokeStop \"{}\"".format(fort_name))
Esempio n. 21
0
    def navigate(self, map_cells):
        # type: (List[Cell]) -> List[Destination]

        yield Destination(*self.position, name="Manual destination", exact_location=True)