<commit_before>class Metric < ActiveRecord::Base
  belongs_to :rubric, touch: true
  has_many :tiers, dependent: :destroy

  has_many :metric_badges
  has_many :badges, through: :metric_badges

  has_many :rubric_grades
  belongs_to :full_credit_tier, foreign_key: :full_credit_tier_id, class_name: "Tier", touch: true
  attr_accessible :name, :max_points, :description, :order, :rubric_id, :full_credit_tier_id
  attr_accessor :add_default_tiers

  after_initialize :set_defaults
  #after_create :generate_default_tiers, if: :add_default_tiers?
  #after_save :update_full_credit, if: :add_default_tiers?

  validates :max_points, presence: true
  validates :name, presence: true, length: { maximum: 30 }
  validates :order, presence: true

  scope :ordered, lambda { order(:order) }

  def description_missing?
    description.nil? or description.blank?
  end

  include DisplayHelpers

  protected

  def add_default_tiers?
    self.add_default_tiers === true
  end

  def set_defaults
    self.add_default_tiers = true
  end

  def generate_default_tiers
    @full_credit_tier = create_full_credit_tier
    create_no_credit_tier
    #update_attributes full_credit_tier_id: @full_credit_tier[:id]
  end

  def update_full_credit
    find_and_set_full_credit_tier unless full_credit_tier
    full_credit_tier.update_attributes points: max_points
  end

  def find_and_set_full_credit_tier
    full_credit_tier = tiers.where(full_credit: true).first
    full_credit_tier ||= create_full_credit_tier
    update_attributes full_credit_tier_id: full_credit_tier[:id]
  end

  def create_full_credit_tier
    tiers.create name: "Full Credit", points: max_points, full_credit: true, durable: true, sort_order: 0
  end

  def create_no_credit_tier
    tiers.create name: "No Credit", points: 0, no_credit: true, durable: true, sort_order: 1000
  end
end<commit_msg>Reset temporary metric object fix back to master state<commit_after>class Metric < ActiveRecord::Base
  belongs_to :rubric, touch: true
  has_many :tiers, dependent: :destroy

  has_many :metric_badges
  has_many :badges, through: :metric_badges

  has_many :rubric_grades
  belongs_to :full_credit_tier, foreign_key: :full_credit_tier_id, class_name: "Tier", touch: true
  attr_accessible :name, :max_points, :description, :order, :rubric_id, :full_credit_tier_id
  attr_accessor :add_default_tiers

  after_initialize :set_defaults
  #after_create :generate_default_tiers, if: :add_default_tiers?
  #after_save :update_full_credit, if: :add_default_tiers?

  validates :max_points, presence: true
  validates :name, presence: true, length: { maximum: 30 }
  validates :order, presence: true

  scope :ordered, lambda { order(:order) }

  def description_missing?
    description.nil? or description.blank?
  end

  include DisplayHelpers

  protected

  def add_default_tiers?
    self.add_default_tiers === true
  end

  def set_defaults
    self.add_default_tiers = true
  end

  def generate_default_tiers
    @full_credit_tier = create_full_credit_tier
    create_no_credit_tier
    update_attributes full_credit_tier_id: @full_credit_tier[:id]
  end

  def update_full_credit
    find_and_set_full_credit_tier unless full_credit_tier
    full_credit_tier.update_attributes points: max_points
  end

  def find_and_set_full_credit_tier
    full_credit_tier = tiers.where(full_credit: true).first
    full_credit_tier ||= create_full_credit_tier
    update_attributes full_credit_tier_id: full_credit_tier[:id]
  end

  def create_full_credit_tier
    tiers.create name: "Full Credit", points: max_points, full_credit: true, durable: true, sort_order: 0
  end

  def create_no_credit_tier
    tiers.create name: "No Credit", points: 0, no_credit: true, durable: true, sort_order: 1000
  end
end
{'fraction_non_alphanumeric': 0.07104843001596593, 'fraction_numerical': 0.004257583821181479, 'mean_word_length': 5.275459098497496, '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': '5407146', 'n_tokens_mistral': 1372, 'n_tokens_neox': 1243, 'n_words': 295}