<commit_before>module HalfAndHalf
  
  class Event
    attr_accessor :name, :variant

    def initialize(args={})
      @name = args[:name]
      @variant = args[:variant]
    end

    def experiment
      variant.experiment
    end

    def count
      key = [experiment.name, variant.name, name].join(".")
      Redis.current.bitcount(key)
    end

    def conversion_rate
      count.to_f / variant.sample_size
    end

    def significant?
      count >= count_needed
    end

    def count_needed
      if effect == 0
        Float::INFINITY
      else
        (16 * variance / (effect ** 2)).to_i
      end
    end

    private

    def variance<commit_msg>fix bug, use sample size to determine significance<commit_after>module HalfAndHalf
  
  class Event
    attr_accessor :name, :variant

    def initialize(args={})
      @name = args[:name]
      @variant = args[:variant]
    end

    def experiment
      variant.experiment
    end

    def count
      key = [experiment.name, variant.name, name].join(".")
      Redis.current.bitcount(key)
    end

    def conversion_rate
      count.to_f / variant.sample_size
    end

    def significant?
      variant.sample_size >= count_needed
    end

    def count_needed
      if effect == 0
        Float::INFINITY
      else
        (16 * variance / (effect ** 2)).to_i
      end
    end

    private

    def variance
{'fraction_non_alphanumeric': 0.08569353667392883, 'fraction_numerical': 0.005809731299927378, 'mean_word_length': 2.0554323725055434, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2070168', 'n_tokens_mistral': 433, 'n_tokens_neox': 404, 'n_words': 110}