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

Returns a new instance of Configuration.



210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/split/configuration.rb', line 210

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')
  @dashboard_pagination_default_per_page = 10
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.



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

def allow_multiple_experiments
  @allow_multiple_experiments
end

#beta_probability_simulationsObject

Returns the value of attribute beta_probability_simulations.



25
26
27
# File 'lib/split/configuration.rb', line 25

def beta_probability_simulations
  @beta_probability_simulations
end

#botsObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/split/configuration.rb', line 35

def bots
  @bots ||= {
    # Indexers
    'AdsBot-Google' => 'Google Adwords',
    'Baidu' => 'Chinese search engine',
    'Baiduspider' => 'Chinese search engine',
    'bingbot' => 'Microsoft bing bot',
    'Butterfly' => 'Topsy Labs',
    'Gigabot' => 'Gigabot spider',
    'Googlebot' => 'Google spider',
    'MJ12bot' => 'Majestic-12 spider',
    'msnbot' => 'Microsoft bot',
    'rogerbot' => 'SeoMoz spider',
    'PaperLiBot' => 'PaperLi is another content curation service',
    'Slurp' => 'Yahoo spider',
    'Sogou' => 'Chinese search engine',
    'spider' => 'generic web spider',
    'UnwindFetchor' => 'Gnip crawler',
    'WordPress' => 'WordPress spider',
    'YandexAccessibilityBot' => 'Yandex accessibility spider',
    'YandexBot' => 'Yandex spider',
    'YandexMobileBot' => 'Yandex mobile spider',
    'ZIBB' => 'ZIBB spider',

    # HTTP libraries
    'Apache-HttpClient' => 'Java http library',
    'AppEngine-Google' => 'Google App Engine',
    'curl' => 'curl unix CLI http client',
    'ColdFusion' => 'ColdFusion http library',
    'EventMachine HttpClient' => 'Ruby http library',
    'Go http package' => 'Go http library',
    'Go-http-client' => 'Go http library',
    'Java' => 'Generic Java http library',
    'libwww-perl' => 'Perl client-server library loved by script kids',
    'lwp-trivial' => 'Another Perl library loved by script kids',
    'Python-urllib' => 'Python http library',
    'PycURL' => 'Python http library',
    'Test Certificate Info' => 'C http library?',
    'Typhoeus' => 'Ruby http library',
    'Wget' => 'wget unix CLI http client',

    # URL expanders / previewers
    'awe.sm' => 'Awe.sm URL expander',
    'bitlybot' => 'bit.ly bot',
    '[email protected]' => 'Linkfluence bot',
    'facebookexternalhit' => 'facebook bot',
    'Facebot' => 'Facebook crawler',
    'Feedfetcher-Google' => 'Google Feedfetcher',
    'https://developers.google.com/+/web/snippet' => 'Google+ Snippet Fetcher',
    'LinkedInBot' => 'LinkedIn bot',
    'LongURL' => 'URL expander service',
    'NING' => 'NING - Yet Another Twitter Swarmer',
    'Pinterest' => 'Pinterest Bot',
    'redditbot' => 'Reddit Bot',
    'ShortLinkTranslate' => 'Link shortener',
    'Slackbot' => 'Slackbot link expander',
    'TweetmemeBot' => 'TweetMeMe Crawler',
    'Twitterbot' => 'Twitter URL expander',
    'UnwindFetch' => 'Gnip URL expander',
    'vkShare' => 'VKontake Sharer',

    # Uptime monitoring
    'check_http' => 'Nagios monitor',
    'GoogleStackdriverMonitoring' => 'Google Cloud monitor',
    'NewRelicPinger' => 'NewRelic monitor',
    'Panopta' => 'Monitoring service',
    'Pingdom' => 'Pingdom monitoring',
    'SiteUptime' => 'Site monitoring services',
    'UptimeRobot' => 'Monitoring service',

    # ???
    'DigitalPersona Fingerprint Software' => 'HP Fingerprint scanner',
    'ShowyouBot' => 'Showyou iOS app spider',
    'ZyBorg' => 'Zyborg? Hmmm....',
    'ELB-HealthChecker' => 'ELB Health Check'
  }
