<commit_before># frozen_string_literal: true
# == Schema Information
#
# Table name: activities
#
#  id                         :bigint           not null, primary key
#  action                     :string(510)      not null
#  recipient_type             :string(510)      not null
#  resources_count            :integer          default(0), not null
#  solo                       :boolean          default(FALSE), not null
#  trackable_type             :string(510)      not null
#  created_at                 :datetime
#  updated_at                 :datetime
#  episode_id                 :bigint
#  episode_record_id          :bigint
#  multiple_episode_record_id :bigint
#  recipient_id               :bigint           not null
#  status_id                  :bigint
#  trackable_id               :bigint           not null
#  user_id                    :bigint           not null
#  work_id                    :bigint
#  work_record_id             :bigint
#
# Indexes
#
#  activities_user_id_idx                          (user_id)
#  index_activities_on_episode_id                  (episode_id)
#  index_activities_on_episode_record_id           (episode_record_id)
#  index_activities_on_multiple_episode_record_id  (multiple_episode_record_id)
#  index_activities_on_status_id                   (status_id)
#  index_activities_on_work_id                     (work_id)
#  index_activities_on_work_record_id              (work_record_id)
#
# Foreign Keys
#
#  activities_user_id_fk  (user_id => users.id) ON DELETE => cascade
#  fk_rails_...           (episode_id => episodes.id)
#  fk_rails_...           (episode_record_id => episode_records.id)
#  fk_rails_...           (multiple_episode_record_id => multiple_episode_records.id)
#  fk_rails_...           (status_id => statuses.id)
#  fk_rails_...           (work_id => works.id)
#  fk_rails_...           (work_record_id => work_records.id)
#

class Activity < ApplicationRecord
  extend Enumerize

  enumerize :action, in: %w(
    create_status
    create_episode_record
    create_work_record
    create_multiple_episode_records
  ), scope: true

  belongs_to :episode, optional: true
  belongs_to :multiple_episode_record, optional: true
  belongs_to :recipient, polymorphic: true
  belongs_to :episode_record, optional: true
  belongs_to :work_record, optional: true
  belongs_to :status, optional: true
  belongs_to :trackable, polymorphic: true
  belongs_to :user
  belongs_to :work, optional: true

  has_many :episode_records, dependent: :destroy
  has_many :statuses, dependent: :destroy
  has_many :work_records, dependent: :destroy

  scope :records_and_reviews, -> { with_action(:create_episode_record, :create_work_record, :create_multiple_episode_records) }

  def resources
    case trackable_type
    when "Status"
      statuses
    when "EpisodeRecord"
      episode_records
    when "WorkRecord"
      work_records
    else
      []
    end
  end

  def deprecated_action
    case action
    when "create_episode_record"
      "create_record"
    when "create_work_record"
      "create_review"<commit_msg>Ignore unused columns<commit_after># frozen_string_literal: true
# == Schema Information
#
# Table name: activities
#
#  id              :bigint           not null, primary key
#  action          :string(510)      not null
#  resources_count :integer          default(0), not null
#  solo            :boolean          default(FALSE), not null
#  trackable_type  :string(510)      not null
#  created_at      :datetime
#  updated_at      :datetime
#  user_id         :bigint           not null
#
# Indexes
#
#  activities_user_id_idx                          (user_id)
#  index_activities_on_episode_id                  (episode_id)
#  index_activities_on_episode_record_id           (episode_record_id)
#  index_activities_on_multiple_episode_record_id  (multiple_episode_record_id)
#  index_activities_on_status_id                   (status_id)
#  index_activities_on_work_id                     (work_id)
#  index_activities_on_work_record_id              (work_record_id)
#
# Foreign Keys
#
#  activities_user_id_fk  (user_id => users.id) ON DELETE => cascade
#  fk_rails_...           (episode_id => episodes.id)
#  fk_rails_...           (episode_record_id => episode_records.id)
#  fk_rails_...           (multiple_episode_record_id => multiple_episode_records.id)
#  fk_rails_...           (status_id => statuses.id)
#  fk_rails_...           (work_id => works.id)
#  fk_rails_...           (work_record_id => work_records.id)
#

class Activity < ApplicationRecord
  extend Enumerize

  self.ignored_columns = %w(
    recipient_id recipient_type trackable_id work_id episode_id status_id episode_record_id
    multiple_episode_record_id work_record_id
  )

  enumerize :action, in: %w(
    create_status
    create_episode_record
    create_work_record
    create_multiple_episode_records
  ), scope: true

  belongs_to :user

  has_many :episode_records, dependent: :destroy
  has_many :statuses, dependent: :destroy
  has_many :work_records, dependent: :destroy

  scope :records_and_reviews, -> { with_action(:create_episode_record, :create_work_record, :create_multiple_episode_records) }

  def resources
    case trackable_type
    when "Status"
      statuses
    when "EpisodeRecord"
      episode_records
    when "WorkRecord"
      work_records
    else
      []
    end
  end

  def deprecated_action
    case action
    when "create_episode_record"
      "create_record"
    when "create_work_record"
      "create_review"
{'fraction_non_alphanumeric': 0.07401375316684763, 'fraction_numerical': 0.003076366268548679, 'mean_word_length': 2.4936788874841973, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1839184', 'n_tokens_mistral': 1812, 'n_tokens_neox': 1737, 'n_words': 350}