<commit_before>import constants
from dataobjects.constants import legendaries
from collections import OrderedDict


class Deck(object):
    """
    Class for storing information about Hearthstone deck
    """

    def __init__(self):
        self.player_class = ''
        self.name = 'Noname deck'
        self.type = constants.CONSTRUCTED_DECK
        self.cards = {}

    def is_valid(self):
        """
        is this Deck valid to use in Heartstone?
        :return: bool
        """
        return len(self.get_errors()) == 0

    def get_errors(self):
        """
        Get list of errors in deck
        :return: list of str
        """
        errors = []
        if self.player_class not in constants.player_classes:
            errors.append('Invalid class %s' % self.player_class)
        if sum(self.cards.values()) != 30:
            errors.append('Deck should contain 30 cards, this deck contain %d' % sum(self.cards.values()))
        if self.type != constants.ARENA_DECK:
            for card_name, card_count in self.cards.iteritems():
                if card_count > 2 or card_count < 1:
                    errors.append('Invalid count of card "%s" : %d' % (card_name, card_count))
                if card_count > 1 and card_name in legendaries:
                    errors.append('You cannot have more then 1 legendary card "%s" in deck' % card_name)
        errors.extend(self.get_nerfed_deck_errors())
        # TODO add checking for class cards - deck should have only class and common cards
        return errors

    def get_nerfed_deck_errors(self):
        """
        Check if this deck was invalidated by card nerfs and return those
        :return: list of str
        """
        errors = []
        if 'Warsong Commander' in self.cards and ('Grim Patron' in self.cards or 'Frothing Berserker' in self.cards):
            errors.append('Patron-Warsong and Berserker-Warsong combos no longer valid by Warsong commander nerf')
        return errors

    def get_arena_advice(self):
        # todo
        pass

    def get_constructed_advice(self):
        # todo
        pass

    def get_advice(self):
        if self.type == constants.CONSTRUCTED_DECK:
            self.get_constructed_advice()
        else:
            self.get_arena_advice()

    def get_total_synergy_score(self):
        # todo
        pass

    def add_card(self, card_name):
        if card_name in self.cards:
            self.cards[card_name] += 1
        else:
            self.cards[card_name] = 1<commit_msg>added "joker" errors method, to filter out joke decks<commit_after>import constants
from dataobjects.constants import legendaries
from collections import OrderedDict


class Deck(object):
    """
    Class for storing information about Hearthstone deck
    """

    def __init__(self):
        self.player_class = ''
        self.name = 'Noname deck'
        self.type = constants.CONSTRUCTED_DECK
        self.cards = {}

    def is_valid(self):
        """
        is this Deck valid to use in Heartstone?
        :return: bool
        """
        return len(self.get_errors()) == 0

    def get_errors(self):
        """
        Get list of errors in deck
        :return: list of str
        """
        errors = []
        if self.player_class not in constants.player_classes:
            errors.append('Invalid class %s' % self.player_class)
        if sum(self.cards.values()) != 30:
            errors.append('Deck should contain 30 cards, this deck contain %d' % sum(self.cards.values()))
        if self.type != constants.ARENA_DECK:
            for card_name, card_count in self.cards.iteritems():
                if card_count > 2 or card_count < 1:
                    errors.append('Invalid count of card "%s" : %d' % (card_name, card_count))
                if card_count > 1 and card_name in legendaries:
                    errors.append('You cannot have more then 1 legendary card "%s" in deck' % card_name)
        errors.extend(self.get_nerfed_deck_errors())
        errors.extend(self.get_jokers_errors())
        # TODO add checking for class cards - deck should have only class and common cards
        return errors

    def get_nerfed_deck_errors(self):
        """
        Check if this deck was invalidated by card nerfs and return those
        :return: list of str
        """
        errors = []
        if 'Warsong Commander' in self.cards and ('Grim Patron' in self.cards or 'Frothing Berserker' in self.cards):
            errors.append('Patron-Warsong and Berserker-Warsong combos no longer valid by Warsong commander nerf')
        return errors

    def get_jokers_errors(self):
        """
        Filter out "joke" decks
        :return:
        """
        errors = []
        if self.player_class in ['Mage', 'Warlock', 'Priest', 'Druid'] and 'Dread Corsair' in self.cards:
            errors.append('Haha, Dread Corsair in class without weapons, very funny')
        return errors

    def get_arena_advice(self):
        # todo
        pass

    def get_constructed_advice(self):
        # todo
        pass

    def get_advice(self):
        if self.type == constants.CONSTRUCTED_DECK:
            self.get_constructed_advice()
        else:
            self.get_arena_advice()

    def get_total_synergy_score(self):
        # todo
        pass

    def add_card(self, card_name):
        if card_name in self.cards:
            self.cards[card_name] += 1
        else:
            self.cards[card_name] = 1
{'fraction_non_alphanumeric': 0.08989585236616116, 'fraction_numerical': 0.004019733235885255, 'mean_word_length': 2.119088319088319, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '874971', 'n_tokens_mistral': 1604, 'n_tokens_neox': 1546, 'n_words': 471}