<commit_before>class User < ActiveRecord::Base
  has_secure_password
  validates :username, presence: true, uniqueness: true
  validates :email, presence: true, uniqueness: true
  validates_format_of :email, with: /@/
  validates :password, presence: true, length: { within: 6..20 }

  has_many :answers
  has_many :questions
  has_many :votes
  has_many :comments

  def self.session_user session_id
    User.find(session_id)
  end

  def current_user?
    self.id.eql? User.session_user.id
  end

  def questions_asked
    self.questions.count
  end

  def has_questions?
    true if !self.questions.empty?
  end

  def reputation
    self.upvote_count - self.downvote_count
  end

  def upvote_count
    (get_all_upvotes(self.questions) + get_all_upvotes(self.answers)) + (get_all_upvotes(self.answers) + get_all_upvotes(self.answers))
  end

  def downvote_count
    self.votes.where(upvote: false).count
  end

  def get_all_upvotes data_set
    data_set.each do |data|
      data.select { |vote| vote.upvote? }.count
    end
  end

  def get_all_downvotes data_set
    data_set.each do |data|
      data.select { |vote| vote.downvote? }.count
    end
  end
end<commit_msg>User Model: created user reputation methods.<commit_after>class User < ActiveRecord::Base
  has_secure_password
  validates :username, presence: true, uniqueness: true
  validates :email, presence: true, uniqueness: true
  validates_format_of :email, with: /@/
  validates :password, presence: true, length: { within: 6..20 }

  has_many :questions
  has_many :answers, through: :questions
  has_many :votes
  has_many :comments

  def self.session_user session_id
    User.find(session_id)
  end

  def current_user?
    self.id.eql? User.session_user.id
  end

  def questions_asked
    self.questions.count
  end

  def questions_answer
    self.answers.count
  end

  def has_questions?
    true unless self.questions.empty?
  end

  def reputation
    self.upvotes.count - self.downvotes.count
  end

  def upvotes
    question_votes = self.votes_on_all_questions.select { |vote| vote.upvote? }
    answer_votes = self.votes_on_all_answers.select { |vote| vote.downvote? }

    question_votes.concat(answer_votes)
  end

  def downvotes
    question_votes = self.votes_on_all_questions.select { |vote| vote.downvote? }
    answer_votes = self.votes_on_all_answers.select { |vote| vote.downvote? }

    question_votes.concat(answer_votes)
  end

  def votes_on_all_questions
    self.questions.map do |question|
      question.votes
    end.flatten
  end

  def votes_on_all_answers
    self.answers.map do |answer|
      answer.votes
    end.flatten
  end
end
{'fraction_non_alphanumeric': 0.08364875094625283, 'fraction_numerical': 0.002271006813020439, 'mean_word_length': 3.5885416666666665, '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': '4288392', 'n_tokens_mistral': 966, 'n_tokens_neox': 910, 'n_words': 206}