internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: PokemonGoF/PokemonGo-Bot

Issue:
Starting bot in sleep cycle
### Actual

When starting the bot while it should be in a sleep cycle, it waits for start of next sleep cycle.
### Expected

Bot should 'continue' sleeping and wake up on normal time.



Discussion:
Is this the intended behavior?

No, shouldn't be, sleep is sleep no matter when the bot starts.

@OniZakuma does it sleep after 1 cycle of the bot (i.e a couple of seconds), or does it wait until the next day when the sleep cycle should start (i.e. 20 hours or so)

No, it waits the full x-hours till next cycle starts.

Sleep schedule may need to be updated after https://github.com/PokemonGoF/PokemonGo-Bot/pull/2956/commits/081d90de32de84810120a50b238b70093e51ef17


Resolving patch:
diff --git a/pokemongo_bot/cell_workers/sleep_schedule.py b/pokemongo_bot/cell_workers/sleep_schedule.py
--- a/pokemongo_bot/cell_workers/sleep_schedule.py
+++ b/pokemongo_bot/cell_workers/sleep_schedule.py
@@ -36,9 +36,10 @@ def initialize(self):
         # self.bot.event_manager.register_event('sleeper_scheduled', parameters=('datetime',))
         self._process_config()
         self._schedule_next_sleep()
+        self._calculate_current_sleep()
 
     def work(self):
-        if datetime.now() >= self._next_sleep:
+        if self._should_sleep_now():
             self._sleep()
             self._schedule_next_sleep()
             self.bot.login()
@@ -71,6 +72,20 @@ def _schedule_next_sleep(self):
             }
         )
 
+    def _calculate_current_sleep(self):
+        self._current_sleep = self._next_sleep - timedelta(days=1)
+        current_duration = self._get_next_duration()
+        self._current_end = self._current_sleep + timedelta(seconds = current_duration)
+
+    def _should_sleep_now(self):
+        if datetime.now() >= self._next_sleep:
+            return True
+        if datetime.now() >= self._current_sleep and datetime.now() < self._current_end:
+            self._next_duration = (self._current_end - datetime.now()).total_seconds()
+            return True
+
+        return False
+
     def _get_next_sleep_schedule(self):
         now = datetime.now() + self.SCHEDULING_MARGIN
         next_time = now.replace(hour=self.time.hour, minute=self.time.minute)


Test patch:
Repository: PokemonGoF/PokemonGo-Bot

Issue:
Show what kind of egg is being hatched.
So instead of this: 
[IncubateEggs] [INFO] [next_egg_incubates] Next egg incubates in 1.71 km
I'd like to see something like:
[IncubateEggs] [INFO] [next_egg_incubates] Next egg (5 km) incubates in 1.71 km



Discussion:
I had thought this existed at one point but maybe I imagined it


Resolving patch:
diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py
--- a/pokemongo_bot/__init__.py
+++ b/pokemongo_bot/__init__.py
@@ -381,7 +381,7 @@ def _register_events(self):
         )
         self.event_manager.register_event(
             'next_egg_incubates',
-            parameters=('distance_in_km',)
+            parameters=('km_needed', 'distance_in_km',)
         )
         self.event_manager.register_event('incubator_already_used')
         self.event_manager.register_event('egg_already_incubating')
diff --git a/pokemongo_bot/cell_workers/incubate_eggs.py b/pokemongo_bot/cell_workers/incubate_eggs.py
--- a/pokemongo_bot/cell_workers/incubate_eggs.py
+++ b/pokemongo_bot/cell_workers/incubate_eggs.py
@@ -34,8 +34,9 @@ def work(self):
             else:
                 self.emit_event(
                     'next_egg_incubates',
-                    formatted='Next egg incubates in {distance_in_km:.2f} km',
+                    formatted='Next egg ({km_needed} km) incubates in {distance_in_km:.2f} km',
                     data={
+                        'km_needed': self.used_incubators[0]['km_needed'],
                         'distance_in_km': km_left
                     }
                 )
@@ -118,9 +119,12 @@ def _check_inventory(self, lookup_ids=[]):
                     incubators = [incubators]
                 for incubator in incubators:
                     if 'pokemon_id' in incubator:
