<commit_before>class GeneratePayoutReportJob < ApplicationJob
  queue_as :low

  def perform(should_send_notifications: true, final: true)
    Rails.logger.info("Generating payout report..")

    payout_report = PayoutReport.create(final: final, fee_rate: fee_rate)
    publishers = Publisher.with_verified_channel.not_suspended

    payouts = []
    total_amount_probi = 0
    total_fee_probi = 0
    num_payments = 0
    i = 0

    publishers.find_each do |publisher|
      Rails.logger.info("Completed #{i} of #{publishers.count} publishers for payout report.") if i % 500 == 0
      i += 1 
      publisher_has_unsettled_balance = false
      wallet = publisher.wallet

      probi = wallet.channel_balances[publisher.owner_identifier].probi_before_fees # probi = balance
      if probi > 0
        publisher_has_unsettled_balance = true

        if publisher.uphold_verified? && !wallet.address.blank?
          num_payments += 1
          total_amount_probi += probi

          payouts.push({
            "name" => "#{publisher.name}",
            "altcurrency" => "BAT",
            "probi" => "#{probi}",
            "fees" => "0",
            "authority" => "GeneratePayoutReportJob",
            "transactionId" => "#{payout_report.id}",
            "owner" => "#{publisher.owner_identifier}",
            "type" => "referral",
            "address" => "#{wallet.address}",<commit_msg>check for nil wallet<commit_after>class GeneratePayoutReportJob < ApplicationJob
  queue_as :low

  def perform(should_send_notifications: true, final: true)
    Rails.logger.info("Generating payout report..")

    payout_report = PayoutReport.create(final: final, fee_rate: fee_rate)
    publishers = Publisher.with_verified_channel.not_suspended

    payouts = []
    total_amount_probi = 0
    total_fee_probi = 0
    num_payments = 0
    i = 0

    publishers.find_each do |publisher|
      Rails.logger.info("Completed #{i} of #{publishers.count} publishers for payout report.") if i % 500 == 0
      i += 1 
      publisher_has_unsettled_balance = false
      wallet = publisher.wallet
      next if wallet.nil?

      probi = wallet.channel_balances[publisher.owner_identifier].probi_before_fees # probi = balance
      if probi > 0
        publisher_has_unsettled_balance = true

        if publisher.uphold_verified? && !wallet.address.blank?
          num_payments += 1
          total_amount_probi += probi

          payouts.push({
            "name" => "#{publisher.name}",
            "altcurrency" => "BAT",
            "probi" => "#{probi}",
            "fees" => "0",
            "authority" => "GeneratePayoutReportJob",
            "transactionId" => "#{payout_report.id}",
            "owner" => "#{publisher.owner_identifier}",
            "type" => "referral",
            "address" => "#{wallet.address}",
{'fraction_non_alphanumeric': 0.11902231668437832, 'fraction_numerical': 0.008501594048884165, 'mean_word_length': 2.6770833333333335, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, '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': '915932', 'n_tokens_mistral': 896, 'n_tokens_neox': 867, 'n_words': 175}