<commit_before>class Target < ActiveRecord::Base
  include ActionView::Helpers::TextHelper

  attr_accessible :due_date, :target_count, :unit, :conference_id

  default_scope { order('due_date ASC') }

  def self.units
    {
      registrations: 'Registration',
      submissions: 'Submission',
      program_minutes: 'Program minute'
    }
  end

  validates :due_date, :target_count, :unit, presence: true
  validates :target_count,
            allow_nil: false,
            numericality: { only_integer: true, greater_than: 0 }
  validates :unit, allow_nil: false, inclusion: { in: Target.units.values }

  belongs_to :conference
  belongs_to :campaign

  ##
  # Returns the actual progress of the target in percent.
  #
  # ====Returns
  # * +String+ -> progress in percent
  def get_progress
    numerator = 0
    case unit
    when Target.units[:submissions]
      numerator = conference.events.where('created_at < ?', due_date).count
    when Target.units[:registrations]
      numerator = conference.registrations.where('created_at < ?', due_date).count
    when Target.units[:program_minutes]
      numerator = conference.current_program_minutes
    end
    (100 * numerator / target_count).to_s
  end

  ##
  # Returns a hash with values of the corresponding campaign.
  #
  # ====Returns
  # * +Hash+ -> target_name, campaign_name, value, unit, created_at, progress, days_left
  def get_campaign
    numerator = 0
    if unit == Target.units[:submissions]<commit_msg>get_progress: Move default value into else branch<commit_after>class Target < ActiveRecord::Base
  include ActionView::Helpers::TextHelper

  attr_accessible :due_date, :target_count, :unit, :conference_id

  default_scope { order('due_date ASC') }

  def self.units
    {
      registrations: 'Registration',
      submissions: 'Submission',
      program_minutes: 'Program minute'
    }
  end

  validates :due_date, :target_count, :unit, presence: true
  validates :target_count,
            allow_nil: false,
            numericality: { only_integer: true, greater_than: 0 }
  validates :unit, allow_nil: false, inclusion: { in: Target.units.values }

  belongs_to :conference
  belongs_to :campaign

  ##
  # Returns the actual progress of the target in percent.
  #
  # ====Returns
  # * +String+ -> progress in percent
  def get_progress
    case unit
    when Target.units[:submissions]
      numerator = conference.events.where('created_at < ?', due_date).count
    when Target.units[:registrations]
      numerator = conference.registrations.where('created_at < ?', due_date).count
    when Target.units[:program_minutes]
      numerator = conference.current_program_minutes
    else
      numerator = 0
    end
    (100 * numerator / target_count).to_s
  end

  ##
  # Returns a hash with values of the corresponding campaign.
  #
  # ====Returns
  # * +Hash+ -> target_name, campaign_name, value, unit, created_at, progress, days_left
  def get_campaign
    numerator = 0
    if unit == Target.units[:submissions]
{'fraction_non_alphanumeric': 0.10223110223110222, 'fraction_numerical': 0.003996003996003996, 'mean_word_length': 3.5377643504531724, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '7618144', 'n_tokens_mistral': 932, 'n_tokens_neox': 899, 'n_words': 232}