<commit_before>class DatabaseSanitizer
  attr_reader :email_blacklist

  def initialize(email_blacklist)
    @email_blacklist = Set.new(email_blacklist)
  end

  def sanitize_user(user)
    return if email_blacklist.include?(user.email)

    first_name = Faker::Name.first_name

    user.update!(
      first_name: first_name,
      last_name: Faker::Name.last_name,
      email: Faker::Internet.safe_email("#{first_name}#{user.id}"),
      password: 'password',
      legacy_password_md5: nil
    )
  end

  def sanitize_user_con_profile(user_con_profile)
    user = user_con_profile.user
    return if email_blacklist.include?(user.email)

    sanitized_fields = {
      first_name: user.first_name,
      last_name: user.last_name,
      nickname: Faker::Lorem.word.titleize,
      birth_date: Faker::Time.between(Date.today - 70.years, Date.today - 16.years),
      address1: Faker::Address.street_address,
      address2: Faker::Address.secondary_address,
      city: Faker::Address.city,
      state: Faker::Address.state_abbr,
      zipcode: Faker::Address.postcode,
      country: Faker::Address.country,
      day_phone: Faker::PhoneNumber.phone_number,
      evening_phone: Faker::PhoneNumber.phone_number,
      best_call_time: Faker::Lorem.words
    }

    sanitized_present_fields = sanitized_fields.select { |key, value| user_con_profile.public_send(key).present? }

    user_con_profile.update!(sanitized_present_fields)
  end
end

task :sanitize_db => :environment do
  require 'faker'

  email_blacklist = ['<EMAIL>']
  sanitizer = DatabaseSanitizer.new(email_blacklist)

  ActiveRecord::Base.transaction do
    User.find_each do |user|
      puts "Sanitizing user #{user.id}"

      sanitizer.sanitize_user(user)
    end

    UserConProfile.includes(:user).find_each do |user_con_profile|
      puts "Sanitizing user con profile #{user_con_profile.id}"

      sanitizer.sanitize_user_con_profile(user_con_profile)
    end
  end
end<commit_msg>Populate best_call_time with string, not array<commit_after>class DatabaseSanitizer
  attr_reader :email_blacklist

  def initialize(email_blacklist)
    @email_blacklist = Set.new(email_blacklist)
  end

  def sanitize_user(user)
    return if email_blacklist.include?(user.email)

    first_name = Faker::Name.first_name

    user.update!(
      first_name: first_name,
      last_name: Faker::Name.last_name,
      email: Faker::Internet.safe_email("#{first_name}#{user.id}"),
      password: 'password',
      legacy_password_md5: nil
    )
  end

  def sanitize_user_con_profile(user_con_profile)
    user = user_con_profile.user
    return if email_blacklist.include?(user.email)

    sanitized_fields = {
      first_name: user.first_name,
      last_name: user.last_name,
      nickname: Faker::Lorem.word.titleize,
      birth_date: Faker::Time.between(Date.today - 70.years, Date.today - 16.years),
      address1: Faker::Address.street_address,
      address2: Faker::Address.secondary_address,
      city: Faker::Address.city,
      state: Faker::Address.state_abbr,
      zipcode: Faker::Address.postcode,
      country: Faker::Address.country,
      day_phone: Faker::PhoneNumber.phone_number,
      evening_phone: Faker::PhoneNumber.phone_number,
      best_call_time: Faker::Lorem.sentence
    }

    sanitized_present_fields = sanitized_fields.select { |key, value| user_con_profile.public_send(key).present? }

    user_con_profile.update!(sanitized_present_fields)
  end
end

task :sanitize_db => :environment do
  require 'faker'

  email_blacklist = ['<EMAIL>']
  sanitizer = DatabaseSanitizer.new(email_blacklist)

  ActiveRecord::Base.transaction do
    User.find_each do |user|
      puts "Sanitizing user #{user.id}"

      sanitizer.sanitize_user(user)
    end

    UserConProfile.includes(:user).find_each do |user_con_profile|
      puts "Sanitizing user con profile #{user_con_profile.id}"

      sanitizer.sanitize_user_con_profile(user_con_profile)
    end
  end
end
{'fraction_non_alphanumeric': 0.10131379484588175, 'fraction_numerical': 0.0035371399696816574, 'mean_word_length': 3.9736180904522613, 'pattern_counts': {'":': 0, '<': 5, '<?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': '486769', 'n_tokens_mistral': 1355, 'n_tokens_neox': 1325, 'n_words': 218}