+                        start_km = incubator.get('start_km_walked', 9001)
+                        km_walked = incubator.get('target_km_walked', 9001)
                         temp_used_incubators.append({
                             "id": incubator.get('id', -1),
-                            "km": incubator.get('target_km_walked', 9001)
+                            "km": km_walked,
+                            "km_needed": (km_walked - start_km)
                         })
                     else:
                         temp_ready_incubators.append({


Test patch:
Repository: PokemonGoF/PokemonGo-Bot

Issue:
Request: Please add "log_stats" to colored_logging handler
### Short Description

Please add "log_stats" to colored_logging handler
### Possible solution

The following line can be added to colored_logging_handler.py
### _'log_stats': 'magenta',_
### How it would help others

It will be easy to track the progress with so many lines printed on the console between 2 status logs.



Discussion:

Resolving patch:
diff --git a/pokemongo_bot/event_handlers/colored_logging_handler.py b/pokemongo_bot/event_handlers/colored_logging_handler.py
--- a/pokemongo_bot/event_handlers/colored_logging_handler.py
+++ b/pokemongo_bot/event_handlers/colored_logging_handler.py
@@ -55,6 +55,8 @@ class ColoredLoggingHandler(EventHandler):
         'unknown_spin_result':               'red',
         'unset_pokemon_nickname':            'red',
         'vip_pokemon':                       'red',
+        'log_stats':                         'magenta',
+        'show_inventory':                    'magenta',
 
         # event names for 'white' still here to remember that these events are already determined its color.
         'arrived_at_cluster':                'white',


Test patch:
Repository: PokemonGoF/PokemonGo-Bot

Issue:
When running on dev the version reported is not accurate
When you run the dev branch it says

`2016-08-18 21:19:01,214 [       cli] [INFO] PokemonGO Bot v1.0`

Without specifying the commit SHA.

Not sure what devs or other people thinks, but in my opinion this should have the commit that is running.

I'm asking because I'm running with docker, and i'm not sure if I've to rebuild my container after I made a `git pull`  



Discussion:

Resolving patch:
diff --git a/pokecli.py b/pokecli.py
--- a/pokecli.py
+++ b/pokecli.py
@@ -34,6 +34,8 @@
 import sys
 import time
 import signal
+import string
+import subprocess
 from datetime import timedelta
 from getpass import getpass
 from pgoapi.exceptions import NotLoggedInException, ServerSideRequestThrottlingException, ServerBusyOrOfflineException
@@ -70,8 +72,17 @@ def handle_sigint(*args):
         raise SIGINTRecieved
     signal.signal(signal.SIGINT, handle_sigint)
 
+    def get_commit_hash():
+        try:
+            hash = subprocess.check_output(['git', 'rev-parse', 'HEAD'], stderr=subprocess.STDOUT)[:-1] 
+
+            return hash if all(c in string.hexdigits for c in hash) else "not found"
+        except:
+            return "not found"
+
     try:
         logger.info('PokemonGO Bot v1.0')
+        logger.info('commit: ' + get_commit_hash())
         sys.stdout = codecs.getwriter('utf8')(sys.stdout)
         sys.stderr = codecs.getwriter('utf8')(sys.stderr)
 


Test patch:
Repository: PokemonGoF/PokemonGo-Bot

Issue:
Create small random change of position to resume the Bot after some time off
When you stop the Bot (by more than X hours for example) does not return the exact same position. It is strange to stay a few hours without running the bot and it resumes in the same previous position.



Discussion:

Resolving patch:
diff --git a/pokemongo_bot/cell_workers/sleep_schedule.py b/pokemongo_bot/cell_workers/sleep_schedule.py
--- a/pokemongo_bot/cell_workers/sleep_schedule.py
+++ b/pokemongo_bot/cell_workers/sleep_schedule.py
@@ -18,6 +18,7 @@ class SleepSchedule(BaseTask):
           "duration":"5:30",
           "time_random_offset": "00:30",
           "duration_random_offset": "00:30"
+          "wake_up_at_location": ""
         }
     }
     time: (HH:MM) local time that the bot should sleep
