Module: Bandit
- Defined in:
- lib/bandit/storage/base.rb,
lib/bandit.rb,
lib/bandit/config.rb,
lib/bandit/version.rb,
lib/bandit/date_hour.rb,
lib/bandit/exceptions.rb,
lib/bandit/experiment.rb,
lib/bandit/memoizable.rb,
lib/bandit/players/base.rb,
lib/bandit/storage/redis.rb,
lib/bandit/storage/memory.rb,
lib/bandit/storage/memcache.rb,
lib/bandit/players/round_robin.rb,
lib/bandit/players/epsilon_greedy.rb,
lib/bandit/extensions/view_concerns.rb,
lib/generators/bandit/install_generator.rb,
lib/bandit/extensions/controller_concerns.rb,
lib/generators/bandit/dashboard_generator.rb
Overview
every so often store current epsilon state:<experiment>:<player>:epsilon = 0.1
Defined Under Namespace
Modules: ControllerConcerns, Generators, Memoizable, ViewConcerns
Classes: BasePlayer, BaseStorage, Config, DateHour, EpsilonGreedyPlayer, Experiment, MemCacheStorage, MemoryStorage, MissingConfigurationError, RedisStorage, RoundRobinPlayer, UnknownPlayerEngineError, UnknownStorageEngineError
Constant Summary
collapse
- VERSION =
"0.0.8"
- @@storage_failure_at =
nil
Class Method Summary
collapse
Class Method Details
.config ⇒ Object
26
27
28
|
# File 'lib/bandit.rb', line 26
def self.config
@config ||= Config.new
end
|
.get_experiment(name) ⇒ Object
55
56
57
58
|
# File 'lib/bandit.rb', line 55
def self.get_experiment(name)
exp = Experiment.instances.select { |e| e.name == name }
exp.length > 0 ? exp.first : nil
end
|
.setup {|config| ... } ⇒ Object
30
31
32
33
34
35
|
# File 'lib/bandit.rb', line 30
def self.setup(&block)
yield config
config.check!
config.storage_config = config.storage_config.inject({}) { |n,o| n[o.first.intern] = o.last; n }
end
|
.storage ⇒ Object
37
38
39
40
41
42
43
44
45
|
# File 'lib/bandit.rb', line 37
def self.storage
if @@storage_failure_at.nil? or (Time.now.to_i - @@storage_failure_at) > 300
@storage ||= BaseStorage.get_storage(Bandit.config.storage.intern, Bandit.config.storage_config)
else
Rails.logger.warn "storage failure detected #{Time.now.to_i - @@storage_failure_at} seconds ago - using memory storage for 5 minutes"
BaseStorage.get_storage(:memory, Bandit.config.storage_config)
end
end
|
.storage_failed! ⇒ Object
51
52
53
|
# File 'lib/bandit.rb', line 51
def self.storage_failed!
@@storage_failure_at = Time.now.to_i
end
|