<commit_before>namespace :weekly_digester do

  desc "Sends out all weekly digests"
  task :mail_all_users => :environment do
    initialize_performance_assessments("Processing weekly digests for all users.")

    User.all.each do |u|
      digest = WeeklyEmailDigester.new(u, 1.day.ago)

      if digest.purchases.blank?
        puts "No weekly digest send for User ##{u.id} (No purchases found for previous week)."
      else
        UserMailer.weekly_digest(u, digest).deliver
        @counter += 1
      end
    end

    output_performance_report
  end

private 

  def initialize_performance_assessments(message)
    @counter = 0
    @start_time = Time.now
    puts "#{message} (#{@start_time})"
  end

  def output_performance_report
    puts "Task complete. #{@counter} mailer jobs sent in #{Time.now - @start_time} seconds."
  end

end<commit_msg>Allow for end_date to be specified in WeeklyDigester task<commit_after>namespace :weekly_digester do

  desc "Sends out all weekly digests"
  task :mail_all_users, [:end_date_days_ago] => :environment do |t, args|
    unless args[:end_date_days_ago].blank? || !!(args[:end_date_days_ago] =~ /\A[-+]?[0-9]+\z/)
      raise ">>> End date must be an integer! (# of days since end of period)"
    end

    end_date_of_period = args[:end_date_days_ago].blank? ? 1 : args[:end_date_days_ago].to_i

    initialize_performance_assessments("Processing weekly digests for all users.")

    User.all.each do |u|
      digest = WeeklyEmailDigester.new(u, end_date_of_period.day.ago)

      if digest.purchases.blank?
        puts "No weekly digest send for User ##{u.id}. (No purchases found for time period.)"
      else
        UserMailer.weekly_digest(u, digest).deliver
        @counter += 1
      end
    end

    output_performance_report
  end

private 

  def initialize_performance_assessments(message)
    @counter = 0
    @start_time = Time.now
    puts "#{message} (#{@start_time})"
  end

  def output_performance_report
    puts "Task complete. #{@counter} mailer jobs sent in #{Time.now - @start_time} seconds."
  end

end
{'fraction_non_alphanumeric': 0.10384615384615385, 'fraction_numerical': 0.0038461538461538464, 'mean_word_length': 3.3995771670190273, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '2337856', 'n_tokens_mistral': 695, 'n_tokens_neox': 662, 'n_words': 184}