<commit_before>class Site < ApplicationRecord
  belongs_to :project
  has_many :checks, dependent: :destroy
  validates :name, presence: true, uniqueness: { scope: :project,
                                                 message: 'name must be unique' }
  validates :url, url: true
  validates :custom_status, numericality: { only_integer: true,
                                            greater_than_or_equal_to: 100,
                                            less_than_or_equal_to: 527 }, allow_nil: true

  def active?
    success?
  end

  def state
    last = checks.order('created_at desc').limit(1).first
    return :unknown unless last
    return :active if success?
    return :inactive unless success?
  end

  def uptime
    # Number of checks recieved
    total = checks.count

    # Number of inactive checks
    inactive = inactive_checks.count

    if total.zero?
      nil
    elsif inactive.zero?
      100
    else
      (100 - (inactive.to_f / total.to_f) * 100).round(2)
    end
  end

  def last_downtime
    inactive_checks.last.try(:created_at)
  end

  def inactive_checks
    if custom_status
      checks.where.not(status: custom_status)
    else
      checks.where('status < 199 OR status > 300 OR status == null')
    end
  end

  def success?
    last = checks.order('created_at desc').limit(1).first
    return false unless last && last.status

    if custom_status
      last.status == custom_status
    else
      last.status.between?(200, 299)
    end
  end
end
<commit_msg>:bug: dont check if status is null (#51)<commit_after>class Site < ApplicationRecord
  belongs_to :project
  has_many :checks, dependent: :destroy
  validates :name, presence: true, uniqueness: { scope: :project,
                                                 message: 'name must be unique' }
  validates :url, url: true
  validates :custom_status, numericality: { only_integer: true,
                                            greater_than_or_equal_to: 100,
                                            less_than_or_equal_to: 527 }, allow_nil: true

  def active?
    success?
  end

  def state
    last = checks.order('created_at desc').limit(1).first
    return :unknown unless last
    return :active if success?
    return :inactive unless success?
  end

  def uptime
    # Number of checks recieved
    total = checks.count

    # Number of inactive checks
    inactive = inactive_checks.count

    if total.zero?
      nil
    elsif inactive.zero?
      100
    else
      (100 - (inactive.to_f / total.to_f) * 100).round(2)
    end
  end

  def last_downtime
    inactive_checks.last.try(:created_at)
  end

  def inactive_checks
    if custom_status
      checks.where.not(status: custom_status)
    else
      checks.where('status < 199 OR status > 300')
    end
  end

  def success?
    last = checks.order('created_at desc').limit(1).first
    return false unless last && last.status

    if custom_status
      last.status == custom_status
    else
      last.status.between?(200, 299)
    end
  end
end

{'fraction_non_alphanumeric': 0.07874794069192752, 'fraction_numerical': 0.02042833607907743, 'mean_word_length': 2.1559251559251558, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '305064', 'n_tokens_mistral': 951, 'n_tokens_neox': 861, 'n_words': 256}