Class: Split::Configuration
- Inherits:
-
Object
- Object
- Split::Configuration
- Defined in:
- lib/split/configuration.rb
Instance Attribute Summary collapse
-
#algorithm ⇒ Object
Returns the value of attribute algorithm.
-
#allow_multiple_experiments ⇒ Object
Returns the value of attribute allow_multiple_experiments.
-
#beta_probability_simulations ⇒ Object
Returns the value of attribute beta_probability_simulations.
-
#bots ⇒ Object
Returns the value of attribute bots.
-
#db_failover ⇒ Object
Returns the value of attribute db_failover.
-
#db_failover_allow_parameter_override ⇒ Object
Returns the value of attribute db_failover_allow_parameter_override.
-
#db_failover_on_db_error ⇒ Object
Returns the value of attribute db_failover_on_db_error.
-
#enabled ⇒ Object
Returns the value of attribute enabled.
-
#experiments ⇒ Object
Returns the value of attribute experiments.
-
#ignore_filter ⇒ Object
Returns the value of attribute ignore_filter.
-
#ignore_ip_addresses ⇒ Object
Returns the value of attribute ignore_ip_addresses.
-
#include_rails_helper ⇒ Object
Returns the value of attribute include_rails_helper.
-
#on_before_experiment_delete ⇒ Object
Returns the value of attribute on_before_experiment_delete.
-
#on_before_experiment_reset ⇒ Object
Returns the value of attribute on_before_experiment_reset.
-
#on_experiment_delete ⇒ Object
Returns the value of attribute on_experiment_delete.
-
#on_experiment_reset ⇒ Object
Returns the value of attribute on_experiment_reset.
-
#on_trial ⇒ Object
Returns the value of attribute on_trial.
-
#on_trial_choose ⇒ Object
Returns the value of attribute on_trial_choose.
-
#on_trial_complete ⇒ Object
Returns the value of attribute on_trial_complete.
-
#persistence ⇒ Object
Returns the value of attribute persistence.
-
#persistence_cookie_length ⇒ Object
Returns the value of attribute persistence_cookie_length.
-
#redis ⇒ Object
Returns the value of attribute redis.
-
#reset_manually ⇒ Object
Returns the value of attribute reset_manually.
-
#robot_regex ⇒ Object
Returns the value of attribute robot_regex.
-
#start_manually ⇒ Object
Returns the value of attribute start_manually.
-
#store_override ⇒ Object
Returns the value of attribute store_override.
-
#winning_alternative_recalculation_interval ⇒ Object
Returns the value of attribute winning_alternative_recalculation_interval.
Instance Method Summary collapse
- #disabled? ⇒ Boolean
- #experiment_for(name) ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #metrics ⇒ Object
- #normalize_alternatives(alternatives) ⇒ Object
- #normalized_experiments ⇒ Object
- #redis_url ⇒ Object
- #redis_url=(value) ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/split/configuration.rb', line 203 def initialize @ignore_ip_addresses = [] @ignore_filter = proc{ |request| is_robot? || is_ignored_ip_address? } @db_failover = false @db_failover_on_db_error = proc{|error|} # e.g. use Rails logger here @on_experiment_reset = proc{|experiment|} @on_experiment_delete = proc{|experiment|} @on_before_experiment_reset = proc{|experiment|} @on_before_experiment_delete = proc{|experiment|} @db_failover_allow_parameter_override = false @allow_multiple_experiments = false @enabled = true @experiments = {} @persistence = Split::Persistence::SessionAdapter @persistence_cookie_length = 31536000 # One year from now @algorithm = Split::Algorithms::WeightedSample @include_rails_helper = true @beta_probability_simulations = 10000 @winning_alternative_recalculation_interval = 60 * 60 * 24 # 1 day @redis = ENV.fetch(ENV.fetch('REDIS_PROVIDER', 'REDIS_URL'), 'redis://localhost:6379') end |
Instance Attribute Details
#algorithm ⇒ Object
Returns the value of attribute algorithm.
15 16 17 |
# File 'lib/split/configuration.rb', line 15 def algorithm @algorithm end |
#allow_multiple_experiments ⇒ Object
Returns the value of attribute allow_multiple_experiments.
11 12 13 |
# File 'lib/split/configuration.rb', line 11 def allow_multiple_experiments @allow_multiple_experiments end |
#beta_probability_simulations ⇒ Object
Returns the value of attribute beta_probability_simulations.
27 28 29 |
# File 'lib/split/configuration.rb', line 27 def beta_probability_simulations @beta_probability_simulations end |
#bots ⇒ Object
Returns the value of attribute bots.
4 5 6 |
# File 'lib/split/configuration.rb', line 4 def bots @bots end |
#db_failover ⇒ Object
Returns the value of attribute db_failover.
8 9 10 |
# File 'lib/split/configuration.rb', line 8 def db_failover @db_failover end |
#db_failover_allow_parameter_override ⇒ Object
Returns the value of attribute db_failover_allow_parameter_override.
10 11 12 |
# File 'lib/split/configuration.rb', line 10 def db_failover_allow_parameter_override @db_failover_allow_parameter_override end |
#db_failover_on_db_error ⇒ Object
Returns the value of attribute db_failover_on_db_error.
9 10 11 |
# File 'lib/split/configuration.rb', line 9 def db_failover_on_db_error @db_failover_on_db_error end |
#enabled ⇒ Object
Returns the value of attribute enabled.
12 13 14 |
# File 'lib/split/configuration.rb', line 12 def enabled @enabled end |
#experiments ⇒ Object
Returns the value of attribute experiments.
31 32 33 |
# File 'lib/split/configuration.rb', line 31 def experiments @experiments end |
#ignore_filter ⇒ Object
Returns the value of attribute ignore_filter.
7 8 9 |
# File 'lib/split/configuration.rb', line 7 def ignore_filter @ignore_filter end |
#ignore_ip_addresses ⇒ Object
Returns the value of attribute ignore_ip_addresses.
6 7 8 |
# File 'lib/split/configuration.rb', line 6 def ignore_ip_addresses @ignore_ip_addresses end |
#include_rails_helper ⇒ Object
Returns the value of attribute include_rails_helper.
26 27 28 |
# File 'lib/split/configuration.rb', line 26 def include_rails_helper @include_rails_helper end |
#on_before_experiment_delete ⇒ Object
Returns the value of attribute on_before_experiment_delete.
25 26 27 |
# File 'lib/split/configuration.rb', line 25 def on_before_experiment_delete @on_before_experiment_delete end |
#on_before_experiment_reset ⇒ Object
Returns the value of attribute on_before_experiment_reset.
24 25 26 |
# File 'lib/split/configuration.rb', line 24 def on_before_experiment_reset @on_before_experiment_reset end |
#on_experiment_delete ⇒ Object
Returns the value of attribute on_experiment_delete.
23 24 25 |
# File 'lib/split/configuration.rb', line 23 def on_experiment_delete @on_experiment_delete end |
#on_experiment_reset ⇒ Object
Returns the value of attribute on_experiment_reset.
22 23 24 |
# File 'lib/split/configuration.rb', line 22 def on_experiment_reset @on_experiment_reset end |
#on_trial ⇒ Object
Returns the value of attribute on_trial.
19 20 21 |
# File 'lib/split/configuration.rb', line 19 def on_trial @on_trial end |
#on_trial_choose ⇒ Object
Returns the value of attribute on_trial_choose.
20 21 22 |
# File 'lib/split/configuration.rb', line 20 def on_trial_choose @on_trial_choose end |
#on_trial_complete ⇒ Object
Returns the value of attribute on_trial_complete.
21 22 23 |
# File 'lib/split/configuration.rb', line 21 def on_trial_complete @on_trial_complete end |
#persistence ⇒ Object
Returns the value of attribute persistence.
13 14 15 |
# File 'lib/split/configuration.rb', line 13 def persistence @persistence end |
#persistence_cookie_length ⇒ Object
Returns the value of attribute persistence_cookie_length.
14 15 16 |
# File 'lib/split/configuration.rb', line 14 def @persistence_cookie_length end |
#redis ⇒ Object
Returns the value of attribute redis.
29 30 31 |
# File 'lib/split/configuration.rb', line 29 def redis @redis end |
#reset_manually ⇒ Object
Returns the value of attribute reset_manually.
18 19 20 |
# File 'lib/split/configuration.rb', line 18 def reset_manually @reset_manually end |
#robot_regex ⇒ Object
Returns the value of attribute robot_regex.
5 6 7 |
# File 'lib/split/configuration.rb', line 5 def robot_regex @robot_regex end |
#start_manually ⇒ Object
Returns the value of attribute start_manually.
17 18 19 |
# File 'lib/split/configuration.rb', line 17 def start_manually @start_manually end |
#store_override ⇒ Object
Returns the value of attribute store_override.
16 17 18 |
# File 'lib/split/configuration.rb', line 16 def store_override @store_override end |
#winning_alternative_recalculation_interval ⇒ Object
Returns the value of attribute winning_alternative_recalculation_interval.
28 29 30 |
# File 'lib/split/configuration.rb', line 28 def winning_alternative_recalculation_interval @winning_alternative_recalculation_interval end |
Instance Method Details
#disabled? ⇒ Boolean
111 112 113 |
# File 'lib/split/configuration.rb', line 111 def disabled? !enabled end |
#experiment_for(name) ⇒ Object
115 116 117 118 119 120 |
# File 'lib/split/configuration.rb', line 115 def experiment_for(name) if normalized_experiments # TODO symbols normalized_experiments[name.to_sym] end end |
#metrics ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/split/configuration.rb', line 122 def metrics return @metrics if defined?(@metrics) @metrics = {} if self.experiments self.experiments.each do |key, value| metrics = value_for(value, :metric) rescue nil Array(metrics).each do |metric_name| if metric_name @metrics[metric_name.to_sym] ||= [] @metrics[metric_name.to_sym] << Split::Experiment.new(key) end end end end @metrics end |
#normalize_alternatives(alternatives) ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/split/configuration.rb', line 168 def normalize_alternatives(alternatives) given_probability, num_with_probability = alternatives.inject([0,0]) do |a,v| p, n = a if percent = value_for(v, :percent) [p + percent, n + 1] else a end end num_without_probability = alternatives.length - num_with_probability unassigned_probability = ((100.0 - given_probability) / num_without_probability / 100.0) if num_with_probability.nonzero? alternatives = alternatives.map do |v| if (name = value_for(v, :name)) && (percent = value_for(v, :percent)) { name => percent / 100.0 } elsif name = value_for(v, :name) { name => unassigned_probability } else { v => unassigned_probability } end end [alternatives.shift, alternatives] else alternatives = alternatives.dup [alternatives.shift, alternatives] end end |
#normalized_experiments ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/split/configuration.rb', line 139 def normalized_experiments return nil if @experiments.nil? experiment_config = {} @experiments.keys.each do |name| experiment_config[name.to_sym] = {} end @experiments.each do |experiment_name, settings| alternatives = if (alts = value_for(settings, :alternatives)) normalize_alternatives(alts) end experiment_data = { alternatives: alternatives, goals: value_for(settings, :goals), metadata: value_for(settings, :metadata), algorithm: value_for(settings, :algorithm), resettable: value_for(settings, :resettable) } experiment_data.each do |name, value| experiment_config[experiment_name.to_sym][name] = value if value != nil end end experiment_config end |
#redis_url ⇒ Object
230 231 232 233 |
# File 'lib/split/configuration.rb', line 230 def redis_url warn '[DEPRECATED] `redis_url` is deprecated in favor of `redis`' self.redis end |
#redis_url=(value) ⇒ Object
225 226 227 228 |
# File 'lib/split/configuration.rb', line 225 def redis_url=(value) warn '[DEPRECATED] `redis_url=` is deprecated in favor of `redis=`' self.redis = value end |