end

#dashboard_pagination_default_per_pageObject

Returns the value of attribute dashboard_pagination_default_per_page.



28
29
30
# File 'lib/split/configuration.rb', line 28

def dashboard_pagination_default_per_page
  @dashboard_pagination_default_per_page
end

#db_failoverObject

Returns the value of attribute db_failover.



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

def db_failover
  @db_failover
end

#db_failover_allow_parameter_overrideObject

Returns the value of attribute db_failover_allow_parameter_override.



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

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.



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

def db_failover_on_db_error
  @db_failover_on_db_error
end

#enabledObject

Returns the value of attribute enabled.



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

def enabled
  @enabled
end

#experimentsObject

Returns the value of attribute experiments.



30
31
32
# File 'lib/split/configuration.rb', line 30

def experiments
  @experiments
end

#ignore_filterObject

Returns the value of attribute ignore_filter.



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

def ignore_filter
  @ignore_filter
end

#ignore_ip_addressesObject

Returns the value of attribute ignore_ip_addresses.



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

def ignore_ip_addresses
  @ignore_ip_addresses
end

#include_rails_helperObject

Returns the value of attribute include_rails_helper.



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

def include_rails_helper
  @include_rails_helper
end

#on_before_experiment_deleteObject

Returns the value of attribute on_before_experiment_delete.



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

def on_before_experiment_delete
  @on_before_experiment_delete
end

#on_before_experiment_resetObject

Returns the value of attribute on_before_experiment_reset.



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

def on_before_experiment_reset
  @on_before_experiment_reset
end

#on_experiment_deleteObject

Returns the value of attribute on_experiment_delete.



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

def on_experiment_delete
  @on_experiment_delete
end

#on_experiment_resetObject

Returns the value of attribute on_experiment_reset.



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

def on_experiment_reset
  @on_experiment_reset
end

#on_trialObject

Returns the value of attribute on_trial.



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

def on_trial
  @on_trial
end

#on_trial_chooseObject

Returns the value of attribute on_trial_choose.



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

def on_trial_choose
  @on_trial_choose
end

#on_trial_completeObject

Returns the value of attribute on_trial_complete.



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

def on_trial_complete
  @on_trial_complete
end

#persistenceObject

Returns the value of attribute persistence.



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

def persistence
  @persistence
end

Returns the value of attribute persistence_cookie_length.



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

def persistence_cookie_length
  @persistence_cookie_length
end

#redisObject

Returns the value of attribute redis.



27
28
29
# File 'lib/split/configuration.rb', line 27

def redis
  @redis
end

#reset_manuallyObject

Returns the value of attribute reset_manually.



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

def reset_manually
  @reset_manually
end

#robot_regexObject



206
207
208
# File 'lib/split/configuration.rb', line 206

def robot_regex
  @robot_regex ||= /\b(?:#{escaped_bots.join('|')})\b|\A\W*\z/i
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

#winning_alternative_recalculation_intervalObject

Returns the value of attribute winning_alternative_recalculation_interval.



26
27
28
# File 'lib/split/configuration.rb', line 26

def winning_alternative_recalculation_interval
  @winning_alternative_recalculation_interval
end

Instance Method Details

#disabled?Boolean

Returns:

  • (Boolean)


118
119
120
# File 'lib/split/configuration.rb', line 118

def disabled?
  !enabled
end

#experiment_for(name) ⇒ Object



122
123
124
125
126
127
# File 'lib/split/configuration.rb', line 122

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

#metricsObject



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/split/configuration.rb', line 129

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



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/split/configuration.rb', line 175

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



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/split/configuration.rb', line 146

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_urlObject



238
239
240
241
# File 'lib/split/configuration.rb', line 238

def redis_url
  warn '[DEPRECATED] `redis_url` is deprecated in favor of `redis`'
  self.redis
end

#redis_url=(value) ⇒ Object



233
234
235
236
# File 'lib/split/configuration.rb', line 233

def redis_url=(value)
  warn '[DEPRECATED] `redis_url=` is deprecated in favor of `redis=`'
  self.redis = value
end