<commit_before>require "#{Rails.root}/lib/data_cycle/batch_update_logging"
require "#{Rails.root}/lib/surveys/survey_notifications_manager"

class SurveyUpdate
  include BatchUpdateLogging

  def initialize
    setup_logger
    log_start_of_update
    create_survey_notifications
    send_survey_notifications
    send_survey_notification_follow_ups
    log_end_of_update 'Survey update finished.'
  end

  private

  def create_survey_notifications
    log_message 'Creating new SurveyNotifications'
    before_count = SurveyNotification.count
    SurveyNotificationsManager.create_notifications
    after_count = SurveyNotification.count
    log_message "#{after_count - before_count} SurveyNotifications created"
  end

  def send_survey_notifications
    log_message 'Sending survey invitation emails'
    before_count = SurveyNotification.where(email_sent_at: nil).count
    SurveyNotification.active.each(&:send_email)
    after_count = SurveyNotification.where(email_sent_at: nil).count
    log_message "#{after_count - before_count} survey invitations sent"
  end

  def send_survey_notification_follow_ups
    log_message 'Sending survey reminder emails'
    before_count = SurveyNotification.sum(:follow_up_count)
    SurveyNotification.active.each(&:send_follow_up)
    after_count = SurveyNotification.sum(:follow_up_count)
    log_message "#{after_count - before_count} survey reminders sent"
  end
<commit_msg>Fix arithmetic in survey update logs<commit_after>require "#{Rails.root}/lib/data_cycle/batch_update_logging"
require "#{Rails.root}/lib/surveys/survey_notifications_manager"

class SurveyUpdate
  include BatchUpdateLogging

  def initialize
    setup_logger
    log_start_of_update
    create_survey_notifications
    send_survey_notifications
    send_survey_notification_follow_ups
    log_end_of_update 'Survey update finished.'
  end

  private

  def create_survey_notifications
    log_message 'Creating new SurveyNotifications'
    before_count = SurveyNotification.count
    SurveyNotificationsManager.create_notifications
    after_count = SurveyNotification.count
    log_message "#{after_count - before_count} SurveyNotifications created"
  end

  def send_survey_notifications
    log_message 'Sending survey invitation emails'
    before_count = SurveyNotification.where.not(email_sent_at: nil).count
    SurveyNotification.active.each(&:send_email)
    after_count = SurveyNotification.where.not(email_sent_at: nil).count
    log_message "#{after_count - before_count} survey invitations sent"
  end

  def send_survey_notification_follow_ups
    log_message 'Sending survey reminder emails'
    before_count = SurveyNotification.sum(:follow_up_count)
    SurveyNotification.active.each(&:send_follow_up)
    after_count = SurveyNotification.sum(:follow_up_count)
    log_message "#{after_count - before_count} survey reminders sent"
  end

{'fraction_non_alphanumeric': 0.0611323376172282, 'fraction_numerical': 0.0, 'mean_word_length': 5.371681415929204, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5193280', 'n_tokens_mistral': 838, 'n_tokens_neox': 829, 'n_words': 161}