<commit_before>class User < ActiveRecord::Base
  authenticates_with_sorcery!

  Roles = %w{student professor gsi admin}

  has_attached_file :avatar,
                    :styles => { :medium => "300x300>",
                                 :thumb => "100x100>" },
                    :url => '/assets/avatars/:id/:style/:basename.:extension',
                    :path => ':rails_root/public/assets/avatars/:id/:style/:basename.:extension',
                    :default_url => '/images/missing_:style.png'


  has_many :grades
  has_many :earned_badges, :through => :grades
  belongs_to :team

  email_regex = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i

  validates_length_of :password, :minimum => 3, :message => "password must be at least 3 characters long", :if => :password
  validates_confirmation_of :password, :message => "should match confirmation", :if => :password
  validates :username, :presence => true,
                    :length => { :maximum => 50 }
  validates :email, :presence => true,
                    :format   => { :with => email_regex },
                    :uniqueness => { :case_sensitive => false }


  %w{student gsi professor admin}.each do |role|
    scope role.pluralize, where(:role => role)
  end

  def name
    [first_name,last_name].join(' ')
  end

  def is_prof?
    role == "professor"
  end

  def is_gsi?
    role == "gsi"
  end

  def is_student?
    role == "student" || role.blank?
  end

  def is_admin?
    role == "admin"
  end

  def role
    super || "student"
  end

  def is_staff?
    is_prof? || is_gsi? || is_admin?
  end

  #Actual
  
  def standard_score
    grades.standard.sum(:score) || 0
  end
  
  
  def blogging_score
    grades.blogging.sum(:score) || 0
  end
  
  def attendance_score
    grades.attendance.sum(:score) || 0
  end
  
  def reading_reaction_score
    grades.reading_reaction.map(&:score).inject(&:+) || 0
  end
   
  def calculate_score
    standard_score + blogging_score + attendance_score + reading_reaction_score || 0
  end
  
  #Possible 
  def reading_reaction_possible
    grades.where(:type=>"ReadingReactionGrade").map(&:points_possible).inject(&:+) || 0
  end
    
  def standard_possible
    grades.where(:type=>"StandardGrade").map(&:points_possible).inject(&:+) || 0
  end
  
  def attendance_possible
    grades.where(:type=>"AttendanceGrade").map(&:points_possible).inject(&:+) || 0
  end
  
  def possible_score
    attendance_possible + reading_reaction_possible + standard_possible || 0
  end<commit_msg>Updated user score for real<commit_after>class User < ActiveRecord::Base
  authenticates_with_sorcery!

  Roles = %w{student professor gsi admin}

  has_attached_file :avatar,
                    :styles => { :medium => "300x300>",
                                 :thumb => "100x100>" },
                    :url => '/assets/avatars/:id/:style/:basename.:extension',
                    :path => ':rails_root/public/assets/avatars/:id/:style/:basename.:extension',
                    :default_url => '/images/missing_:style.png'


  has_many :grades
  has_many :earned_badges, :through => :grades
  belongs_to :team

  email_regex = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i

  validates_length_of :password, :minimum => 3, :message => "password must be at least 3 characters long", :if => :password
  validates_confirmation_of :password, :message => "should match confirmation", :if => :password
  validates :username, :presence => true,
                    :length => { :maximum => 50 }
  validates :email, :presence => true,
                    :format   => { :with => email_regex },
                    :uniqueness => { :case_sensitive => false }


  %w{student gsi professor admin}.each do |role|
    scope role.pluralize, where(:role => role)
  end

  def name
    [first_name,last_name].join(' ')
  end

  def is_prof?
    role == "professor"
  end

  def is_gsi?
    role == "gsi"
  end

  def is_student?
    role == "student" || role.blank?
  end

  def is_admin?
    role == "admin"
  end

  def role
    super || "student"
  end

  def is_staff?
    is_prof? || is_gsi? || is_admin?
  end

  #Actual
  
  def standard_score
    grades.standard.sum(:score) || 0
  end
  
  
  def blogging_score
    grades.blogging.sum(:score) || 0
  end
  
  def attendance_score
    grades.attendance.sum(:score) || 0
  end
  
  def reading_reaction_score
    grades.reading_reaction.map(&:score).inject(&:+) || 0
  end
   
  def score
    grades.map(&:score).inject(&:+) || 0
  end
  
  #Possible 
  def reading_reaction_possible
    grades.where(:type=>"ReadingReactionGrade").map(&:points_possible).inject(&:+) || 0
  end
    
  def standard_possible
    grades.where(:type=>"StandardGrade").map(&:points_possible).inject(&:+) || 0
  end
  
  def attendance_possible
    grades.where(:type=>"AttendanceGrade").map(&:points_possible).inject(&:+) || 0
  end
  
  def possible_score
    attendance_possible + reading_reaction_possible + standard_possible || 0
  end
{'fraction_non_alphanumeric': 0.13962873284907182, 'fraction_numerical': 0.010088781275221953, 'mean_word_length': 2.7186796699174796, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5129492', 'n_tokens_mistral': 1716, 'n_tokens_neox': 1594, 'n_words': 342}