Class: Split::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/split/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/split/configuration.rb', line 192

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|}
  @db_failover_allow_parameter_override = false
  @allow_multiple_experiments = false
  @enabled = true
  @experiments = {}
  @persistence = Split::Persistence::SessionAdapter
  @algorithm = Split::Algorithms::WeightedSample
  @include_rails_helper = true
  @beta_probability_simulations = 10000
end

Instance Attribute Details

#algorithmObject

Returns the value of attribute algorithm



13
14
15
# File 'lib/split/configuration.rb', line 13

def algorithm
  @algorithm
end

#allow_multiple_experimentsObject

Returns the value of attribute allow_multiple_experiments



10
11
12
# File 'lib/split/configuration.rb', line 10

def allow_multiple_experiments
  @allow_multiple_experiments
end

#beta_probability_simulationsObject

Returns the value of attribute beta_probability_simulations



21
22
23
# File 'lib/split/configuration.rb', line 21

def beta_probability_simulations
  @beta_probability_simulations
end

#botsObject

Returns the value of attribute bots



3
4
5
# File 'lib/split/configuration.rb', line 3

def bots
  @bots
end

#db_failoverObject

Returns the value of attribute db_failover



7
8
9
# File 'lib/split/configuration.rb', line 7

def db_failover
  @db_failover
end

#db_failover_allow_parameter_overrideObject

Returns the value of attribute db_failover_allow_parameter_override



9
10
11
# File 'lib/split/configuration.rb', line 9

def db_failover_allow_parameter_override
  @db_failover_allow_parameter_override
end

#db_failover_on_db_errorObject

Returns the value of attribute db_failover_on_db_error



8
9
10
# File 'lib/split/configuration.rb', line 8

def db_failover_on_db_error
  @db_failover_on_db_error
end

#enabledObject

Returns the value of attribute enabled



11
12
13
# File 'lib/split/configuration.rb', line 11

def enabled
  @enabled
end

#experimentsObject

Returns the value of attribute experiments



23
24
25
# File 'lib/split/configuration.rb', line 23

def experiments
  @experiments
end

#ignore_filterObject

Returns the value of attribute ignore_filter



6
7
8
# File 'lib/split/configuration.rb', line 6

def ignore_filter
  @ignore_filter
end

#ignore_ip_addressesObject

Returns the value of attribute ignore_ip_addresses



5
6
7
# File 'lib/split/configuration.rb', line 5

def ignore_ip_addresses
  @ignore_ip_addresses
end

#include_rails_helperObject

Returns the value of attribute include_rails_helper



20
21
22
# File 'lib/split/configuration.rb', line 20

def include_rails_helper
  @include_rails_helper
end

#on_experiment_deleteObject

Returns the value of attribute on_experiment_delete



19
20
21
# File 'lib/split/configuration.rb', line 19

def on_experiment_delete
  @on_experiment_delete
end

#on_experiment_resetObject

Returns the value of attribute on_experiment_reset



18
19
20
# File 'lib/split/configuration.rb', line 18

def on_experiment_reset
  @on_experiment_reset
end

#on_trial_chooseObject

Returns the value of attribute on_trial_choose



16
17
18
# File 'lib/split/configuration.rb', line 16

def on_trial_choose
  @on_trial_choose
end

#on_trial_completeObject

Returns the value of attribute on_trial_complete



17
18
19
# File 'lib/split/configuration.rb', line 17

def on_trial_complete
  @on_trial_complete
end

#persistenceObject

Returns the value of attribute persistence



12
13
14
# File 'lib/split/configuration.rb', line 12

def persistence
  @persistence
end

#robot_regexObject

Returns the value of attribute robot_regex



4
5
6
# File 'lib/split/configuration.rb', line 4

def robot_regex
  @robot_regex
end

#start_manuallyObject

Returns the value of attribute start_manually



15
16
17
# File 'lib/split/configuration.rb', line 15

def start_manually
  @start_manually
end

#store_overrideObject

Returns the value of attribute store_override



14
15
16
# File 'lib/split/configuration.rb', line 14

def store_override
  @store_override
end

Instance Method Details

#disabled?Boolean



98
99
100
# File 'lib/split/configuration.rb', line 98

def disabled?
  !enabled
end

#experiment_for(name) ⇒ Object



102
103
104
105
106
107
# File 'lib/split/configuration.rb', line 102

def experiment_for(name)
  if normalized_experiments
    # TODO symbols
    normalized_experiments[name.to_sym]
  end
end

#metricsObject



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/split/configuration.rb', line 109

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



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/split/configuration.rb', line 157

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_experimentsObject



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/split/configuration.rb', line 126

def normalized_experiments
  if @experiments.nil?
    nil
  else
    experiment_config = {}
    @experiments.keys.each do |name|
      experiment_config[name.to_sym] = {}
    end

    @experiments.each do |experiment_name, settings|
      if alternatives = value_for(settings, :alternatives)
        experiment_config[experiment_name.to_sym][:alternatives] = normalize_alternatives(alternatives)
      end

      if goals = value_for(settings, :goals)
        experiment_config[experiment_name.to_sym][:goals] = goals
      end

      if  = value_for(settings, :metadata)
        experiment_config[experiment_name.to_sym][:metadata] = 
      end

      if (resettable = value_for(settings, :resettable)) != nil
        experiment_config[experiment_name.to_sym][:resettable] = resettable
      end
    end

    experiment_config
  end
end