<commit_before># encoding: utf-8

class Post < ActiveRecord::Base
  extend FriendlyId
  friendly_id :title, :use => :slugged

  has_many :comments, :dependent => :destroy
  has_many :audios,   :dependent => :destroy

  validates :title, :presence => true
  validate :validate_status

  scope :published, where(:status => 'published')
  scope :lifo, order('created_at DESC')
  scope :this_month, where(:created_at => Date.today.beginning_of_month..Date.today.end_of_month)

  def self.statuses
    ['published', 'draft', 'deleted']
  end

  def self.created_on(year, month = nil, day = nil)
    date = Date.new year.to_i

    if month.present?
      date = date.change( :month => month.to_i )
      if day.present?
        date = date.change( :day => day.to_i )
        range_date = date.beginning_of_day..date.end_of_day
      else
        range_date = date.beginning_of_month..date.end_of_month
      end
    else
      range_date = date.beginning_of_year..date.end_of_year
    end

    where(:created_at => range_date)
  end

  def self.post_count_by_month
    sql = <<-SQL
    SELECT DISTINCT
      YEAR(created_at) "year",
      MONTH(created_at) "month",
      COUNT(*) AS count
    FROM
      posts
    WHERE
      status = 'published'
    GROUP BY
      year, month
    ORDER BY
      year DESC, month DESC
    SQL

    self.find_by_sql(sql)
  end
<commit_msg>Fix date range border problem<commit_after># encoding: utf-8

class Post < ActiveRecord::Base
  extend FriendlyId
  friendly_id :title, :use => :slugged

  has_many :comments, :dependent => :destroy
  has_many :audios,   :dependent => :destroy

  validates :title, :presence => true
  validate :validate_status

  scope :published, where(:status => 'published')
  scope :lifo, order('created_at DESC')
  scope :this_month, where(:created_at => Date.today.beginning_of_month..Date.today.end_of_month)

  def self.statuses
    ['published', 'draft', 'deleted']
  end

  def self.created_on(year, month = nil, day = nil)
    date = Date.new year.to_i

    if month.present?
      date = date.change( :month => month.to_i )
      if day.present?
        date = date.change( :day => day.to_i )
        range_date = date.beginning_of_day..date.end_of_day
      else
        range_date = date.beginning_of_month.beginning_of_day..date.end_of_month.end_of_day
      end
    else
      range_date = date.beginning_of_year.beginning_of_day..date.end_of_year.end_of_day
    end

    where(:created_at => range_date)
  end

  def self.post_count_by_month
    sql = <<-SQL
    SELECT DISTINCT
      YEAR(created_at) "year",
      MONTH(created_at) "month",
      COUNT(*) AS count
    FROM
      posts
    WHERE
      status = 'published'
    GROUP BY
      year, month
    ORDER BY
      year DESC, month DESC
    SQL

    self.find_by_sql(sql)
  end

{'fraction_non_alphanumeric': 0.10691375623663578, 'fraction_numerical': 0.0007127583749109052, 'mean_word_length': 2.8824343015214384, 'pattern_counts': {'":': 0, '<': 9, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5478929', 'n_tokens_mistral': 983, 'n_tokens_neox': 952, 'n_words': 222}