<commit_before>class Pod < ActiveRecord::Base
  has_many :instructions
  has_many :shipments
  
  validates :month, uniqueness: true
  
  rails_admin do
    object_label_method :to_param
  end

  def shipping_crops(organic = false)
    crops = instructions.where(ship: true).map{|x| x.crop}
    if organic
      crops = crops.select{|x| x.organic == true}
    else
      crops = crops.select{|x| x.non_organic == true}
    end
  end

  def self.find_by_date(date)
    Pod.where(month: Date.strptime(date, "%Y-%m")).first
  end

  def previous_pod(user)
    if !previous_pod = Pod.where(month: month << 1).first
      return false
    end

    if user && !previous_pod.shipped_to?(user)
      return false
    end

    previous_pod
  end

  def next_pod(user)
    if !next_pod = Pod.where(month: month >> 1).first
      return false
    end

    if user && !next_pod.shipped_to?(user)
      return false
    end

    next_pod
  end

  def to_param
    month.strftime("%Y-%m")
  end

  def self.accepting_payments
    Pod.where(month: (Date.today + 10.days).beginning_of_month).first
  end

  def self.currently_shipping
    Pod.where(month: Date.today.beginning_of_month).first
  end

  def shipped_to?(user)
    shipments.where(user: user).first.present?
  end

  def self.discount(months: 1)
    case months
    when 1..5
      0
    when 6..8
      0.05
    when 9..11
      0.10
    else
      0.15
    end
  end

  def self.base_price_per_month(organic: false)
    if organic
      Pod.base_price_per_month + 1.00
    else
      5.95
    end
  end

  def self.price(months: 1, organic: false)
    (Pod.base_price_per_month(organic: organic) * months * (1.0-Pod.discount(months: months))).round(2)
  end
  
  def self.generate_future_pods!<commit_msg>Emergency generate pods before hitting weird error<commit_after>class Pod < ActiveRecord::Base
  has_many :instructions
  has_many :shipments

  validates :month, uniqueness: true

  rails_admin do
    object_label_method :to_param
  end

  def shipping_crops(organic = false)
    crops = instructions.where(ship: true).map{|x| x.crop}
    if organic
      crops = crops.select{|x| x.organic == true}
    else
      crops = crops.select{|x| x.non_organic == true}
    end
  end

  def self.find_by_date(date)
    Pod.where(month: Date.strptime(date, "%Y-%m")).first
  end

  def previous_pod(user)
    if !previous_pod = Pod.where(month: month << 1).first
      return false
    end

    if user && !previous_pod.shipped_to?(user)
      return false
    end

    previous_pod
  end

  def next_pod(user)
    if !next_pod = Pod.where(month: month >> 1).first
      return false
    end

    if user && !next_pod.shipped_to?(user)
      return false
    end

    next_pod
  end

  def to_param
    month.strftime("%Y-%m")
  end

  def self.accepting_payments
    Pod.where(month: (Date.today + 10.days).beginning_of_month).first
  end

  def self.currently_shipping
    if !(pod = Pod.where(month: Date.today.beginning_of_month).first)
      Pod.generate_future_pods!
      Pod.currently_shipping
    end
    pod
  end

  def shipped_to?(user)
    shipments.where(user: user).first.present?
  end

  def self.discount(months: 1)
    case months
    when 1..5
      0
    when 6..8
      0.05
    when 9..11
      0.10
    else
      0.15
    end
  end

  def self.base_price_per_month(organic: false)
    if organic
      Pod.base_price_per_month + 1.00
    else
      5.95
    end
  end

  def self.price(months: 1, organic: false)
    (Pod.base_price_per_month(organic: organic) * months * (1.0-Pod.discount(months: months))).round(2)
  end

  def self.generate_future_pods!
{'fraction_non_alphanumeric': 0.10281146637265712, 'fraction_numerical': 0.017640573318632856, 'mean_word_length': 2.643574297188755, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '6110744', 'n_tokens_mistral': 1368, 'n_tokens_neox': 1276, 'n_words': 291}