<commit_before>class WorkUnit < ActiveRecord::Base
  include GuidReferenced
  acts_as_commentable
  has_many :comments, :as => :commentable
  belongs_to :ticket
  belongs_to :user
  validates_presence_of :ticket_id, :user_id, :description, :hours, :scheduled_at, :effective_hours

  scope :scheduled_between, lambda{|start_time, end_time| where('scheduled_at BETWEEN ? AND ?', start_time, end_time) }
  scope :unpaid, lambda{ where('paid IS NULL or paid = ""') }
  scope :not_invoiced, lambda{ where('invoiced IS NULL OR invoiced = ""') }
  scope :for_client, lambda{|client| joins({:ticket => {:project => [:client]}}).where("clients.id = ?", client.id) }
  scope :for_project, lambda{|project| joins({:ticket => [:project]}).where("projects.id = ?", project.id)}
  scope :for_ticket, lambda {|ticket| where('ticket_id = ?', ticket.id) }
  scope :for_user, lambda{|user| where('user_id = ?', user.id)}
  scope :sort_by_scheduled_at, order('scheduled_at DESC')
  scope :pto, where('hours_type = "PTO"')
  scope :cto, where('hours_type = "CTO"')
  scope :overtime, where('hours_type = "Overtime"')
  scope :normal, where('hours_type = "Normal"')

  before_validation :set_effective_hours!
  after_validation :validate_client_status
  after_save :send_email!

  def validate_client_status
    if client && client.status == "Inactive"
      self.errors.add(:base, "Cannot create work units on inactive clients.")
    end
  end

  def send_email!
    Notifier.work_unit_notification(self, email_list).deliver if email_list.length > 0
  end

  def email_list<commit_msg>[WORKUNIT] validate hours type presence<commit_after>class WorkUnit < ActiveRecord::Base
  include GuidReferenced
  acts_as_commentable
  has_many :comments, :as => :commentable
  belongs_to :ticket
  belongs_to :user
  validates_presence_of :ticket_id, :user_id, :description, :hours, :scheduled_at, :effective_hours, :hours_type

  scope :scheduled_between, lambda{|start_time, end_time| where('scheduled_at BETWEEN ? AND ?', start_time, end_time) }
  scope :unpaid, lambda{ where('paid IS NULL or paid = ""') }
  scope :not_invoiced, lambda{ where('invoiced IS NULL OR invoiced = ""') }
  scope :for_client, lambda{|client| joins({:ticket => {:project => [:client]}}).where("clients.id = ?", client.id) }
  scope :for_project, lambda{|project| joins({:ticket => [:project]}).where("projects.id = ?", project.id)}
  scope :for_ticket, lambda {|ticket| where('ticket_id = ?', ticket.id) }
  scope :for_user, lambda{|user| where('user_id = ?', user.id)}
  scope :sort_by_scheduled_at, order('scheduled_at DESC')
  scope :pto, where('hours_type = "PTO"')
  scope :cto, where('hours_type = "CTO"')
  scope :overtime, where('hours_type = "Overtime"')
  scope :normal, where('hours_type = "Normal"')

  before_validation :set_effective_hours!
  after_validation :validate_client_status
  after_save :send_email!

  def validate_client_status
    if client && client.status == "Inactive"
      self.errors.add(:base, "Cannot create work units on inactive clients.")
    end
  end

  def send_email!
    Notifier.work_unit_notification(self, email_list).deliver if email_list.length > 0
  end

  def email_list
{'fraction_non_alphanumeric': 0.13884506153360682, 'fraction_numerical': 0.0006311139160618492, 'mean_word_length': 5.469387755102041, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '1423616', 'n_tokens_mistral': 1112, 'n_tokens_neox': 1051, 'n_words': 250}