Class: Mg::Choice

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/mountain-goat/models/mg/choice.rb

Overview

Mg::Choice represents a split of an a/b test

Attributes

mg_test_id

ID of Mg::Test which this is a choice for

name
value

The value to serve when this choice comes up (assuming non-switch)

opt1

Optional additional data

opt2

Optional additional data

served

Number of times this choice has been served

reward

Total accumulated reward for this choice

reward_count

How many rewards factor into this total

switch_type

Is this a switch-type choice

deleted_at

Is this choice still active?

Instance Method Summary collapse

Instance Method Details

#avg_points_per_serveObject

What is the average reward given to this choice



52
53
54
55
# File 'lib/mountain-goat/models/mg/choice.rb', line 52

def avg_points_per_serve
  return nil if self.served == 0 || self.served.nil? || self.reward.nil?
  return self.reward / self.served.to_f
end

#reward_rateObject

What is the average reward given to this choice



46
47
48
49
# File 'lib/mountain-goat/models/mg/choice.rb', line 46

def reward_rate
  return nil if self.reward_count == 0 || self.reward_count.nil? || self.reward.nil?
  return self.reward / self.reward_count.to_f
end

#tally_goal(goal, reward) ⇒ Object

Reward has a “default” or adjustable setting



37
38
39
40
41
42
43
# File 'lib/mountain-goat/models/mg/choice.rb', line 37

def tally_goal(goal, reward)
  self.transaction do
    Mg::Choice.update_counters(self.id, :reward_count => 1, :reward => reward)
  end
  
  return self.reload
end

#tally_serveObject

Mark that we have served this choice



27
28
29
30
31
32
33
34
# File 'lib/mountain-goat/models/mg/choice.rb', line 27

def tally_serve
  self.transaction do
    self.update_attribute(:reward, 0) if self.reward.nil? #we should merge this with the next line, but whatever
    Mg::Choice.update_counters(self.id, :served => 1)
  end
  
  return self.reload
end