Repository: PokemonGoF/PokemonGo-Bot

Issue:
Keep heaviest pokemon
### Edited by moderator:

Submitting a request to have an option in the config to keep pokemon by their stats.
Example: Recycle pokemon by size.

---
#### Original Post:

Hi,

Is there a way to keep pokemons based on their weight or size instead of only iv or cp ?

Thanks



Discussion:
But why? 

They like big Pokemon? You can't question why it's a just a matter of who else who do it :p

anyone of you guys have a sample config.json.optimizer file? I dont know how to correctly set the parameters under keep section. im still trying to understand the whole thing but if anyone can give me a working config.json.optimizer, i would appreciate it very much. sorry for barging into your thread bro @lmondry. :)

@breinntaguilar join the slack server, there's 100s of ppl there with configs

Sounds interesting, tag it with feature requests. 😂😂😂

I had the same concern, but I "solve" it by playing with the release parameter and logical operand. You can further customize by type of Pokemon:

```
  "any": {"release_below_cp": 0, "release_below_iv": 0, "logic": "or"},
 "// Best fighters, keep 2:": {},
  "Arcanine": {"keep_best_iv": 2},
```

but I think your suggestion is relevant

There is a stat rationale for keeping, not the heaviest _per se_, but XL pokemon. Rumour has it that the HP pool is greater for XL pokemon.

Seems like a decent feature request that is probably pretty easy to implement.

@jrjhealey 
If that is he case, you can use "hp_max" as a sorting key in Pokemon Optimizer.


Resolving patch:
diff --git a/pokemongo_bot/cell_workers/transfer_pokemon.py b/pokemongo_bot/cell_workers/transfer_pokemon.py
--- a/pokemongo_bot/cell_workers/transfer_pokemon.py
+++ b/pokemongo_bot/cell_workers/transfer_pokemon.py
@@ -4,8 +4,7 @@
 from pokemongo_bot import inventory
 from pokemongo_bot.human_behaviour import action_delay
 from pokemongo_bot.base_task import BaseTask
-from pokemongo_bot.inventory import Pokemons, Pokemon
-
+from pokemongo_bot.inventory import Pokemons, Pokemon, Attack
 
 class TransferPokemon(BaseTask):
     SUPPORTED_TASK_API_VERSION = 1
@@ -19,10 +18,13 @@ def work(self):
         for pokemon_id, group in pokemon_groups.iteritems():
             pokemon_name = Pokemons.name_for(pokemon_id)
             keep_best, keep_best_cp, keep_best_iv = self._validate_keep_best_config(pokemon_name)
-
+            #TODO continue list possible criteria
+            keep_best_possible_criteria = ['cp','iv', 'iv_attack', 'iv_defense', 'iv_stamina', 'moveset.attack_perfection','moveset.defense_perfection','hp','hp_max']
+            keep_best_custom, keep_best_criteria, keep_amount = self._validate_keep_best_config_custom(pokemon_name, keep_best_possible_criteria)
+            
+            best_pokemon_ids = set()
+            order_criteria = 'none'
             if keep_best:
-                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]
@@ -36,8 +38,14 @@ def work(self):
                     if order_criteria == 'cp':
                         order_criteria = 'cp and iv'
                     else:
-                        order_criteria = 'iv'
-
+                        order_criteria = 'iv'      
+            elif keep_best_custom:
+                limit = keep_amount
+                best_pokemons = sorted(group, key=lambda x: keep_best_criteria, reverse=True)[:limit]
+                best_pokemon_ids = set(pokemon.id for pokemon in best_pokemons)
+                order_criteria = ' and '.join(keep_best_criteria)
+                
+            if keep_best or keep_best_custom:
                 # remove best pokemons from all pokemons array
                 all_pokemons = group
                 best_pokemons = []
@@ -76,7 +84,7 @@ def _release_pokemon_get_groups(self):
                 continue
 
             group_id = pokemon.pokemon_id
-
+            
             if group_id not in pokemon_groups:
                 pokemon_groups[group_id] = []
 
@@ -178,6 +186,32 @@ def _get_release_config_for(self, pokemon):
             release_config = {}
         return release_config
 
+    def _validate_keep_best_config_custom(self, pokemon_name, keep_best_possible_custom):
+        keep_best = False
+
+        release_config = self._get_release_config_for(pokemon_name)    
+        keep_best_custom = release_config.get('keep_best_custom', '')
+        keep_amount = release_config.get('amount', 0)
+
+        if keep_best_custom and keep_amount:
+            keep_best = True
+            
+            keep_best_custom = keep_best_custom.split(',')
+            for _str in keep_best_custom:
+                if _str not in keep_best_possible_custom:
+                    keep_best = False
+                    break
+
+            try:
+                keep_amount = int(keep_amount)
+            except ValueError:
+                keep_best = False
+              
+            if keep_amount < 0:
+                keep_best = False
+                
+        return keep_best, keep_best_custom, keep_amount
+        
     def _validate_keep_best_config(self, pokemon_name):
         keep_best = False
 
@@ -185,7 +219,7 @@ def _validate_keep_best_config(self, pokemon_name):
 
         keep_best_cp = release_config.get('keep_best_cp', 0)
         keep_best_iv = release_config.get('keep_best_iv', 0)
-
+        
         if keep_best_cp or keep_best_iv:
             keep_best = True
             try:
@@ -197,7 +231,7 @@ def _validate_keep_best_config(self, pokemon_name):
                 keep_best_iv = int(keep_best_iv)
             except ValueError:
                 keep_best_iv = 0
-
+                
             if keep_best_cp < 0 or keep_best_iv < 0:
                 keep_best = False
 


Test patch: