Skip to content

Commit

Permalink
Task EvolvePokemon should give us a status updates so we know it is w…
Browse files Browse the repository at this point in the history
…orking (#5570)

* Task EvolvePokemon should give us a status updates so we know it is working

* Task EvolvePokemon should give us a status updates so we know it is working

* Task EvolvePokemon should give us a status updates so we know it is working

* Task EvolvePokemon should give us a status updates so we know it is working

* Task EvolvePokemon should give us a status updates so we know it is working
  • Loading branch information
ch1ago authored and alexyaoyang committed Sep 26, 2016
1 parent f9bd89d commit c53a57e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 5 deletions.
1 change: 1 addition & 0 deletions configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
"type": "EvolvePokemon",
"config": {
"enabled": false,
"log_interval": 120,

"// evolve only pidgey and drowzee": "",
"// evolve_list": "pidgey, drowzee",
Expand Down
1 change: 1 addition & 0 deletions docs/configuration_files.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ The behaviors of the bot are configured via the `tasks` key in the `config.json`
* EvolvePokemon
* `enable`: Disable or enable this task.
* `evolve_all`: Default `NONE` | Depreciated. Please use evolve_list and donot_evolve_list
* `log_interval`: `Default: 120`. Time (in seconds) to periodically print how far you are from having enough pokemon to evolve (more than `min_pokemon_to_be_evolved`)
* `evolve_list`: Default `all` | Set to all, or specifiy different pokemon seperated by a comma
* `donot_evolve_list`: Default `none` | Pokemon seperated by comma, will be ignored from evolve_list
* `min_evolve_speed`: Default `25` | Minimum seconds to wait between each evolution
Expand Down
8 changes: 6 additions & 2 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def __init__(self, db, config):
self.heartbeat_counter = 0
self.last_heartbeat = time.time()
self.hb_locked = False # lock hb on snip

# Inventory refresh limiting
self.inventory_refresh_threshold = 10
self.inventory_refresh_counter = 0
Expand Down Expand Up @@ -481,6 +481,10 @@ def _register_events(self):
'pokemon_evolved',
parameters=('pokemon', 'iv', 'cp', 'candy', 'xp')
)
self.event_manager.register_event(
'pokemon_evolve_check',
parameters=('has', 'needs')
)
self.event_manager.register_event(
'pokemon_upgraded',
parameters=('pokemon', 'iv', 'cp', 'candy', 'stardust')
Expand Down Expand Up @@ -1485,4 +1489,4 @@ def _refresh_inventory(self):
inventory.refresh_inventory()
self.last_inventory_refresh = now
self.inventory_refresh_counter += 1

26 changes: 23 additions & 3 deletions pokemongo_bot/cell_workers/evolve_pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def __init__(self, bot, config):

def initialize(self):
self.start_time = 0
self.next_log_update = None
self.log_interval = self.config.get('log_interval', 120)
self.evolve_list = self.config.get('evolve_list', [])
self.donot_evolve_list = self.config.get('donot_evolve_list', [])
self.min_evolve_speed = self.config.get('min_evolve_speed', 25)
Expand All @@ -41,7 +43,7 @@ def initialize(self):
def _validate_config(self):
if isinstance(self.evolve_list, basestring):
self.evolve_list = [str(pokemon_name).lower().strip() for pokemon_name in self.evolve_list.split(',')]

if isinstance(self.donot_evolve_list, basestring):
self.donot_evolve_list = [str(pokemon_name).lower().strip() for pokemon_name in self.donot_evolve_list.split(',')]

Expand All @@ -65,19 +67,37 @@ def work(self):
candy = inventory.candies().get(pokemon.pokemon_id)
pokemon_to_be_evolved = pokemon_to_be_evolved + min(candy.quantity / (pokemon.evolution_cost - 1), filtered_dict[pokemon.pokemon_id])

if pokemon_to_be_evolved >= self.min_pokemon_to_be_evolved:
self._log_update_if_should(pokemon_to_be_evolved, self.min_pokemon_to_be_evolved)

has_minimum_to_evolve = pokemon_to_be_evolved >= self.min_pokemon_to_be_evolved
if has_minimum_to_evolve:
if self.use_lucky_egg:
self._use_lucky_egg()
cache = {}
for pokemon in filtered_list:
if pokemon.can_evolve_now():
self._execute_pokemon_evolve(pokemon, cache)

def _log_update_if_should(self, has, needs):
self._compute_next_log_update()
if self._should_log_update:

This comment has been minimized.

Copy link
@alexyaoyang

alexyaoyang Sep 26, 2016

Contributor

@thejamespinto Needs brackets here too: if self._should_log_update():

self.emit_event(
'pokemon_evolve_check',
formatted='Evolvable: {has}/{need}',

This comment has been minimized.

Copy link
@alexyaoyang

alexyaoyang Sep 26, 2016

Contributor

@thejamespinto Typo, should be needs. I thought you tested your changes?

data={'has': has, 'needs': needs}
)

def _compute_next_log_update(self):
self.next_log_update = datetime.now() + timedelta(seconds=self.log_interval)

This comment has been minimized.

Copy link
@ukos-git

ukos-git Sep 26, 2016

Contributor

@thejamespinto you should import the appropriate functions in the beginning. Otherwise it gives an error. At least in my python.
from datetime import datetime, timedelta

This comment has been minimized.

Copy link
@alexyaoyang

alexyaoyang Sep 26, 2016

Contributor

I'll submit a PR


def _should_log_update(self):
return datetime.now() >= self.next_log_update

def _should_run(self):
if not self.evolve_list or self.evolve_list[0] == 'none':
return False
return True

def _use_lucky_egg(self):
using_lucky_egg = time.time() - self.start_time < 1800
if using_lucky_egg:
Expand Down
1 change: 1 addition & 0 deletions pokemongo_bot/event_handlers/logging_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class LoggingHandler(EventHandler):
'pokemon_capture_failed': 'red',
'pokemon_caught': 'blue',
'pokemon_evolved': 'green',
'pokemon_evolve_check': 'green',
'pokemon_fled': 'red',
'pokemon_inventory_full': 'red',
'pokemon_nickname_invalid': 'red',
Expand Down

0 comments on commit c53a57e

Please sign in to comment.