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 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="Di chuyen toi pokestop {fort_name} - {distance}", data=fort_event_data ) else: self.emit_event( 'moving_to_fort', formatted="Di chuyen toi pokestop {fort_name} - {distance}", data=fort_event_data ) step_walker = StepWalker( self.bot, self.bot.config.walk, lat, lng ) if not step_walker.step(): return WorkerResult.RUNNING self.emit_event( 'arrived_at_fort', formatted='Arrived at fort.' ) return WorkerResult.SUCCESS
def work(self): last_lat = self.bot.api._position_lat last_lng = self.bot.api._position_lng point = self.points[self.ptr] self.cnt += 1 dist = distance( last_lat, last_lng, point['lat'], point['lng'] ) if self.bot.config.walk_max > 0: step_walker = StepWalker( self.bot, 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': (last_lat, last_lng, 0), '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'], 0) self.emit_event( 'position_update', formatted="Teleported from {last_position} to {current_position} ({distance} {distance_unit})", data={ 'last_position': (last_lat, last_lng, 0), 'current_position': (point['lat'], point['lng'], 0), 'distance': dist, 'distance_unit': 'm' } ) if dist <= 1 or (self.bot.config.walk_min > 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 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 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): forts = self.bot.get_forts() log_lure_avail_str = '' log_lured_str = '' if self.lured: log_lured_str = 'lured ' lured_forts = [x for x in forts if 'lure_info' in x] if len(lured_forts) > 0: self.dest = find_biggest_cluster(self.radius, lured_forts, 'lure_info') 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: log_str = log_lure_avail_str + 'Move to destiny. ' + str(cnt) + ' ' + log_lured_str + \ 'pokestops will be in range of ' + str(self.radius) + 'm. Arrive in ' \ + str(distance(self.bot.position[0], self.bot.position[1], lat, lng)) + 'm.' logger.log(log_str) self.announced = False if self.bot.config.walk > 0: step_walker = StepWalker( self.bot, self.bot.config.walk, 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: log_str = 'Arrived at destiny. ' + str(cnt) + ' pokestops are in range of ' \ + str(self.radius) + 'm.' logger.log(log_str) self.announced = True else: lat = self.bot.position[0] lng = self.bot.position[1] return [lat, lng]
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 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="Walking from {last_position} to {current_position} ({distance} {distance_unit})", data={ 'last_position': (last_lat, last_lng, 0), 'current_position': (lat, lng, 0), 'distance': dist, 'distance_unit': 'm' } ) return [lat, lng]
def test_small_distance_same_spot(self): walk_max = self.bot.config.walk_max walk_min = self.bot.config.walk_min self.bot.config.walk_max = 1 self.bot.config.walk_min = 1 sw = StepWalker(self.bot, 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]) self.bot.config.walk_max = walk_max self.bot.config.walk_min = walk_min
def work(self): # check for pokeballs (excluding masterball) pokeballs = self.bot.item_inventory_count(1) superballs = self.bot.item_inventory_count(2) ultraballs = self.bot.item_inventory_count(3) if (pokeballs + superballs + ultraballs) < 1: return WorkerResult.SUCCESS self.update_map_location() self.dump_caught_pokemon() pokemon_list = self.get_pokemon_from_map() pokemon_list.sort(key=lambda x: x['dist']) if self.config['mode'] == 'priority': pokemon_list.sort(key=lambda x: x['priority'], reverse=True) if self.config['prioritize_vips']: pokemon_list.sort(key=lambda x: x['is_vip'], reverse=True) if len(pokemon_list) < 1: return WorkerResult.SUCCESS pokemon = pokemon_list[0] # if we only have ultraballs and the target is not a vip don't snipe/walk if (pokeballs + superballs) < 1 and not pokemon['is_vip']: return WorkerResult.SUCCESS if self.config['snipe']: return self.snipe(pokemon) now = int(time.time()) logger.log('Moving towards {}, {} left ({})'.format(pokemon['name'], format_dist(pokemon['dist'], self.unit), format_time(pokemon['disappear_time'] - now))) step_walker = StepWalker( self.bot, self.bot.config.walk, pokemon['latitude'], pokemon['longitude'] ) if not step_walker.step(): return WorkerResult.RUNNING logger.log('Arrived at {}'.format(pokemon['name'])) self.add_caught(pokemon) return WorkerResult.SUCCESS
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: logger.log( 'Walking from ' + str((self.bot.api._position_lat, self.bot.api._position_lng)) + " to " + str([point['lat'], point['lng']]) + " " + format_dist(dist, self.bot.config.distance_unit)) 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 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').encode('utf8', 'replace') 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: if self.is_attracted() > 0: add_str = ' (attraction of lure {})'.format(format_dist(self.lure_distance, unit)) else: add_str = '' logger.log('Moving towards fort {}, {} left{}'.format(fort_name, format_dist(dist, unit), add_str)) step_walker = StepWalker( self.bot, self.bot.config.walk, lat, lng ) if not step_walker.step(): return WorkerResult.RUNNING logger.log('Arrived at pokestop.') return WorkerResult.SUCCESS
def test_normalized_distance(self): walk_max = self.bot.config.walk_max walk_min = self.bot.config.walk_min self.bot.config.walk_max = 1 self.bot.config.walk_min = 1 sw = StepWalker(self.bot, 0.1, 0.1) self.assertGreater(sw.dLat, 0) self.assertGreater(sw.dLng, 0) stayInPlace = sw.step() self.assertFalse(stayInPlace) self.assertTrue(float_equal(self.lat, NORMALIZED_LAT_LNG_DISTANCE_STEP)) self.assertTrue(float_equal(self.lng, NORMALIZED_LAT_LNG_DISTANCE_STEP)) self.bot.config.walk_max = walk_max self.bot.config.walk_min = walk_min
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": "{}".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, self.bot.config.walk, lat, lng) if not step_walker.step(): return WorkerResult.RUNNING self.emit_event("arrived_at_fort", formatted="Arrived at fort.") return WorkerResult.SUCCESS
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): 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 work(self): if not self.should_run(): return WorkerResult.SUCCESS nearest_fort = self.get_nearest_fort() if nearest_fort == None: return WorkerResult.SUCCESS lat = nearest_fort['latitude'] lng = nearest_fort['longitude'] fortID = nearest_fort['id'] unit = self.config.distance_unit # Unit to use when printing formatted distance dist = distance( self.position[0], self.position[1], lat, lng ) if dist > Constants.MAX_DISTANCE_FORT_IS_REACHABLE: logger.log('Moving towards fort {}, {} left'.format(fortID, format_dist(dist, unit))) step_walker = StepWalker( self.bot, self.config.walk, lat, lng ) if not step_walker.step(): return WorkerResult.RUNNING logger.log('Arrived at pokestop.') return WorkerResult.SUCCESS
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): forts = self.bot.get_forts() log_lure_avail_str = '' log_lured_str = '' if self.lured: log_lured_str = 'lured ' lured_forts = [x for x in forts if 'lure_info' in x] if len(lured_forts) > 0: self.dest = find_biggest_cluster(self.radius, lured_forts, 'lure_info') 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 destiny {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(distance(self.bot.position[0], self.bot.position[1], lat, lng)) } ) 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. {forts} are in a range of {radius}m radius.", data={ 'forts': str(cnt), 'radius': self.radius } ) self.announced = True else: lat = self.bot.position[0] lng = self.bot.position[1] 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]