<commit_before>class Status < ActiveRecord::Base
  belongs_to :campaign
  has_many :donated_statuses
  has_many :donations, :through => :donated_statuses

  validates_presence_of :campaign, :body
  validates_length_of :body, :maximum=>140, :minimum => 1

  scope :donated_through_account, lambda {|a| {:joins => "INNER JOIN donated_statuses ON donated_statuses.status_id = statuses.id INNER JOIN donations ON donations.id = donated_statuses.donation_id INNER JOIN accounts ON donations.account_id = accounts.id ", :conditions => ["accounts.id = ?", a.id], :group => "statuses.id" } }  
  scope :desc, order("statuses.id desc")
  scope :within_1_day, :conditions => ["statuses.created_at > ?", Time.now - 1.days]
  scope :within_1_week, :conditions => ["statuses.created_at > ?", Time.now - 7.days]
  scope :within_1_month, :conditions => ["statuses.created_at > ?", Time.now - 28.days]
  scope :for_levels, lambda {|levels| {:conditions => levels.collect{|l| "statuses.level = #{l}"}.join(" OR ")}}

  attr_accessor :levels

  before_create do
    tweet = Twitter::Client.new(:oauth_token => self.campaign.account.token, :oauth_token_secret => self.campaign.account.secret)
    response = tweet.update(self.body)
    self.twitter_status_id = response["id"]
  end

  after_create do
    self.delay.publish
  end

  def publish
    unless self.twitter_status_id.blank?
      level_array = []
      level_array << Donation::LEVELS["Gold"] if (self.level & Donation::LEVELS["Gold"])
      level_array << Donation::LEVELS["Silver"] if (self.level & Donation::LEVELS["Silver"])
      level_array << Donation::LEVELS["Bronze"] if (self.level & Donation::LEVELS["Bronze"])
      self.campaign.donations.for_levels(level_array).each do |donation|
        donation.donated_statuses.create(:status => self)
      end
    end
  end

  def validate
    accumulator = 0
    if self.levels.is_a?(Array)
      self.levels.each do |l|
        accumulator += l.to_i
      end<commit_msg>Fix for donation levels code<commit_after>class Status < ActiveRecord::Base
  belongs_to :campaign
  has_many :donated_statuses
  has_many :donations, :through => :donated_statuses

  validates_presence_of :campaign, :body
  validates_length_of :body, :maximum=>140, :minimum => 1

  scope :donated_through_account, lambda {|a| {:joins => "INNER JOIN donated_statuses ON donated_statuses.status_id = statuses.id INNER JOIN donations ON donations.id = donated_statuses.donation_id INNER JOIN accounts ON donations.account_id = accounts.id ", :conditions => ["accounts.id = ?", a.id], :group => "statuses.id" } }  
  scope :desc, order("statuses.id desc")
  scope :within_1_day, :conditions => ["statuses.created_at > ?", Time.now - 1.days]
  scope :within_1_week, :conditions => ["statuses.created_at > ?", Time.now - 7.days]
  scope :within_1_month, :conditions => ["statuses.created_at > ?", Time.now - 28.days]
  scope :for_levels, lambda {|levels| {:conditions => levels.collect{|l| "statuses.level = #{l}"}.join(" OR ")}}

  attr_accessor :levels

  before_create do
    tweet = Twitter::Client.new(:oauth_token => self.campaign.account.token, :oauth_token_secret => self.campaign.account.secret)
    response = tweet.update(self.body)
    self.twitter_status_id = response["id"]
  end

  after_create do
    self.delay.publish
  end

  def publish
    unless self.twitter_status_id.blank?
      level_array = []
      level_array << Donation::LEVELS["Gold"] if ((self.level & Donation::LEVELS["Gold"]) > 0)
      level_array << Donation::LEVELS["Silver"] if ((self.level & Donation::LEVELS["Silver"]) > 0)
      level_array << Donation::LEVELS["Bronze"] if ((self.level & Donation::LEVELS["Bronze"]) > 0)
      self.campaign.donations.for_levels(level_array).each do |donation|
        donation.donated_statuses.create(:status => self)
      end
    end
  end

  def validate
    accumulator = 0
    if self.levels.is_a?(Array)
      self.levels.each do |l|
        accumulator += l.to_i
      end
{'fraction_non_alphanumeric': 0.13925963233442457, 'fraction_numerical': 0.006799294887937547, 'mean_word_length': 4.205766710353866, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 38, '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': '6918289', 'n_tokens_mistral': 1386, 'n_tokens_neox': 1289, 'n_words': 278}