Sha256: ed21d880e2d79590dc1304e3cc732315593bb3f91e0079b5b5479b6c4ee3eeaa

Contents?: true

Size: 672 Bytes

Versions: 5

Compression:

Stored size: 672 Bytes

Contents

# frozen_string_literal: true
# Selects alternative with minimum count of participants
# If all counts are even (i.e. all are minimum), samples from all possible alternatives

module Split
  module Algorithms
    module BlockRandomization
      class << self
        def choose_alternative(experiment)
          minimum_participant_alternatives(experiment.alternatives).sample
        end

        private

        def minimum_participant_alternatives(alternatives)
          alternatives_by_count = alternatives.group_by(&:participant_count)
          min_group = alternatives_by_count.min_by { |k, v| k }
          min_group.last
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
ab-split-1.0.2 lib/split/algorithms/block_randomization.rb
ab-split-1.0.1 lib/split/algorithms/block_randomization.rb
ab-split-1.0.0 lib/split/algorithms/block_randomization.rb
split-3.4.1 lib/split/algorithms/block_randomization.rb
split-3.4.0 lib/split/algorithms/block_randomization.rb