@@ -26,7 +27,8 @@ class SleepSchedule(BaseTask):
                         for this example the possible start time is 11:30-12:30
     duration_random_offset: (HH:MM) random offset of duration of sleep
                         for this example the possible duration is 5:00-6:00
-    """
+    wake_up_at_location: (lat, long | lat, long, alt | "") the location at which the bot wake up 
+    *Note that an empty string ("") will not change the location*.    """
     SUPPORTED_TASK_API_VERSION = 1
 
     LOG_INTERVAL_SECONDS = 600
@@ -42,6 +44,9 @@ def work(self):
         if self._should_sleep_now():
             self._sleep()
             self._schedule_next_sleep()
+            wake_up_at_location = self.config.get("wake_up_at_location", "")
+            if wake_up_at_location:
+                self.bot.api.set_position(self.wake_up_at_location[0],self.wake_up_at_location[1],self.wake_up_at_location[2])
             self.bot.login()
 
     def _process_config(self):
@@ -60,6 +65,21 @@ def _process_config(self):
         self.duration_random_offset = int(
             timedelta(
                 hours=duration_random_offset.hour, minutes=duration_random_offset.minute).total_seconds())
+        
+        wake_up_at_location = self.config.get("wake_up_at_location", "")
+        if wake_up_at_location:
+            try:
+                wake_up_at_location = wake_up_at_location.split(',',2)               
+                lat=float(wake_up_at_location[0])
+                lng=float(wake_up_at_location[1])
+                if len(wake_up_at_location) == 3:
+                    alt=float(wake_up_at_location[2])
+                else:
+                    alt = uniform(self.bot.config.alt_min, self.bot.config.alt_max)
+            except ValueError:
+                raise ValueError('SleepSchedule wake_up_at_location, parsing error in location') #TODO there must be a more elegant way to do it...
+
+            self.wake_up_at_location = [lat, lng, alt]
 
     def _schedule_next_sleep(self):
         self._next_sleep = self._get_next_sleep_schedule()


Test patch:
Repository: PokemonGoF/PokemonGo-Bot

Issue:
No usable pokeballs found
When "No usable pokeballs found" happens, the bot just hanging there and not tried to move and spin the fort.



Discussion:
What commit are you on?

commit 601e21dbf464e2b3631d6a58e508b26af7fd470f


Resolving patch:
diff --git a/pokemongo_bot/cell_workers/pokemon_catch_worker.py b/pokemongo_bot/cell_workers/pokemon_catch_worker.py
--- a/pokemongo_bot/cell_workers/pokemon_catch_worker.py
+++ b/pokemongo_bot/cell_workers/pokemon_catch_worker.py
@@ -355,7 +355,7 @@ def _do_catch(self, pokemon, encounter_id, catch_rate_by_ball, is_vip=False):
                     maximum_ball = ITEM_ULTRABALL
                     continue
                 else:
-                    break
+                    return WorkerResult.ERROR
 
             # check future ball count
             num_next_balls = 0


Test patch:
Repository: PokemonGoF/PokemonGo-Bot

Issue:
No usable pokeballs found
When "No usable pokeballs found" happens, the bot just hanging there and not tried to move and spin the fort.



Discussion:
What commit are you on?

commit 601e21dbf464e2b3631d6a58e508b26af7fd470f


Resolving patch:
diff --git a/pokemongo_bot/cell_workers/catch_pokemon.py b/pokemongo_bot/cell_workers/catch_pokemon.py
--- a/pokemongo_bot/cell_workers/catch_pokemon.py
+++ b/pokemongo_bot/cell_workers/catch_pokemon.py
@@ -31,8 +31,10 @@ def work(self):
         num_pokemon = len(pokemon)
         if num_pokemon > 0:
             pokemon = self.sort_pokemon(pokemon)
-            self.catch_pokemon(pokemon[0])
-            if num_pokemon > 1:
+            
+            if self.catch_pokemon(pokemon[0]) == WorkerResult.ERROR:
+                return WorkerResult.ERROR
+            elif num_pokemon > 1:
                 return WorkerResult.RUNNING
 
         return WorkerResult.SUCCESS
