<commit_before>class SummaryService
  attr_reader :checked_items, :buyer, :extra,
              :promote_charges, :promote_price,
              :serve_charges, :serve_price, :total_serve_price
  attr_accessor :bulk_price, :discount_price, :retail_price, :promote_price,
                :total_quantity

    def initialize(_checked_items, buyer_id: nil, extra: nil)
    @checked_items = _checked_items
    @buyer = Buyer.find(buyer_id) if buyer_id
    @extra = extra
    compute_total
    compute_promote
    compute_serve
  end

  def compute_price
    @bulk_price = checked_items.sum { |cart_item| cart_item.bulk_price }
  end

  def compute_total
    compute_price
    self.promote_price = checked_items.sum { |cart_item| cart_item.promote_price }
    self.discount_price = checked_items.sum { |cart_item| cart_item.discount_price }
    self.retail_price = checked_items.sum { |cart_item| cart_item.retail_price }
    self.total_quantity = checked_items.sum { |cart_item| cart_item.total_quantity }
  end

  def compute_promote
    @promote_charges = []
    Promote.sequence.each do |quence|
      AmountPromote.total.overall.where(sequence: quence).each do |promote|
        charge = promote.compute_price(bulk_price)
        @promote_charges << charge if charge
      end

      if buyer
        buyer.promotes.total.where(sequence: quence).each do |promote|
          charge = promote.compute_price(bulk_price)
          @promote_charges << charge if charge
        end
      end

      compute_price
    end

    @promote_price = @promote_charges.map(&:subtotal).sum
  end

  def compute_serve
    @serve_charges = []

    QuantityServe.total.overall.each do |serve|
      charge = serve.compute_price(total_quantity, extra)
      @serve_charges << charge if charge.persisted?
    end

    @serve_price = checked_items.sum { |cart_item| cart_item.serve_price }
    @total_serve_price = serve_charges.sum { |i| i.subtotal }
  end

  def total_price
    @total_price ||= @bulk_price + @promote_price + @total_serve_price
  end

end
<commit_msg>default blank hash<commit_after>class SummaryService
  attr_reader :checked_items, :buyer, :extra,
              :promote_charges, :promote_price,
              :serve_charges, :serve_price, :total_serve_price
  attr_accessor :bulk_price, :discount_price, :retail_price, :promote_price,
                :total_quantity

    def initialize(_checked_items, buyer_id: nil, extra: {})
    @checked_items = _checked_items
    @buyer = Buyer.find(buyer_id) if buyer_id
    @extra = extra
    compute_total
    compute_promote
    compute_serve
  end

  def compute_price
    @bulk_price = checked_items.sum { |cart_item| cart_item.bulk_price }
  end

  def compute_total
    compute_price
    self.promote_price = checked_items.sum { |cart_item| cart_item.promote_price }
    self.discount_price = checked_items.sum { |cart_item| cart_item.discount_price }
    self.retail_price = checked_items.sum { |cart_item| cart_item.retail_price }
    self.total_quantity = checked_items.sum { |cart_item| cart_item.total_quantity }
  end

  def compute_promote
    @promote_charges = []
    Promote.sequence.each do |quence|
      AmountPromote.total.overall.where(sequence: quence).each do |promote|
        charge = promote.compute_price(bulk_price)
        @promote_charges << charge if charge
      end

      if buyer
        buyer.promotes.total.where(sequence: quence).each do |promote|
          charge = promote.compute_price(bulk_price)
          @promote_charges << charge if charge
        end
      end

      compute_price
    end

    @promote_price = @promote_charges.map(&:subtotal).sum
  end

  def compute_serve
    @serve_charges = []

    QuantityServe.total.overall.each do |serve|
      charge = serve.compute_price(total_quantity, extra)
      @serve_charges << charge if charge.persisted?
    end

    @serve_price = checked_items.sum { |cart_item| cart_item.serve_price }
    @total_serve_price = serve_charges.sum { |i| i.subtotal }
  end

  def total_price
    @total_price ||= @bulk_price + @promote_price + @total_serve_price
  end

end

{'fraction_non_alphanumeric': 0.08585365853658537, 'fraction_numerical': 0.0, 'mean_word_length': 3.321390937829294, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 3, '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': '3513693', 'n_tokens_mistral': 1386, 'n_tokens_neox': 1346, 'n_words': 259}