<commit_before># It seems Application is NOT a name you want to use; rails
# breaks in baffling places.  So I named it appln, it's shorter
# anyways!
# 
class Appln < ActiveRecord::Base
  belongs_to :viewer
  belongs_to :form
  
  has_many :answers, :foreign_key => :instance_id
  has_many :profiles
  
  has_many :reference_instances, :class_name => 'ApplnReference', :foreign_key => 'instance_id', :order => :reference_id
  
  belongs_to :preference1, :class_name => "Project", :foreign_key => :preference1_id
  belongs_to :preference2, :class_name => "Project", :foreign_key => :preference2_id
  
  has_one :processor_form
  
  def acceptances
    profiles.reject { |p| p.class != Acceptance }
  end
  
  def person() viewer.person end
  def status() profile.status end
  def status=(val) profile.status = val end
  def completed_at() profile.completed_at end
  def accepted_at() profile.accepted_at end
  def withdrawn_at() profile.withdrawn_at end
  def submitted?() profile.class == Applying && 
           profile.status != 'started' && profile.status != 'unsubmitted' end
  def withdrawn?() profile.class == Withdrawn end
  def completed?() profile.class == Applying && profile.status == 'completed' end
  def accepted?() profile.class == Acceptance end
  
  def Appln.find_all_by_status(s, options = {})
    options[:include] ||= []
    options[:include] = [ options[:include] ] if options[:include].class == Symbol
    options[:include] << :profiles
    # expects :conditions as an array with 2 elements, the second being a hash
    if !options.has_key?("conditions")
      options[:conditions] = ['', {}]
    else
      options[:conditions][0] += " and "  # append status to conditions
    end
    options[:conditions][0] += "status = :status"
    options[:conditions][1][:status] = s
    Appln.find(:all, options)
  end
  
  def full_name
    [self.form.event_group.parent.title, self.form.event_group.title, self.form.name].join(" ")
  end
  
  def profile
    p = profiles[0]
    if p.nil?
      p = Applying.new :appln_id => id, :status => 'started', :viewer_id => viewer_id
      p.save!
      profiles << p
    end
    p
  end
  
  def editable?
    profile.class == Applying && 
      Appln.unsubmitted_statuses.include?(status)
  end
  
  # The statuses that mean an application has NOT been submitted
  def self.unsubmitted_statuses
    %w(started unsubmitted)
  end
  
  # The statuses that mean an applicant is NOT ready to evaluate
  def self.not_ready_statuses
    %w(submitted withdrawn)
  end
<commit_msg>fixed bug where it assumed the event group had a parent<commit_after># It seems Application is NOT a name you want to use; rails
# breaks in baffling places.  So I named it appln, it's shorter
# anyways!
# 
class Appln < ActiveRecord::Base
  belongs_to :viewer
  belongs_to :form
  
  has_many :answers, :foreign_key => :instance_id
  has_many :profiles
  
  has_many :reference_instances, :class_name => 'ApplnReference', :foreign_key => 'instance_id', :order => :reference_id
  
  belongs_to :preference1, :class_name => "Project", :foreign_key => :preference1_id
  belongs_to :preference2, :class_name => "Project", :foreign_key => :preference2_id
  
  has_one :processor_form
  
  def acceptances
    profiles.reject { |p| p.class != Acceptance }
  end
  
  def person() viewer.person end
  def status() profile.status end
  def status=(val) profile.status = val end
  def completed_at() profile.completed_at end
  def accepted_at() profile.accepted_at end
  def withdrawn_at() profile.withdrawn_at end
  def submitted?() profile.class == Applying && 
           profile.status != 'started' && profile.status != 'unsubmitted' end
  def withdrawn?() profile.class == Withdrawn end
  def completed?() profile.class == Applying && profile.status == 'completed' end
  def accepted?() profile.class == Acceptance end
  
  def Appln.find_all_by_status(s, options = {})
    options[:include] ||= []
    options[:include] = [ options[:include] ] if options[:include].class == Symbol
    options[:include] << :profiles
    # expects :conditions as an array with 2 elements, the second being a hash
    if !options.has_key?("conditions")
      options[:conditions] = ['', {}]
    else
      options[:conditions][0] += " and "  # append status to conditions
    end
    options[:conditions][0] += "status = :status"
    options[:conditions][1][:status] = s
    Appln.find(:all, options)
  end
  
  def full_name
    [(self.form.event_group.parent.title if self.form.event_group.parent).to_s, self.form.event_group.title, self.form.name].join(" ")
  end
  
  def profile
    p = profiles[0]
    if p.nil?
      p = Applying.new :appln_id => id, :status => 'started', :viewer_id => viewer_id
      p.save!
      profiles << p
    end
    p
  end
  
  def editable?
    profile.class == Applying && 
      Appln.unsubmitted_statuses.include?(status)
  end
  
  # The statuses that mean an application has NOT been submitted
  def self.unsubmitted_statuses
    %w(started unsubmitted)
  end
  
  # The statuses that mean an applicant is NOT ready to evaluate
  def self.not_ready_statuses
    %w(submitted withdrawn)
  end

{'fraction_non_alphanumeric': 0.11588566984250437, 'fraction_numerical': 0.00349990278047832, 'mean_word_length': 3.5969615728328863, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 25, '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': '5157537', 'n_tokens_mistral': 1676, 'n_tokens_neox': 1622, 'n_words': 460}