bandido 0.0.6 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc
CHANGED
@@ -1,3 +1,23 @@
|
|
1
|
+
= bandido
|
2
|
+
|
3
|
+
Bandido is a fork of the bandit gem, the README for which you may find below this section. It still uses the same code namespace as bandit (Bandit), should be compatible with projects already using bandit. If you run into any problems because of this, consider adding:
|
4
|
+
|
5
|
+
require 'bandit'
|
6
|
+
|
7
|
+
in your bandit initializer, e.g. config/initializers/bandit.rb
|
8
|
+
|
9
|
+
Bandido provides more control over cookies, participant counts and the like. Instead of calling bandit_choose and bandit_convert! in your code, you may use the following method combinations:
|
10
|
+
|
11
|
+
bandit_simple_choose/bandit_simple_convert! (no cookies involved, same as raw impressions)
|
12
|
+
bandit_session_choose/bandit_session_convert! (session cookie, same as bandit_choose with a fix)
|
13
|
+
bandit_sticky_choose/bandit_sticky_convert! (persistent cookies)
|
14
|
+
|
15
|
+
bandit_sticky_convert! creates a _converted cookie which stops additional conversions from being counted. For example, if you are collecting email addresses, a user may enter their email address more than once, but you may want to count all these attempts as one conversion.
|
16
|
+
|
17
|
+
You may also use the bandit_sticky_choose/bandit_session_convert! combination if you wish to use persistent cookies but allow each user to convert multiple times. This way visitors are always presented with the same alternative until they convert, at which point they are presented with another and so on.
|
18
|
+
|
19
|
+
Finally, if you use bandit_simple_convert!, please remember the second argument (alternative) is not optional, as we have no cookie to read from.
|
20
|
+
|
1
21
|
= bandit
|
2
22
|
|
3
23
|
Bandit is a multi-armed bandit optimization framework for Rails. It provides an alternative to A/B testing in Rails. For background and a comparison with A/B testing, see the whybandit.rdoc document or the blog post here[http://findingscience.com/rails/vanity/statistics/testing/2011/11/12/bandit:-a-b-testing-alternative-for-rails.html].
|
@@ -74,4 +94,4 @@ For instance, to generate a week's worth of fake data for the click_test above:
|
|
74
94
|
rake bandit:populate_data[click_test]
|
75
95
|
|
76
96
|
= Fault Tolerance
|
77
|
-
If the storage mechanism fails, then Bandit will automatically switch to in memory storage. It will then check every 5 minutes after that to see if the original storage mechanism is back up. If you have distributed front ends then each front end will continue to optimize (based on the in memory storage), but this optimization will be inefficient compared to shared storage among all front ends.
|
97
|
+
If the storage mechanism fails, then Bandit will automatically switch to in memory storage. It will then check every 5 minutes after that to see if the original storage mechanism is back up. If you have distributed front ends then each front end will continue to optimize (based on the in memory storage), but this optimization will be inefficient compared to shared storage among all front ends.
|
@@ -2,16 +2,14 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
2
2
|
require "bandit/version"
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
|
-
s.name = "
|
5
|
+
s.name = "bandido"
|
6
6
|
s.version = Bandit::VERSION
|
7
|
-
s.authors = ["Brian Muller
|
8
|
-
s.email = ["
|
9
|
-
s.homepage = "https://github.com/
|
7
|
+
s.authors = ["Michael Nacos"] # original author is Brian Muller, this is a fork
|
8
|
+
s.email = ["m.nacos@gmail.com"]
|
9
|
+
s.homepage = "https://github.com/mnacos/bandit"
|
10
10
|
s.summary = "Multi-armed bandit testing in rails"
|
11
|
-
s.description = "Bandit
|
12
|
-
|
13
|
-
s.rubyforge_project = "bandit"
|
14
|
-
|
11
|
+
s.description = "Bandit-clone, more options around cookies (simple/session/sticky)"
|
12
|
+
s.rubyforge_project = "bandido"
|
15
13
|
s.files = `git ls-files`.split("\n")
|
16
14
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
15
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
@@ -3,22 +3,29 @@ require 'active_support/concern'
|
|
3
3
|
module Bandit
|
4
4
|
module ControllerConcerns
|
5
5
|
extend ActiveSupport::Concern
|
6
|
-
|
6
|
+
|
7
7
|
module ClassMethods
|
8
|
-
|
9
8
|
end
|
10
9
|
|
11
10
|
module InstanceMethods
|
12
|
-
|
11
|
+
# look mum, no cookies
|
12
|
+
def bandit_simple_convert!(exp, alt, count=1)
|
13
|
+
Bandit.get_experiment(exp).convert!(alt, count)
|
14
|
+
end
|
15
|
+
|
16
|
+
# expects a session cookie, deletes it, will convert again
|
17
|
+
def bandit_session_convert!(exp, alt=nil, count=1)
|
13
18
|
cookiename = "bandit_#{exp}".intern
|
19
|
+
cookiename_converted = "bandit_#{exp}_converted".intern
|
14
20
|
alt ||= cookies.signed[cookiename]
|
15
|
-
unless alt.nil?
|
21
|
+
unless alt.nil? or cookies.signed[cookiename_converted]
|
16
22
|
Bandit.get_experiment(exp).convert!(alt, count)
|
17
23
|
cookies.delete(cookiename)
|
18
24
|
end
|
19
25
|
end
|
20
26
|
|
21
|
-
|
27
|
+
# creates a _converted cookie, prevents multiple conversions
|
28
|
+
def bandit_sticky_convert!(exp, alt=nil, count=1)
|
22
29
|
cookiename = "bandit_#{exp}".intern
|
23
30
|
cookiename_converted = "bandit_#{exp}_converted".intern
|
24
31
|
alt ||= cookies.signed[cookiename]
|
@@ -27,7 +34,16 @@ module Bandit
|
|
27
34
|
Bandit.get_experiment(exp).convert!(alt, count)
|
28
35
|
end
|
29
36
|
end
|
30
|
-
end
|
31
37
|
|
38
|
+
# FIXME: deprecated (for compatibility with bandit gem & older bandido versions)
|
39
|
+
# ------------------------------------------------------------------------------
|
40
|
+
def bandit_convert!(exp, alt=nil, count=1)
|
41
|
+
bandit_session_convert!(exp, alt, count)
|
42
|
+
end
|
43
|
+
|
44
|
+
def bandit_final_convert!(exp, alt=nil, count=1)
|
45
|
+
bandit_sticky_convert!(exp, alt, count)
|
46
|
+
end
|
47
|
+
end
|
32
48
|
end
|
33
49
|
end
|
@@ -3,38 +3,45 @@ require 'active_support/concern'
|
|
3
3
|
module Bandit
|
4
4
|
module ViewConcerns
|
5
5
|
extend ActiveSupport::Concern
|
6
|
-
|
6
|
+
|
7
7
|
module ClassMethods
|
8
|
-
|
9
8
|
end
|
10
9
|
|
11
10
|
module InstanceMethods
|
12
|
-
|
13
|
-
|
11
|
+
# always choose something new and increase the participant count
|
12
|
+
def bandit_simple_choose(exp)
|
13
|
+
Bandit.get_experiment(exp).choose(nil)
|
14
|
+
end
|
14
15
|
|
16
|
+
# stick to one alternative for the entire browser session
|
17
|
+
def bandit_session_choose(exp)
|
18
|
+
name = "bandit_#{exp}".intern
|
15
19
|
# choose url param with preference
|
16
20
|
value = params[name].nil? ? cookies.signed[name] : params[name]
|
17
|
-
|
18
21
|
# choose with default, and set cookie
|
19
22
|
cookies.signed[name] = Bandit.get_experiment(exp).choose(value)
|
20
23
|
end
|
21
24
|
|
25
|
+
# stick to one alternative until user deletes cookies or changes browser
|
22
26
|
def bandit_sticky_choose(exp)
|
23
27
|
name = "bandit_#{exp}".intern
|
24
|
-
|
25
28
|
# choose url param with preference
|
26
29
|
value = params[name].nil? ? cookies.signed[name] : params[name]
|
27
|
-
|
28
30
|
# sticky choice may outlast a given alternative
|
29
31
|
alternative = if Bandit.get_experiment(exp).alternatives.include?(value)
|
30
32
|
value
|
31
33
|
else
|
32
34
|
Bandit.get_experiment(exp).choose(value)
|
33
35
|
end
|
34
|
-
|
35
36
|
# re-set cookie
|
36
37
|
cookies.permanent.signed[name] = alternative
|
37
38
|
end
|
39
|
+
|
40
|
+
# FIXME: deprecated (for compatibility with bandit gem & older bandido versions)
|
41
|
+
# ------------------------------------------------------------------------------
|
42
|
+
def bandit_choose(exp)
|
43
|
+
bandit_session_choose(exp)
|
44
|
+
end
|
38
45
|
end
|
39
46
|
end
|
40
47
|
end
|
data/lib/bandit/version.rb
CHANGED
metadata
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bandido
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 8
|
10
|
+
version: 0.0.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
|
-
-
|
13
|
+
- Michael Nacos
|
14
14
|
autorequire:
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-03-19 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rails
|
@@ -63,9 +63,9 @@ dependencies:
|
|
63
63
|
version: "0"
|
64
64
|
type: :development
|
65
65
|
version_requirements: *id003
|
66
|
-
description: Bandit-clone,
|
66
|
+
description: Bandit-clone, more options around cookies (simple/session/sticky)
|
67
67
|
email:
|
68
|
-
-
|
68
|
+
- m.nacos@gmail.com
|
69
69
|
executables: []
|
70
70
|
|
71
71
|
extensions: []
|
@@ -78,7 +78,7 @@ files:
|
|
78
78
|
- LICENSE
|
79
79
|
- README.rdoc
|
80
80
|
- Rakefile
|
81
|
-
-
|
81
|
+
- bandido.gemspec
|
82
82
|
- lib/bandit.rb
|
83
83
|
- lib/bandit/config.rb
|
84
84
|
- lib/bandit/date_hour.rb
|