<commit_before>class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

         has_many :histories

  has_many :neighborhood_users
  has_many :neighborhoods, through: :neighborhood_users

  validates :user_name, presence: true,
                        case_sensitive: false
  validates :zipcode, presence: true, length: { :is => 5 }


  def favorites
    favs = []
    self.histories.each do |history|
      state = history.identify_state
      favs.push(history) if state == "Favorite"
    end
  end

  def start_card
    card_sample = []
    if self.neighborhoods.empty?
      return Food.all.sample
    else
      self.neighborhoods each do |neighborhood|
        neighborhood.places each do |place|
          card_sample << place
        end
      end
    end
    card_sample.sample
  end

  def build_deck
    json = []
    @deck = Food.all.sample(10)
    @deck.each do |food|
      json_food = {
        id: food.id,
        name: food.place.name,
        url: food.url,
        place_id: food.place.id
      }
      json << json_food
    end
    json
  end
end
<commit_msg>Refactor build deck to account for neighborhoods<commit_after>class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

         has_many :histories

  has_many :neighborhood_users
  has_many :neighborhoods, through: :neighborhood_users

  validates :user_name, presence: true,
                        case_sensitive: false
  validates :zipcode, presence: true, length: { :is => 5 }


  def favorites
    favs = []
    self.histories.each do |history|
      state = history.identify_state
      favs.push(history) if state == "Favorite"
    end
  end

  def start_card
    card_sample = []
    if self.neighborhoods.empty?
      return Food.all.sample
    else
      self.neighborhoods each do |neighborhood|
        neighborhood.places each do |place|
          card_sample << place
        end
      end
    end
    card_sample.sample
  end

  def build_deck
    json = []
    if self.neighborhoods.empty?
      Food.all.each do |food|
        json_food = {
          id: food.id,
          name: food.place.name,
          url: food.url,
          place_id: food.place.id
        }
        json << json_food
      end
    else
      self.neighborhoods each do |neighborhood|
        neighborhood.places each do |place|
          place.foods each do |food|
            json_food = {
              id: food.id,
              name: food.place.name,
              url: food.url,
              place_id: food.place.id
            }
            json << json_food
          end
        end
      end
    end
    json
  end
end

{'fraction_non_alphanumeric': 0.08084824387011266, 'fraction_numerical': 0.0013253810470510272, 'mean_word_length': 2.118801652892562, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 5, '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': '6372453', 'n_tokens_mistral': 938, 'n_tokens_neox': 889, 'n_words': 240}