<commit_before>class Idea < ActiveRecord::Base
  include ActiveRecord::UUID
  include Kaminari::ActiveRecordModelExtension

  extend FriendlyId

  friendly_id :slug_candidates, use: :slugged

  belongs_to :product
  belongs_to :user

  has_many :markings, as: :markable
  has_many :marks, through: :markings
  has_one :news_feed_item, foreign_key: 'target_id'

  delegate :news_feed_item_comments, to: :news_feed_item

  validates :name, presence: true,
                   length: { minimum: 2, maximum: 255 },
                   exclusion: { in: Product::EXCLUSIONS }
  validates :tilting_threshold, presence: true
  validate :idea_and_product_have_same_user

  before_validation :set_tilting_threshold!, on: :create

  after_commit :ensure_news_feed_item, on: :create
  after_commit :touch_news_feed_item, on: :update

  default_scope -> { where(deleted_at: nil) }

  scope :by, -> (user) { where(user_id: user.id) }
  scope :hearts, -> { includes(:news_feed_item).order('news_feed_items.hearts_count DESC') }
  scope :greenlit, -> { where.not(greenlit_at: nil) }
  scope :newness, -> { order(created_at: :desc) }
  scope :trending, -> { order(score: :desc) }
  scope :with_mark,  -> (name) { joins(:marks).where(marks: { name: name }) }
  scope :with_percentile, -> (percentile) {
    all.sort_by(&:percentile).
    take(percentile * all.count/100)
  }
  scope :with_topic, -> (topic) { where("? = ANY(topics)", topic) }
  scope :recently_tilted, -> { joins(:product).unscope(where: :product_id).merge(Product.where('products.created_at > ?', 2.weeks.ago)).where.not(product_id: nil) }

  HEARTBURN = 30.days  # period for 100% inflation, equivalent to half-life
  EPOCH_START = Time.new(2013, 6, 6)

  DEFAULT_TILTING_THRESHOLD = 0
  COMMENT_MINIMUM = 5

  CATEGORY_NAMES = [
    "Ideas searching for names",
    "Fresh ideas discussing strategy"
  ]

  CATEGORY_SLUGS = CATEGORY_NAMES.map { |name| name.downcase.gsub(/ /, "-") }

  TOPIC_NAMES = [
    "Art & Design",
    "Education",
    "Entertainment & Games",
    "Family & Lifestyle",
    "Mobile",
    "Productivity & Tools",
    "SaaS",
    "Social"
  ]

  TOPIC_SLUGS = TOPIC_NAMES.map { |name| name.downcase.gsub(/ /, "-") }

  def slug_candidates
    [
      :name,
      [:creator_username, :name],<commit_msg>reverted constants back to correct value<commit_after>class Idea < ActiveRecord::Base
  include ActiveRecord::UUID
  include Kaminari::ActiveRecordModelExtension

  extend FriendlyId

  friendly_id :slug_candidates, use: :slugged

  belongs_to :product
  belongs_to :user

  has_many :markings, as: :markable
  has_many :marks, through: :markings
  has_one :news_feed_item, foreign_key: 'target_id'

  delegate :news_feed_item_comments, to: :news_feed_item

  validates :name, presence: true,
                   length: { minimum: 2, maximum: 255 },
                   exclusion: { in: Product::EXCLUSIONS }
  validates :tilting_threshold, presence: true
  validate :idea_and_product_have_same_user

  before_validation :set_tilting_threshold!, on: :create

  after_commit :ensure_news_feed_item, on: :create
  after_commit :touch_news_feed_item, on: :update

  default_scope -> { where(deleted_at: nil) }

  scope :by, -> (user) { where(user_id: user.id) }
  scope :hearts, -> { includes(:news_feed_item).order('news_feed_items.hearts_count DESC') }
  scope :greenlit, -> { where.not(greenlit_at: nil) }
  scope :newness, -> { order(created_at: :desc) }
  scope :trending, -> { order(score: :desc) }
  scope :with_mark,  -> (name) { joins(:marks).where(marks: { name: name }) }
  scope :with_percentile, -> (percentile) {
    all.sort_by(&:percentile).
    take(percentile * all.count/100)
  }
  scope :with_topic, -> (topic) { where("? = ANY(topics)", topic) }
  scope :recently_tilted, -> { joins(:product).unscope(where: :product_id).merge(Product.where('products.created_at > ?', 2.weeks.ago)).where.not(product_id: nil) }

  HEARTBURN = 30.days  # period for 100% inflation, equivalent to half-life
  EPOCH_START = Time.new(2013, 6, 6)

  DEFAULT_TILTING_THRESHOLD = 15
  COMMENT_MINIMUM = 5

  CATEGORY_NAMES = [
    "Ideas searching for names",
    "Fresh ideas discussing strategy"
  ]

  CATEGORY_SLUGS = CATEGORY_NAMES.map { |name| name.downcase.gsub(/ /, "-") }

  TOPIC_NAMES = [
    "Art & Design",
    "Education",
    "Entertainment & Games",
    "Family & Lifestyle",
    "Mobile",
    "Productivity & Tools",
    "SaaS",
    "Social"
  ]

  TOPIC_SLUGS = TOPIC_NAMES.map { |name| name.downcase.gsub(/ /, "-") }

  def slug_candidates
    [
      :name,
      [:creator_username, :name],
{'fraction_non_alphanumeric': 0.13580786026200872, 'fraction_numerical': 0.009388646288209608, 'mean_word_length': 3.8630573248407645, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4074192', 'n_tokens_mistral': 1718, 'n_tokens_neox': 1612, 'n_words': 330}