<commit_before>class Chapter < ActiveRecord::Base

  # my bone dry solution to search, sort and paginate
  include SearchSortPaginate
  
  BANNER_WIDTH = 1400
  BANNER_HEIGHT = 676
  
  define_index do
    indexes name
    indexes description
    indexes talk(:name), :as => :talk, :sortable => true
    has talk_id, created_at, updated_at
    group_by "talk_id"
  end

  belongs_to :talk
  has_many :performances
  has_many :speakers, :through => :performances
  accepts_nested_attributes_for :performances, :allow_destroy => true

  has_many :chapter_photos
  accepts_nested_attributes_for :chapter_photos, :allow_destroy => true
  
  # we have a polymorphic relationship with notes
  has_many :notes, :as => :asset
  
  validates :sort, :presence => true
  validates_uniqueness_of :sort, :scope => :talk_id
  validate :validate_banner_dimensions, :if => "banner.present?", :unless => "errors.any?"
  validate :validate_homepage_banner_dimensions, :if => "homepage_banner.present?", :unless => "errors.any?"
  
  scope :by_sort, order('sort asc')
  scope :talk_featured, :conditions => {:featured_on_talk => true}
  scope :homepage_featured, :conditions => {:featured_on_homepage => true}
  
  # Simple way to separate current chapters from archived
  #scope :current, joins(Talk).where('id = self.talk_id').joins(:day).where("days.year_id != #{DateTime.now.year}")
  
  #scope :current, joins(self.Talk.years).where("years.id = #{DateTime.now.year}")
  #scope :current, 
  #scope :archived, joins(:years).where("years.id != #{DateTime.now.year}")
  <commit_msg>fixed scopes<commit_after>class Chapter < ActiveRecord::Base

  # my bone dry solution to search, sort and paginate
  include SearchSortPaginate
  
  BANNER_WIDTH = 1400
  BANNER_HEIGHT = 676
  
  define_index do
    indexes name
    indexes description
    indexes talk(:name), :as => :talk, :sortable => true
    has talk_id, created_at, updated_at
    group_by "talk_id"
  end
  
  
  belongs_to :talk
  has_many :performances
  has_many :speakers, :through => :performances
  accepts_nested_attributes_for :performances, :allow_destroy => true

  has_many :chapter_photos
  accepts_nested_attributes_for :chapter_photos, :allow_destroy => true
  
  # we have a polymorphic relationship with notes
  has_many :notes, :as => :asset
  
  validates :sort, :presence => true
  validates_uniqueness_of :sort, :scope => :talk_id
  validate :validate_banner_dimensions, :if => "banner.present?", :unless => "errors.any?"
  validate :validate_homepage_banner_dimensions, :if => "homepage_banner.present?", :unless => "errors.any?"
  
  scope :by_sort, order('sort asc')
  
  

  scope :current, joins(:talk).joins('LEFT JOIN days ON talks.day_id = days.id').where("days.year_id = #{DateTime.now.year}")
 
  
  scope :archived, joins(:talk).joins('LEFT JOIN days ON talks.day_id = days.id').where("days.year_id != #{DateTime.now.year}")
  
  scope :talk_featured, :conditions => {:featured_on_talk => true}
  scope :homepage_featured, :conditions => {:featured_on_homepage => true}
  
  # Simple way to separate current chapters from archived
  #scope :current, joins(Talk).where('id = self.talk_id').joins(:day).where("days.year_id != #{DateTime.now.year}")
  
  #scope :current, joins(self.Talk.years).where("years.id = #{DateTime.now.year}")
  #scope :current, 
  #scope :archived, joins(:years).where("years.id != #{DateTime.now.year}")
  
{'fraction_non_alphanumeric': 0.1290796824463393, 'fraction_numerical': 0.004116436342252279, 'mean_word_length': 4.67, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, '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': '2842315', 'n_tokens_mistral': 1176, 'n_tokens_neox': 1121, 'n_words': 265}