<commit_before>
from __future__ import division
from collections import defaultdict
import random

import utils

SETS = {
    'classic': {
        'c': 188,
        'r': 162,
        'e': 74,
        'l': 33
    },
    'gvg': {
        'c': 80,
        'r': 74,
        'e': 52,
        'l': 20
    },
    'tgt': {
        'c': 98,
        'r': 72,
        'e': 54,
        'l': 20
    }
}

CHANCE = [
    ('c', 0.7165),
    ('r', 0.2284),
    ('e', 0.0442),
    ('l', 0.0110)
]

GOLDEN_CHANCE = {
    'c': 0.0206,
    'r': 0.0554,
    'e': 0.0452,
    'l': 0.0731
}

DUST_VALUE = {
    'c': (5, 50),
    'r': (20, 100),
    'e': (100, 400),
    'l': (400, 1600)
}

MAX_COPIES = {
    'c': 2,
    'r': 2,
    'e': 2,
    'l': 1
}


class Collection(object):

    def __init__(self):
        self.cards = {
            set_name: {rarity: defaultdict(int) for rarity, amount in rarity_amounts.iteritems()}
            for set_name, rarity_amounts in SETS.iteritems()
        }
        self.dust = 0

    def open_pack(self, pack):
        for card in pack.cards:
            self.cards[pack.set_name][card.rarity].setdefault(card.index, []).append(card)

    def dissenchant_extras(self, keep_golden=False):
        for set_name, rarities in self.cards.iteritems():
            for rarity, cards in rarities.iteritems():
                for card_index, copies in cards.iteritems():
                    if len(copies) > MAX_COPIES[rarity]:
                        self.dust += self.dissenchant_extra_copies(copies)

    def dissenchant_extra_copies(self, copies):
        dust = 0
        max_copies = MAX_COPIES[copies[0].rarity]
        while len(copies) > max_copies:
            try:
                card = next(copy for copy in copies if copy.golden)
            except StopIteration:
                card = copies[0]
            copies.remove(card)
            dust += card.dust_value()
        return dust

<commit_msg>Pass setting to keep golden copies<commit_after>
from __future__ import division
from collections import defaultdict
import random

import utils

SETS = {
    'classic': {
        'c': 188,
        'r': 162,
        'e': 74,
        'l': 33
    },
    'gvg': {
        'c': 80,
        'r': 74,
        'e': 52,
        'l': 20
    },
    'tgt': {
        'c': 98,
        'r': 72,
        'e': 54,
        'l': 20
    }
}

CHANCE = [
    ('c', 0.7165),
    ('r', 0.2284),
    ('e', 0.0442),
    ('l', 0.0110)
]

GOLDEN_CHANCE = {
    'c': 0.0206,
    'r': 0.0554,
    'e': 0.0452,
    'l': 0.0731
}

DUST_VALUE = {
    'c': (5, 50),
    'r': (20, 100),
    'e': (100, 400),
    'l': (400, 1600)
}

MAX_COPIES = {
    'c': 2,
    'r': 2,
    'e': 2,
    'l': 1
}


class Collection(object):

    def __init__(self):
        self.cards = {
            set_name: {rarity: defaultdict(int) for rarity, amount in rarity_amounts.iteritems()}
            for set_name, rarity_amounts in SETS.iteritems()
        }
        self.dust = 0

    def open_pack(self, pack):
        for card in pack.cards:
            self.cards[pack.set_name][card.rarity].setdefault(card.index, []).append(card)

    def dissenchant_extras(self, keep_golden=False):
        for set_name, rarities in self.cards.iteritems():
            for rarity, cards in rarities.iteritems():
                for card_index, copies in cards.iteritems():
                    if len(copies) > MAX_COPIES[rarity]:
                        self.dust += self.dissenchant_extra_copies(copies, keep_golden)

    def dissenchant_extra_copies(self, copies, keep_golden):
        dust = 0
        max_copies = MAX_COPIES[copies[0].rarity]
        while len(copies) > max_copies:
            try:
                if keep_golden:
                    card = next(copy for copy in copies if not copy.golden)
                else:
                    card = next(copy for copy in copies if copy.golden)
            except StopIteration:
                card = copies[0]

            copies.remove(card)
            dust += card.dust_value()
        return dust


{'fraction_non_alphanumeric': 0.1420059582919563, 'fraction_numerical': 0.04716981132075472, 'mean_word_length': 1.7389530931339225, 'pattern_counts': {'":': 0, '<': 3, '<?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': '7005469', 'n_tokens_mistral': 1594, 'n_tokens_neox': 1412, 'n_words': 341}