Class: Bandit::Experiment
- Inherits:
-
Object
- Object
- Bandit::Experiment
- Defined in:
- lib/bandit/experiment.rb
Constant Summary collapse
- @@instances =
[]
Instance Attribute Summary collapse
-
#alternatives ⇒ Object
Returns the value of attribute alternatives.
-
#description ⇒ Object
Returns the value of attribute description.
-
#name ⇒ Object
Returns the value of attribute name.
-
#title ⇒ Object
Returns the value of attribute title.
Class Method Summary collapse
Instance Method Summary collapse
- #alternative_start(alt) ⇒ Object
- #choose(default = nil) ⇒ Object
- #conversion_count(alt, date_hour = nil) ⇒ Object
- #conversion_rate(alt) ⇒ Object
- #convert!(alt, count = 1) ⇒ Object
-
#initialize(args = nil) ⇒ Experiment
constructor
A new instance of Experiment.
- #participant_count(alt, date_hour = nil) ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(args = nil) ⇒ Experiment
Returns a new instance of Experiment.
13 14 15 16 17 |
# File 'lib/bandit/experiment.rb', line 13 def initialize(args=nil) args.each { |k,v| send "#{k}=", v } unless args.nil? @@instances << self @storage = Bandit.storage end |
Instance Attribute Details
#alternatives ⇒ Object
Returns the value of attribute alternatives.
3 4 5 |
# File 'lib/bandit/experiment.rb', line 3 def alternatives @alternatives end |
#description ⇒ Object
Returns the value of attribute description.
3 4 5 |
# File 'lib/bandit/experiment.rb', line 3 def description @description end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/bandit/experiment.rb', line 3 def name @name end |
#title ⇒ Object
Returns the value of attribute title.
3 4 5 |
# File 'lib/bandit/experiment.rb', line 3 def title @title end |
Class Method Details
.create(name) {|e| ... } ⇒ Object
6 7 8 9 10 11 |
# File 'lib/bandit/experiment.rb', line 6 def self.create(name) e = Experiment.new(:name => name) yield e e.validate! e end |
.instances ⇒ Object
19 20 21 |
# File 'lib/bandit/experiment.rb', line 19 def self.instances @@instances end |
Instance Method Details
#alternative_start(alt) ⇒ Object
59 60 61 |
# File 'lib/bandit/experiment.rb', line 59 def alternative_start(alt) @storage.alternative_start_time(self, alt) end |
#choose(default = nil) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/bandit/experiment.rb', line 23 def choose(default=nil) if default && alternatives.include?(default) alt = default else alt = Bandit.player.choose_alternative(self) @storage.incr_participants(self, alt) end alt end |
#conversion_count(alt, date_hour = nil) ⇒ Object
45 46 47 |
# File 'lib/bandit/experiment.rb', line 45 def conversion_count(alt, date_hour=nil) @storage.conversion_count(self, alt, date_hour) end |
#conversion_rate(alt) ⇒ Object
53 54 55 56 57 |
# File 'lib/bandit/experiment.rb', line 53 def conversion_rate(alt) pcount = participant_count(alt) ccount = conversion_count(alt) (pcount == 0 or ccount == 0) ? 0 : (ccount.to_f / pcount.to_f * 100.0) end |
#convert!(alt, count = 1) ⇒ Object
33 34 35 |
# File 'lib/bandit/experiment.rb', line 33 def convert!(alt, count=1) @storage.incr_conversions(self, alt, count) end |
#participant_count(alt, date_hour = nil) ⇒ Object
49 50 51 |
# File 'lib/bandit/experiment.rb', line 49 def participant_count(alt, date_hour=nil) @storage.participant_count(self, alt, date_hour) end |
#validate! ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/bandit/experiment.rb', line 37 def validate! [:title, :alternatives].each { |field| unless send(field) raise MissingConfigurationError, "#{field} must be set in experiment #{name}" end } end |