def test_big_distances(self): # FIXME currently the StepWalker acts like it won't move if big distances gives as input # see args below # with self.assertRaises(RuntimeError): sw = StepWalker(self.bot, 1, 10, 10) sw.step( ) # equals True i.e act like the distance is too short for a step
def work(self): point = self.points[self.ptr] lat = float(point['lat']) lng = float(point['lng']) if self.bot.config.walk > 0: step_walker = StepWalker(self.bot, self.bot.config.walk, lat, lng) is_at_destination = False if step_walker.step(): is_at_destination = True else: self.bot.api.set_position(lat, lng) dist = distance(self.bot.api._position_lat, self.bot.api._position_lng, lat, lng) 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.path_mode == 'linear': self.points = list(reversed(self.points)) else: self.ptr += 1 return [lat, lng]
def test_small_distance_same_spot(self): sw = StepWalker(self.bot, 1, 0, 0) self.assertEqual(sw.dLat, 0, 'dLat should be 0') self.assertEqual(sw.dLng, 0, 'dLng should be 0') self.assertTrue(sw.step(), 'step should return True') self.assertTrue(self.lat == self.bot.position[0]) self.assertTrue(self.lng == self.bot.position[1])
def work(self): if not self.should_run(): return WorkerResult.SUCCESS nearest_fort = self.get_nearest_fort() if nearest_fort is None: return WorkerResult.SUCCESS lat = nearest_fort['latitude'] lng = nearest_fort['longitude'] fortID = nearest_fort['id'] details = fort_details(self.bot, fortID, lat, lng) fort_name = details.get('name', 'Unknown') unit = self.bot.config.distance_unit # Unit to use when printing formatted distance dist = distance( self.bot.position[0], self.bot.position[1], lat, lng ) if dist > Constants.MAX_DISTANCE_FORT_IS_REACHABLE: fort_event_data = { 'fort_name': u"{}".format(fort_name), 'distance': format_dist(dist, unit), } if self.is_attracted() > 0: fort_event_data.update(lure_distance=format_dist(self.lure_distance, unit)) self.emit_event( 'moving_to_lured_fort', formatted="Moving towards pokestop {fort_name} - {distance} (attraction of lure {lure_distance})", data=fort_event_data ) else: self.emit_event( 'moving_to_fort', formatted="Moving towards pokestop {fort_name} - {distance}", data=fort_event_data ) step_walker = StepWalker( self.bot, lat, lng ) if not step_walker.step(): return WorkerResult.RUNNING self.emit_event( 'arrived_at_fort', formatted='Arrived at fort.' ) return WorkerResult.SUCCESS
def test_normalized_distance_times_2(self): sw = StepWalker(self.bot, 2, 0.1, 0.1) self.assertTrue(sw.dLat > 0) self.assertTrue(sw.dLng > 0) stayInPlace = sw.step() self.assertFalse(stayInPlace) self.assertTrue( float_equal(self.lat, NORMALIZED_LAT_LNG_DISTANCE_STEP * 2)) self.assertTrue( float_equal(self.lng, NORMALIZED_LAT_LNG_DISTANCE_STEP * 2))
def work(self): point = self.points[self.ptr] self.cnt += 1 if self.bot.config.walk > 0: step_walker = StepWalker( self.bot, self.bot.config.walk, point['lat'], point['lng'] ) dist = distance( self.bot.api._position_lat, self.bot.api._position_lng, point['lat'], point['lng'] ) if self.cnt == 1: self.emit_event( 'position_update', formatted="Walking from {last_position} to {current_position} ({distance} {distance_unit})", data={ 'last_position': self.bot.position, 'current_position': (point['lat'], point['lng'], 0), 'distance': dist, 'distance_unit': 'm' } ) if step_walker.step(): step_walker = None else: self.bot.api.set_position(point['lat'], point['lng']) if distance( self.bot.api._position_lat, self.bot.api._position_lng, point['lat'], point['lng'] ) <= 1 or (self.bot.config.walk > 0 and step_walker == None): if self.ptr + self.direction >= len(self.points) or self.ptr + self.direction <= -1: self.direction *= -1 if len(self.points) != 1: self.ptr += self.direction else: self.ptr = 0 self.cnt = 0 return [point['lat'], point['lng']]
def _move_to(self, pokemon): """Moves trainer towards a Pokemon. Args: pokemon: Pokemon to move to. Returns: StepWalker """ now = int(time.time()) self.emit_event( 'move_to_map_pokemon_move_towards', formatted=('Moving towards {poke_name}, {poke_dist}, left (' '{disappears_in})'), data=self._pokemon_event_data(pokemon)) return StepWalker(self.bot, self.bot.config.walk, pokemon['latitude'], pokemon['longitude'])
def work(self): last_lat = self.bot.api._position_lat last_lng = self.bot.api._position_lng point = self.points[self.ptr] lat = float(point['lat']) lng = float(point['lng']) if self.bot.config.walk_max > 0: step_walker = StepWalker(self.bot, lat, lng) is_at_destination = False if step_walker.step(): is_at_destination = True else: self.bot.api.set_position(lat, lng, 0) dist = distance(last_lat, last_lng, lat, lng) if dist <= 1 or (self.bot.config.walk_min > 0 and is_at_destination): if (self.ptr + 1) == len(self.points): self.ptr = 0 if self.path_mode == 'linear': self.points = list(reversed(self.points)) else: self.ptr += 1 self.emit_event( 'position_update', formatted= "Walk to {last_position} now at {current_position}, distance left: ({distance} {distance_unit}) ..", data={ 'last_position': (lat, lng, 0), 'current_position': (last_lat, last_lng, 0), 'distance': dist, 'distance_unit': 'm' }) return [lat, lng]
def work(self): forts = self.bot.get_forts() log_lure_avail_str = '' log_lured_str = '' if self.lured: lured_forts = [x for x in forts if 'active_fort_modifier' in x] if len(lured_forts) > 0: log_lured_str = 'lured ' self.dest = find_biggest_cluster(self.radius, lured_forts, '9QM=') else: log_lure_avail_str = 'No lured pokestops in vicinity. Search for normal ones instead. ' self.dest = find_biggest_cluster(self.radius, forts) else: self.dest = find_biggest_cluster(self.radius, forts) if self.dest is not None: lat = self.dest['latitude'] lng = self.dest['longitude'] cnt = self.dest['num_points'] if not self.is_at_destination: msg = log_lure_avail_str + ( "Move to cluster: {num_points} {forts} " "pokestops will be in range of {radius}. Walking {distance}m." ) self.emit_event('found_cluster', formatted=msg, data={ 'num_points': cnt, 'forts': log_lured_str, 'radius': str(self.radius), 'distance': str( round( distance(self.bot.position[0], self.bot.position[1], lat, lng), 2)) }) self.announced = False if self.bot.config.walk_max > 0: step_walker = StepWalker(self.bot, lat, lng) self.is_at_destination = False if step_walker.step(): self.is_at_destination = True else: self.bot.api.set_position(lat, lng) elif not self.announced: self.emit_event( 'arrived_at_cluster', formatted= "Arrived at cluster. {num_points} {forts} pokestops are in a range of {radius}m radius.", data={ 'num_points': cnt, 'forts': log_lured_str, 'radius': self.radius }) self.announced = True else: lat = self.bot.position[0] lng = self.bot.position[1] return [lat, lng]
def test_small_distance_small_step(self): sw = StepWalker(self.bot, 1, 1e-5, 1e-5) self.assertEqual(sw.dLat, 0) self.assertEqual(sw.dLng, 0)