<commit_before>class DeckDatabase
  def initialize(db)
    @db = db
  end

  def resolve_card(count, set_code, card_number, foil=false)
    set = @db.sets[set_code] or raise "Set not found #{set_code}"
    printing = set.printings.find{|cp| cp.number == card_number}
    raise "Card not found #{set_code}/#{card_number}" unless printing
    [count, PhysicalCard.for(printing, !!foil)]
  end

  def load!(path=Pathname("#{__dir__}/../../index/deck_index.json"))
    JSON.parse(path.read).each do |deck|
      set_code = deck["set_code"]
      set = @db.sets[set_code] or raise "Set not found #{set_code}"
      set.decks << load_deck(deck)
    end
  end

  def load_deck(deck)
    set_code = deck["set_code"]
    set = @db.sets[set_code]
    cards = deck["cards"].map{|c| resolve_card(*c) }
    sideboard = deck["sideboard"].map{|c| resolve_card(*c) }
    date = deck["release_date"]
    date = date ? Date.parse(date) : nil
    deck = PreconDeck.new(
      set,
      deck["name"],
      deck["type"],
      date,
      cards,
      sideboard,
    )
    return deck
  end

  def load_ech(path=Pathname("#{__dir__}/../../data/ech-precons.json"))
    JSON.parse(path.read).map(&:load_deck)
  end
end<commit_msg>Fix DeckDatabase.load_ech<commit_after>class DeckDatabase
  def initialize(db)
    @db = db
  end

  def resolve_card(count, set_code, card_number, foil=false)
    set = @db.sets[set_code] or raise "Set not found #{set_code}"
    printing = set.printings.find{|cp| cp.number == card_number}
    raise "Card not found #{set_code}/#{card_number}" unless printing
    [count, PhysicalCard.for(printing, !!foil)]
  end

  def load!(path=Pathname("#{__dir__}/../../index/deck_index.json"))
    JSON.parse(path.read).each do |deck|
      set_code = deck["set_code"]
      set = @db.sets[set_code] or raise "Set not found #{set_code}"
      set.decks << load_deck(deck)
    end
  end

  def load_deck(deck)
    set_code = deck["set_code"]
    set = @db.sets[set_code]
    cards = deck["cards"].map{|c| resolve_card(*c) }
    sideboard = deck["sideboard"].map{|c| resolve_card(*c) }
    date = deck["release_date"]
    date = date ? Date.parse(date) : nil
    deck = PreconDeck.new(
      set,
      deck["name"],
      deck["type"],
      date,
      cards,
      sideboard,
    )
    return deck
  end

  def load_ech(path=Pathname("#{__dir__}/../../data/ech-precons.json"))
    JSON.parse(path.read).map{ |deck| load_deck(deck) }
  end
end
{'fraction_non_alphanumeric': 0.16004911993450677, 'fraction_numerical': 0.0, 'mean_word_length': 3.1706484641638224, 'pattern_counts': {'":': 0, '<': 7, '<?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': '1538378', 'n_tokens_mistral': 877, 'n_tokens_neox': 864, 'n_words': 178}