Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 5 commits into from
Sep 26, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
"interval": 60,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small issue, but I'm not sure if users will be confused by interval and min_evolve_speed. Perhaps a better name is log_interval?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this number represents how often - in seconds - the task runs. I just realized I should also add that to the docs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexyaoyang I've added the documentation line. I have been trying this at home for 2 days now and I feel much more comfortable with 120 as the default value because we don't want this message to be spammy 😄


"// evolve only pidgey and drowzee": "",
"// evolve_list": "pidgey, drowzee",
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 @@ -477,6 +477,10 @@ def _register_events(self):
'pokemon_evolved',
parameters=('pokemon', 'iv', 'cp', 'candy', 'xp')
)
self.event_manager.register_event(
'pokemon_evolve_check',
parameters=('has', 'needs', 'message')
)
self.event_manager.register_event(
'pokemon_upgraded',
parameters=('pokemon', 'iv', 'cp', 'candy', 'stardust')
Expand Down Expand Up @@ -1476,4 +1480,4 @@ def _refresh_inventory(self):
inventory.refresh_inventory()
self.last_inventory_refresh = now
self.inventory_refresh_counter += 1

32 changes: 28 additions & 4 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_update = None
self.interval = self.config.get('interval', 60)
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 @@ -55,6 +57,9 @@ def work(self):
if not self._should_run():
return

self._compute_next_update()

result_message = ""
filtered_list, filtered_dict = self._sort_and_filter()

pokemon_to_be_evolved = 0
Expand All @@ -65,19 +70,38 @@ 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._print_check(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 _print_check(self, pokemon_to_be_evolved):
has_minimum_to_evolve = pokemon_to_be_evolved >= self.min_pokemon_to_be_evolved
result_message = ("Gotta catch`em all!", "Gotta evolv`em all!")[has_minimum_to_evolve]
self.emit_event(
'pokemon_evolve_check',
formatted='Checking... Has {has}, needs {needs}. {message}',
Copy link
Contributor

@alexyaoyang alexyaoyang Sep 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it can be even more simplistic: Evolvable: {has}/{need} will be sufficient. 👍

data={
'has': pokemon_to_be_evolved,
'needs': self.min_pokemon_to_be_evolved,
'message': result_message
}
)

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

return self.next_update is None or datetime.now() >= self.next_update
Copy link
Contributor

@alexyaoyang alexyaoyang Sep 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like the duration that user set now affects how frequent evolve pokemon task is ran. I think only the logging should be reduced, but not the task itself.

For example, if I set min_pokemon_to_be_evolved to 80, there's a chance that I might be evolving more than 80 pokemon due to evolve pokemon not running when I have exactly 80 pokemon.

While evolving more pokemon than the quota is not a big deal for me, I'm not sure if that applies to everyone else. Also if user accidentally sets interval to a huge number, that might be a bigger issue.

Copy link
Contributor Author

@ch1ago ch1ago Sep 23, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, but I added documentation for this and the way I see this, people should read it so as not to put a huge number there. Also, how many extra pokemon can they catch in 120 seconds?

Having said that, I can still tweak this to a log_interval if you want ¯_(ツ)_/¯

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm yes I see what you mean and I agree with you, but I'd rather not change the behavior of the task since the purpose of this PR is for giving a status update, and not to reduce frequency of evolve task.

Assuming that not all users read the documentation, we are essentially giving users the power/ability to screw up the evolve task.

IMO, if the frequency of evolve task should be reduced, it should be in another PR. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexyaoyang Hey man, chill. It's his first contribution :) :) :)

Just kidding, I agree with you. Keeping this PR to just the log message, not the task itself, would be better.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Gobberwart Not sure why but I found that very funny. Now people looking at me kinda weird in Starbucks. Thanks!


def _compute_next_update(self):
self.next_update = datetime.now() + timedelta(seconds=self.interval)

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