<commit_before>class User < ApplicationRecord
	has_secure_password

	has_many :searches
	has_many :products, through: :searches
	has_many :ingredients, through: :products

  validates :email, uniqueness: true

  def grade

  end
end<commit_msg>Add validation to require password and email. Add method to return average grade as 2 decimal places<commit_after>class User < ApplicationRecord
	has_secure_password

	has_many :searches
	has_many :products, through: :searches
	has_many :ingredients, through: :products

  validates :email, :password, presence: true
  validates :email, uniqueness: true

  def grade
    numerator = self.products.pluck(:score).reduce { |sum, score| sum + score }
    denominator = self.products.length
    average = numerator / denominator
    '%.1f' % average # returns 1 decimal place even for round numbers
  end
end
{'fraction_non_alphanumeric': 0.07319952774498228, 'fraction_numerical': 0.0035419126328217238, 'mean_word_length': 4.691275167785235, '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': '1057220', 'n_tokens_mistral': 256, 'n_tokens_neox': 242, 'n_words': 85}