<commit_before>class PaypalOrder < ActiveRecord::Base
  include PaypalPayment

  belongs_to :product
  belongs_to :user

  attr_accessible :product, :product_id, :payment_id, :payer_id, :status, :gift
  delegate :name, :to => :product, :allow_nil => true, :prefix => true

  validates_presence_of :user_id, :product_id

  def complete_payment!
    update_attributes(:status => "Completed")
    if gift?
      GeneratePaypalVoucher.new(self).perform
    else
      GrantPerks.new(product, user).perform
    end
    announce_donator
  end

  def announce_donator
    AnnounceDonatorWorker.perform_async(self.id)
  end

  def self.monthly_total(now = Time.current)
    completed.monthly(now).joins(:product).sum('products.price')
  end

  def self.completed
    where(:status => "Completed")
  end

  def self.monthly_goal_percentage(now = Time.current)
    (monthly_total(now) / monthly_goal) * 100.0
  end

  def self.monthly(now = Time.current)
    beginning_of_month = now.beginning_of_month
    end_of_month = now.end_of_month
    where('paypal_orders.created_at > ? AND paypal_orders.created_at < ?', beginning_of_month, end_of_month)
  end

  def self.leaderboard
    completed.group(:user).joins(:user).joins(:product).sum('products.price').sort_by do |user, amount|
      amount
    end.reverse
  end

  def self.monthly_goal(site_host = SITE_HOST)
    if site_host == "serveme.tf"
      250.0
    elsif site_host == "na.serveme.tf"
      100.0
    else<commit_msg>have EU target closer match costs<commit_after>class PaypalOrder < ActiveRecord::Base
  include PaypalPayment

  belongs_to :product
  belongs_to :user

  attr_accessible :product, :product_id, :payment_id, :payer_id, :status, :gift
  delegate :name, :to => :product, :allow_nil => true, :prefix => true

  validates_presence_of :user_id, :product_id

  def complete_payment!
    update_attributes(:status => "Completed")
    if gift?
      GeneratePaypalVoucher.new(self).perform
    else
      GrantPerks.new(product, user).perform
    end
    announce_donator
  end

  def announce_donator
    AnnounceDonatorWorker.perform_async(self.id)
  end

  def self.monthly_total(now = Time.current)
    completed.monthly(now).joins(:product).sum('products.price')
  end

  def self.completed
    where(:status => "Completed")
  end

  def self.monthly_goal_percentage(now = Time.current)
    (monthly_total(now) / monthly_goal) * 100.0
  end

  def self.monthly(now = Time.current)
    beginning_of_month = now.beginning_of_month
    end_of_month = now.end_of_month
    where('paypal_orders.created_at > ? AND paypal_orders.created_at < ?', beginning_of_month, end_of_month)
  end

  def self.leaderboard
    completed.group(:user).joins(:user).joins(:product).sum('products.price').sort_by do |user, amount|
      amount
    end.reverse
  end

  def self.monthly_goal(site_host = SITE_HOST)
    if site_host == "serveme.tf"
      300.0
    elsif site_host == "na.serveme.tf"
      100.0
    else
{'fraction_non_alphanumeric': 0.10668467251856853, 'fraction_numerical': 0.008102633355840648, 'mean_word_length': 3.857377049180328, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, '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': '2456738', 'n_tokens_mistral': 1044, 'n_tokens_neox': 1003, 'n_words': 194}