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

Added further release functionality #1472

Merged
merged 4 commits into from
Jul 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 3 additions & 1 deletion configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
"// Example of keeping 2 stronger (based on IV) Zubat:": {},
"// Zubat": {"keep_best_iv": 2},
"// Also, it is working with any": {},
"// any": {"keep_best_iv": 3}
"// any": {"keep_best_iv": 3},
"// Example of keeping the 2 strongest (based on CP) and 3 best (based on IV) Zubat:": {},
Copy link
Contributor

Choose a reason for hiding this comment

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

should this say 3 strongest ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed it to 2.

"// Zubat": {"keep_best_cp": 2, "keep_best_iv": 3}
}
}
31 changes: 19 additions & 12 deletions pokemongo_bot/cell_workers/pokemon_transfer_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pokemongo_bot.human_behaviour import sleep, action_delay
from pokemongo_bot import logger


class PokemonTransferWorker(object):

def __init__(self, bot):
Expand All @@ -24,21 +25,31 @@ def work(self):
keep_best, keep_best_cp, keep_best_iv = self._validate_keep_best_config(pokemon_name)

if keep_best:
order_criteria = 'cp'
limit = keep_best_cp
best_pokemon_ids = set()
order_criteria = 'none'
if keep_best_cp >= 1:
cp_limit = keep_best_cp
best_cp_pokemons = sorted(group, key=lambda x: (x['cp'], x['iv']), reverse=True)[:cp_limit]
best_pokemon_ids = set(pokemon['pokemon_data']['id'] for pokemon in best_cp_pokemons)
order_criteria = 'cp'

if keep_best_iv >= 1:
order_criteria = 'iv'
limit = keep_best_iv

best_pokemons = sorted(group, key=lambda x: x[order_criteria], reverse=True)[:limit]
iv_limit = keep_best_iv
best_iv_pokemons = sorted(group, key=lambda x: (x['iv'], x['cp']), reverse=True)[:iv_limit]
best_pokemon_ids |= set(pokemon['pokemon_data']['id'] for pokemon in best_iv_pokemons)
Copy link
Member

@douglascamata douglascamata Jul 28, 2016

Choose a reason for hiding this comment

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

I'm not familiar with the operator |= for sets. Why not a simple set addition?

Copy link
Contributor

Choose a reason for hiding this comment

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

https://docs.python.org/2/library/sets.html#set-objects it seems to be standard set operator

Copy link
Contributor Author

@MFizz MFizz Jul 28, 2016

Choose a reason for hiding this comment

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

|= is the union operator from set theory. I don't exactly know what you mean with set addition. But if you mean the add() function, it can only be used for the addition of a single hashable element. Usually though set addition is used as a synonym for union.

In this context best_pokemon_ids.update(set(pokemon['pokemon_data']['id'] for pokemon in best_iv_pokemons)) would have the same effect, if you find that more appealing.

if order_criteria == 'cp':
order_criteria = 'cp and iv'
else:
order_criteria = 'iv'

# remove best pokemons from all pokemons array
all_pokemons = group
for best_pokemon in best_pokemons:
best_pokemons = []
for best_pokemon_id in best_pokemon_ids:
for pokemon in all_pokemons:
if best_pokemon['pokemon_data']['id'] == pokemon['pokemon_data']['id']:
if best_pokemon_id == pokemon['pokemon_data']['id']:
all_pokemons.remove(pokemon)
best_pokemons.append(pokemon)

if best_pokemons and all_pokemons:
logger.log("Keep {} best {}, based on {}".format(len(best_pokemons),
Expand Down Expand Up @@ -190,10 +201,6 @@ def _validate_keep_best_config(self, pokemon_name):
except ValueError:
keep_best_iv = 0

if keep_best_cp > 1 and keep_best_iv > 1:
logger.log("keep_best_cp and keep_best_iv can't be > 0 at the same time. Ignore it.", "red")
keep_best = False

if keep_best_cp < 0 or keep_best_iv < 0:
logger.log("Keep best can't be < 0. Ignore it.", "red")
keep_best = False
Expand Down