diff --git a/pokemongo_bot/cell_workers/pokemon_catch_worker.py b/pokemongo_bot/cell_workers/pokemon_catch_worker.py
--- a/pokemongo_bot/cell_workers/pokemon_catch_worker.py
+++ b/pokemongo_bot/cell_workers/pokemon_catch_worker.py
@@ -111,9 +111,9 @@ def work(self, response_dict=None):
         if inventory.items().get(ITEM_POKEBALL).count < 1:
             if inventory.items().get(ITEM_GREATBALL).count < 1:
                 if inventory.items().get(ITEM_ULTRABALL).count < 1:
-                    return WorkerResult.SUCCESS
+                    return WorkerResult.ERROR
                 elif (not is_vip) and inventory.items().get(ITEM_ULTRABALL).count <= self.min_ultraball_to_keep:
-                    return WorkerResult.SUCCESS
+                    return WorkerResult.ERROR
 
         # log encounter
         self.emit_event(


Test patch:
Repository: PokemonGoF/PokemonGo-Bot

Issue:
Add option to separate usage of incubator unbreakable from breakable (2)
## Short Description:
- The 2, 5 and 10km eggs can be dispatched between either the infinite or the breakables incubators.

I wasn't able to test this option in real-game, since well... My bot is sleeping. From the tests I ran, the option should behave as excepted.
## Fixes/Resolves/Closes (please use correct syntax):
- Closes #3503
- Closes #3552 

Not sure why it failed before (cf #4556)



Discussion:
@supercourgette, thanks for your PR! By analyzing the annotation information on this pull request, we identified @mjmadsen, @DeXtroTip and @TheSavior to be potential reviewers

CI passed this time. Woot. 

This is a great feature! Just a quick question. Will the default values on line 27 and 28 of incubate_eggs.py break old configs which doesn't have the new fields?


Resolving patch:
diff --git a/pokemongo_bot/cell_workers/incubate_eggs.py b/pokemongo_bot/cell_workers/incubate_eggs.py
--- a/pokemongo_bot/cell_workers/incubate_eggs.py
+++ b/pokemongo_bot/cell_workers/incubate_eggs.py
@@ -24,8 +24,8 @@ def _process_config(self):
         self.longer_eggs_first = self.config.get("longer_eggs_first", True)
         self.min_interval = self.config.get('min_interval', 120)
         
-        self.breakable_incubator = self.config.get("breakable", [])
-        self.infinite_incubator = self.config.get("infinite", [])
+        self.breakable_incubator = self.config.get("breakable", [2,5,10])
+        self.infinite_incubator = self.config.get("infinite", [2,5,10])
     
     def work(self):
         try:
@@ -265,4 +265,4 @@ def _compute_next_update(self):
         :return: Nothing.
         :rtype: None
         """
-        self.next_update = datetime.now() + timedelta(seconds=self.min_interval)
\ No newline at end of file
+        self.next_update = datetime.now() + timedelta(seconds=self.min_interval)


Test patch:
Repository: PokemonGoF/PokemonGo-Bot

Issue:
[Feature Request] Randomize Evolve Speed
### Short Description

Randomize Evolve Speed
### Possible solution

"max_evolve_speed": 40,
"min_evolve_speed": 20,
### How it would help others

could make bot detection harder and bot more realistic.



Discussion:

Resolving patch:
diff --git a/pokemongo_bot/cell_workers/evolve_pokemon.py b/pokemongo_bot/cell_workers/evolve_pokemon.py
--- a/pokemongo_bot/cell_workers/evolve_pokemon.py
+++ b/pokemongo_bot/cell_workers/evolve_pokemon.py
@@ -1,3 +1,5 @@
+from random import uniform
+
 from pokemongo_bot import inventory
 from pokemongo_bot.human_behaviour import sleep
 from pokemongo_bot.inventory import Pokemon
@@ -14,7 +16,8 @@ def __init__(self, bot, config):
     def initialize(self):
         self.api = self.bot.api
         self.evolve_all = self.config.get('evolve_all', [])
-        self.evolve_speed = self.config.get('evolve_speed', 2)
+        self.min_evolve_speed = self.config.get('min_evolve_speed', 25)
+        self.max_evolve_speed = self.config.get('max_evolve_speed', 30)
         self.first_evolve_by = self.config.get('first_evolve_by', 'cp')
         self.evolve_above_cp = self.config.get('evolve_above_cp', 500)
         self.evolve_above_iv = self.config.get('evolve_above_iv', 0.8)
@@ -26,6 +29,9 @@ def _validate_config(self):
         if isinstance(self.evolve_all, basestring):
             self.evolve_all = [str(pokemon_name).strip() for pokemon_name in self.evolve_all.split(',')]
 
+        if 'evolve_speed' in self.config:
+            self.logger.warning("evolve_speed is deprecated, please use instead 'min_evolve_speed' and 'max_evolved_speed'.")
+
     def work(self):
         if not self._should_run():
             return
@@ -128,7 +134,7 @@ def _execute_pokemon_evolve(self, pokemon, cache):
             new_pokemon = inventory.Pokemon(evolution)
             inventory.pokemons().add(new_pokemon)
 
-            sleep(self.evolve_speed)
+            sleep(uniform(self.min_evolve_speed, self.max_evolve_speed))
             evolve_result = True
         else:
             # cache pokemons we can't evolve. Less server calls


Test patch:
Repository: PokemonGoF/PokemonGo-Bot

Issue:
Ignore Pokemon based on candy
### Short Description

<!-- Tell us a short description of your request -->

Ignore Pokemon based on the number of candies
### Possible solution

<!-- Tell us how you would include it in the current bot -->

```
candy = inventory.candies(True).get(pokemon.pokemon_id)
if candy > candy_threshold:
    ignore()
else:
    catch()
```

in config.json:

```
"catch": {
      "any": {
            "candy_threshold": 200
      }
 },
```
### How it would help others

<!-- Tell us how you think it would help yourself and other users -->

It will benefit collection-only users. Keep account exp/h low.

<!-- ==========END OF FEATURE REQUEST SECTION========== -->



Discussion:
It will look more like human too.


Resolving patch:
diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py
--- a/pokemongo_bot/__init__.py
+++ b/pokemongo_bot/__init__.py
@@ -164,6 +164,21 @@ def _register_events(self):
         self.event_manager.register_event('set_start_location')
         self.event_manager.register_event('load_cached_location')
         self.event_manager.register_event('location_cache_ignored')
+
+        #  ignore candy above threshold
+        self.event_manager.register_event(
+            'ignore_candy_above_thresold',
+            parameters=(
+                'name',
+                'amount',
+                'threshold'
+            )
+        )
+
+
+
+
+
         self.event_manager.register_event(
             'position_update',
             parameters=(
diff --git a/pokemongo_bot/cell_workers/pokemon_catch_worker.py b/pokemongo_bot/cell_workers/pokemon_catch_worker.py
--- a/pokemongo_bot/cell_workers/pokemon_catch_worker.py
+++ b/pokemongo_bot/cell_workers/pokemon_catch_worker.py
@@ -221,6 +221,23 @@ def _pokemon_matches_config(self, config, pokemon, default_logic='and'):
             'iv': False,
         }
 
+        candies = inventory.candies().get(pokemon.pokemon_id).quantity
+        threshold = pokemon_config.get('candy_threshold', -1 )
+        if( threshold > 0 and candies >= threshold  ):
+            self.emit_event(
+                'ignore_candy_above_thresold',
+                level='info',
+                formatted='Amount of candies for {name} is {amount}, greater than threshold {threshold}',
+                data={
+                    'name': pokemon.name,
+                    'amount': candies ,
+                    'threshold' : threshold
+                }
+            )
+            return False
+
+
+
         if pokemon_config.get('never_catch', False):
             return False
 


Test patch:
Repository: PokemonGoF/PokemonGo-Bot

Issue:
Evolving all pokemon after update
### Expected Behavior

Only evolve pokemon in the evolve_list
### Actual Behavior

Evolving all pokemon
### Your FULL config.json (remove your username, password, gmapkey and any other private info)

http://pastebin.com/xZgs68YY
### Output when issue occurred

[2016-08-30 10:20:09] [pokemon_evolved] Evolved Staryu [IV 0.82] [CP 514] [34 candies] [+1000 xp]
### Steps to Reproduce

<!-- Tell us the steps you have taken to reproduce the issue -->
### Other Information

OS: Mac osX
Branch: Dev
Git Commit: d7cf5558e56c9ca9611cec1f228365541f25f2bd
Python Version: Python 2.7.12



Discussion:
Hm. Must have messed up the logic somewhere. I'll take a gander in a bit. 

Thanks, just disabled "evolvePokemon" for now. Thanks for all te great work!

Did you see it evolve pokemon that **were** in the list? If not I bet I filtered backwards. 

Sorry, quickly stopped the bot since it allready evolved a Dragonair and Staryu that were cleary not on my list, to prevent further damage. 


Resolving patch:
diff --git a/pokemongo_bot/cell_workers/evolve_pokemon.py b/pokemongo_bot/cell_workers/evolve_pokemon.py
--- a/pokemongo_bot/cell_workers/evolve_pokemon.py
+++ b/pokemongo_bot/cell_workers/evolve_pokemon.py
@@ -45,6 +45,9 @@ def work(self):
 
         filtered_list = self._sort_and_filter()
 
+        if (len(self.evolve_list) > 0) and self.evolve_list[0] != 'all':
+            filtered_list = filter(lambda x: x.name in self.evolve_list, filtered_list)
+
         if (len(self.donot_evolve_list) > 0) and self.donot_evolve_list[0] != 'none':
             filtered_list = filter(lambda pokemon: pokemon.name not in donot_evolve_list, filtered_list)
 


Test patch:
Repository: PokemonGoF/PokemonGo-Bot

Issue:
[BUG] Error in Telegram: "AttributeError: 'module' object has no attribute 'now'"
### Expected Behavior

<!-- Tell us what you expect to happen -->

Bot running with Telegram enabled
### Actual Behavior

<!-- Tell us what is happening -->

Bot not starting due to error message
### Your FULL config.json (remove your username, password, gmapkey and any other private info)

<!-- Provide your FULL config file, feel free to use services such as pastebin.com to reduce clutter -->

http://pastebin.com/5nQC2ceh
### Output when issue occurred

<!-- Provide a reasonable sample from your output log (not just the error message), feel free to use services such as pastebin.com to reduce clutter -->

Traceback (most recent call last):
  File "pokecli.py", line 781, in <module>
    main()
  File "pokecli.py", line 128, in main
    bot = start_bot(bot, config)
  File "pokecli.py", line 88, in start_bot
    initialize_task(bot, config)
  File "pokecli.py", line 79, in initialize_task
    tree = TreeConfigBuilder(bot, config.raw_tasks).build()
  File "/PokemonGo-Bot/pokemongo_bot/tree_config_builder.py", line 79, in build
    instance = worker(self.bot, task_config)
  File "/PokemonGo-Bot/pokemongo_bot/base_task.py", line 23, in **init**
    self.initialize()
  File "/PokemonGo-Bot/pokemongo_bot/cell_workers/telegram_task.py", line 42, in initialize
    self.next_job=datetime.now() + timedelta(seconds=self.min_interval)
AttributeError: 'module' object has no attribute 'now'
### Steps to Reproduce

<!-- Tell us the steps you have taken to reproduce the issue -->

Start the bot with the above config.
### Other Information

OS: CentOS

<!-- Tell us what Operating system you're using --> 

Branch: dev

<!-- dev or master --> 

Git Commit: 9e81c6ed90d79e181599ec7f0a0cfa2ecd4d09f5

<!-- run 'git log -n 1 --pretty=format:"%H"' --> 

Python Version: Python 2.7.5

<!-- run 'python -V' and paste it here) --> 

Any other relevant files/configs (eg: path files) 

<!-- Anything else which may be of relevance -->

<!-- ===============END OF ISSUE SECTION=============== -->



Discussion:

Resolving patch:
diff --git a/pokemongo_bot/cell_workers/telegram_task.py b/pokemongo_bot/cell_workers/telegram_task.py
--- a/pokemongo_bot/cell_workers/telegram_task.py
+++ b/pokemongo_bot/cell_workers/telegram_task.py
@@ -1,5 +1,6 @@
 # -*- coding: utf-8 -*-
-import datetime
+from datetime import datetime
+from datetime import timedelta
 import telegram
 import os
 import logging


Test patch: