<commit_before>require_relative "variant_data_store"

# See superclass for documentation
class Tests::EpsilonGreedy < Tests::Base

  # The percentage of samples that should be assigned a random variation
  RANDOM_RATE = Rational(ENV["RANDOM"] || 10, 100).to_f

  def initialize(*args)
    super
    @name = 'Epsilon Greedy'
  end


  private


  def prepare_records
    sample_size.times do
      user = User.new(variant: determine_variant_for_user).tap { |u| u.perform_test }
      store_result(user.variant, user.conversion?)
    end
  end

  def determine_variant_for_user
    if rand < RANDOM_RATE or variant_data.empty?
      random_variant
    else
      most_lucrative_variant
    end
  end


  # A random variant name<commit_msg>All bandit arms have been touched once.<commit_after>require_relative "variant_data_store"

# See superclass for documentation
class Tests::EpsilonGreedy < Tests::Base

  # The percentage of samples that should be assigned a random variation
  RANDOM_RATE = Rational(ENV["RANDOM"] || 10, 100).to_f

  def initialize(*args)
    super
    @name = 'Epsilon Greedy'
    # Explicitly initialize
    variants.each do |name|
      variant_data[name].increment_count
    end
  end


  private


  def prepare_records
    sample_size.times do
      user = User.new(variant: determine_variant_for_user).tap { |u| u.perform_test }
      store_result(user.variant, user.conversion?)
    end
  end

  def determine_variant_for_user
    if rand < RANDOM_RATE
      random_variant
    else
      most_lucrative_variant
    end
  end


  # A random variant name
{'fraction_non_alphanumeric': 0.0695322376738306, 'fraction_numerical': 0.006321112515802781, 'mean_word_length': 3.4591549295774646, 'pattern_counts': {'":': 0, '<': 7, '<?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': '7528592', 'n_tokens_mistral': 517, 'n_tokens_neox': 478, 'n_words': 132}