<commit_before>class Person < ActiveRecord::Base
  extend FriendlyId
  include Elasticsearch::Model
  include Elasticsearch::Model::Callbacks

  DAYS_WORKED = [
    :works_monday,
    :works_tuesday,
    :works_wednesday,
    :works_thursday,
    :works_friday,
    :works_saturday,
    :works_sunday,
  ]

  index_name [Rails.env, model_name.collection.gsub(/\//, '-')].join('_')

  has_paper_trail ignore: [:updated_at, :created_at, :id]
  acts_as_paranoid
  mount_uploader :image, ImageUploader

  validates_presence_of :surname
  has_many :memberships, dependent: :destroy
  has_many :groups, through: :memberships

  default_scope { order(surname: :asc, given_name: :asc) }

  friendly_id :slug_source, use: :slugged

  def name
    [given_name, surname].compact.join(' ').strip
  end

  def to_s
    name
  end

  def completion_score
    completed = [
      :given_name,
      :surname,
      :email,
      :phone,
      :mobile,
      :location,
      :description,
      :groups
    ].map { |f| self.send(f).present? }
    (100 * completed.select { |f| f }.length) / completed.length
  end

  def profile_completed?
    completion_score == 100
  end

  def slug_source
    if email.present?
      email.split(/@/).first
    else
      name
    end
  end

  def self.delete_indexes
    self.__elasticsearch__.delete_index! index: Person.index_name
  end

  def as_indexed_json(options={})
    self.as_json(
      only: [:description, :location],
      methods: [:name, :role_and_group]
    )
  end

  def role_and_group
    memberships.map{ |m| [m.group_name, m.role].join(', ') }.join("; ")
  end

  def self.fuzzy_search(query)
    Person.search({
      size: 100,
      query: {
        fuzzy_like_this: {
          fields: [:name, :description, :location, :role_and_group],
          like_text: query,
          prefix_length: 3,
          ignore_tf: true
        }
      }
    })
  end
end<commit_msg>Gather class variables in one place<commit_after>class Person < ActiveRecord::Base
  extend FriendlyId
  include Elasticsearch::Model
  include Elasticsearch::Model::Callbacks

  DAYS_WORKED = [
    :works_monday,
    :works_tuesday,
    :works_wednesday,
    :works_thursday,
    :works_friday,
    :works_saturday,
    :works_sunday,
  ]

  index_name [Rails.env, model_name.collection.gsub(/\//, '-')].join('_')

  has_paper_trail ignore: [:updated_at, :created_at, :id]
  acts_as_paranoid
  mount_uploader :image, ImageUploader

  validates_presence_of :surname
  has_many :memberships, dependent: :destroy
  has_many :groups, through: :memberships

  default_scope { order(surname: :asc, given_name: :asc) }

  friendly_id :slug_source, use: :slugged

  def self.delete_indexes
    self.__elasticsearch__.delete_index! index: Person.index_name
  end

  def self.fuzzy_search(query)
    Person.search({
      size: 100,
      query: {
        fuzzy_like_this: {
          fields: [:name, :description, :location, :role_and_group],
          like_text: query,
          prefix_length: 3,
          ignore_tf: true
        }
      }
    })
  end

  def name
    [given_name, surname].compact.join(' ').strip
  end

  def to_s
    name
  end

  def completion_score
    completed = [
      :given_name,
      :surname,
      :email,
      :phone,
      :mobile,
      :location,
      :description,
      :groups
    ].map { |f| self.send(f).present? }
    (100 * completed.select { |f| f }.length) / completed.length
  end

  def profile_completed?
    completion_score == 100
  end

  def slug_source
    if email.present?
      email.split(/@/).first
    else
      name
    end
  end

  def as_indexed_json(options={})
    self.as_json(
      only: [:description, :location],
      methods: [:name, :role_and_group]
    )
  end

  def role_and_group
    memberships.map{ |m| [m.group_name, m.role].join(', ') }.join("; ")
  end
end
{'fraction_non_alphanumeric': 0.11636363636363636, 'fraction_numerical': 0.005194805194805195, 'mean_word_length': 2.768101761252446, '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': '4398739', 'n_tokens_mistral': 1401, 'n_tokens_neox': 1332, 'n_words': 280}