<commit_before># irsea - quote.rb
# Author    :: <NAME>
# License   :: BSD License
# Copyright :: Copyright (C) 2009 <NAME>

# irsea quote
class Quote
  include DataMapper::Resource
  
  property :id,        Serial
  property :title,     String,   :length  => 256, :nullable => false
  property :text,      Text,     :lazy    => false, :nullable => false
  property :posted,    DateTime
  property :spamvotes, Integer,  :default => 0
  property :deleted,   Boolean,  :default => false
  property :upvotes,   Integer,  :default => 0
  property :downvotes, Integer,  :default => 0
  
  has n, :comments
  has n, :tags
  
  belongs_to :user
  belongs_to :network
  belongs_to :channel

  def self.recent
    all(:limit => 10, :order => [:posted.desc])
  end
  
  # Returns a set of random quotes, an optional count may be specified.  Quotes
  # are not guaranteed to be unique.
  # @param [Integer] return_count Number of quotes to return
  def self.random(return_count = 10)
    quotes = []
    quote_count = Quote.count
    selected = 0
    
    while selected < return_count do
      qid = 1+rand(quote_count)
      # Ensure the quote exists and isn't marked as deleted, since we can't
      # trust people to alway use common sense and just mark a quote as deleted
      # instead of DROP'ing the row
      unless Quote and Quote.deleted == true
        quote = Quote.get(qid)
        if quote != nil
          quotes << quote
          selected += 1
        end
      end
    end
    
    quotes<commit_msg>Made the random lists not pick a quote twice.<commit_after># irsea - quote.rb
# Author    :: <NAME>
# License   :: BSD License
# Copyright :: Copyright (C) 2009 <NAME>

# irsea quote
class Quote
  include DataMapper::Resource
  
  property :id,        Serial
  property :title,     String,   :length  => 256, :nullable => false
  property :text,      Text,     :lazy    => false, :nullable => false
  property :posted,    DateTime
  property :spamvotes, Integer,  :default => 0
  property :deleted,   Boolean,  :default => false
  property :upvotes,   Integer,  :default => 0
  property :downvotes, Integer,  :default => 0
  
  has n, :comments
  has n, :tags
  
  belongs_to :user
  belongs_to :network
  belongs_to :channel

  def self.recent
    all(:limit => 10, :order => [:posted.desc])
  end
  
  # Returns a set of random quotes, an optional count may be specified.  Quotes
  # are guaranteed to be unique.
  # This could be made more efficient.
  # @param [Integer] return_count Number of quotes to return
  def self.random(return_count = 10)
    quotes = []
    quote_count = Quote.count
    selected = 0
    
    while selected < return_count do
      qid = 1+rand(quote_count)
      # Ensure the quote exists and isn't marked as deleted, since we can't
      # trust people to alway use common sense and just mark a quote as deleted
      # instead of DROP'ing the row
      unless Quote and Quote.deleted == true
        quote = Quote.get(qid)
        if quote != nil and quotes.index(quote)
          quotes << quote
          selected += 1
        end
      end
    end
    
    quotes
{'fraction_non_alphanumeric': 0.09006111289803795, 'fraction_numerical': 0.010935992280476037, 'mean_word_length': 2.5421412300683373, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 27, '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': '2313906', 'n_tokens_mistral': 972, 'n_tokens_neox': 946, 'n_words': 350}