<commit_before>
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 Attack
from pokemongo_bot.inventory import Pokemon
from pokemongo_bot.inventory import Pokemons
from operator import attrgetter
from random import randrange


class TransferPokemon(BaseTask):
    SUPPORTED_TASK_API_VERSION = 1

    def __init__(self, bot, config):
        super(TransferPokemon, self).__init__(bot, config)

    def initialize(self):
        self.min_free_slot = self.config.get('min_free_slot', 5)
        self.transfer_wait_min = self.config.get('transfer_wait_min', 1)
        self.transfer_wait_max = self.config.get('transfer_wait_max', 4)
        self.buddy = self.bot.player_data.get('buddy_pokemon', {})

    def work(self):
        if not self._should_work():
            return

        pokemon_groups = self._release_pokemon_get_groups()
        for pokemon_id, group in pokemon_groups.iteritems():
            pokemon_name = Pokemons.name_for(pokemon_id)
            self._release_pokemon_worst_in_group(group, pokemon_name)

        if self.bot.config.release.get('all'):
            group = [p for p in inventory.pokemons().all()
                     if not p.in_fort and not p.is_favorite and not (p.unique_id == self.buddy['id'])]
            self._release_pokemon_worst_in_group(group, 'all')

    def _should_work(self):
        return True
        random_number = randrange (0,20,1) 
        return inventory.Pokemons.get_space_left() <= max(1,self.min_free_slot - random_number)

    def _release_pokemon_get_groups(self):
        pokemon_groups = {}
        for pokemon in inventory.pokemons().all():
            if pokemon.in_fort or pokemon.is_favorite or pokemon.unique_id == self.buddy['id']:
                continue

            group_id = pokemon.pokemon_id

            if group_id not in pokemon_groups:
                pokemon_groups[group_id] = []

            pokemon_groups[group_id].append(pokemon)

        return pokemon_groups

    def _release_pokemon_worst_in_group(self, group, pokemon_name):
        keep_best, keep_best_cp, keep_best_iv, keep_best_ivcp = self._validate_keep_best_config(<commit_msg>Remove return true from should_work<commit_after>
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 Attack
from pokemongo_bot.inventory import Pokemon
from pokemongo_bot.inventory import Pokemons
from operator import attrgetter
from random import randrange


class TransferPokemon(BaseTask):
    SUPPORTED_TASK_API_VERSION = 1

    def __init__(self, bot, config):
        super(TransferPokemon, self).__init__(bot, config)

    def initialize(self):
        self.min_free_slot = self.config.get('min_free_slot', 5)
        self.transfer_wait_min = self.config.get('transfer_wait_min', 1)
        self.transfer_wait_max = self.config.get('transfer_wait_max', 4)
        self.buddy = self.bot.player_data.get('buddy_pokemon', {})

    def work(self):
        if not self._should_work():
            return

        pokemon_groups = self._release_pokemon_get_groups()
        for pokemon_id, group in pokemon_groups.iteritems():
            pokemon_name = Pokemons.name_for(pokemon_id)
            self._release_pokemon_worst_in_group(group, pokemon_name)

        if self.bot.config.release.get('all'):
            group = [p for p in inventory.pokemons().all()
                     if not p.in_fort and not p.is_favorite and not (p.unique_id == self.buddy['id'])]
            self._release_pokemon_worst_in_group(group, 'all')

    def _should_work(self):
        random_number = randrange (0,20,1) 
        return inventory.Pokemons.get_space_left() <= max(1,self.min_free_slot - random_number)

    def _release_pokemon_get_groups(self):
        pokemon_groups = {}
        for pokemon in inventory.pokemons().all():
            if pokemon.in_fort or pokemon.is_favorite or pokemon.unique_id == self.buddy['id']:
                continue

            group_id = pokemon.pokemon_id

            if group_id not in pokemon_groups:
                pokemon_groups[group_id] = []

            pokemon_groups[group_id].append(pokemon)

        return pokemon_groups

    def _release_pokemon_worst_in_group(self, group, pokemon_name):
        keep_best, keep_best_cp, keep_best_iv, keep_best_ivcp = self._validate_keep_best_config(
{'fraction_non_alphanumeric': 0.08585409252669039, 'fraction_numerical': 0.00400355871886121, 'mean_word_length': 3.191053122087605, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3824894', 'n_tokens_mistral': 1475, 'n_tokens_neox': 1431, 'n_words': 281}