profitably-abingo 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,13 @@
1
+ class AbingoMigrationGenerator < Rails::Generators::Base
2
+ source_root File.expand_path('../templates', __FILE__)
3
+
4
+ def generate_migration
5
+ copy_file "create_abingo_tables.rb", "db/migrate/#{migration_timestamp}_create_abingo_tables.rb"
6
+ end
7
+
8
+ private
9
+
10
+ def migration_timestamp
11
+ @migration_timestamp ||= Time.now.strftime("%Y%m%d%H%M%S")
12
+ end
13
+ end
@@ -0,0 +1,29 @@
1
+ class CreateAbingoTables < ActiveRecord::Migration
2
+ def self.up
3
+ create_table "experiments", :force => true do |t|
4
+ t.string "test_name"
5
+ t.string "status"
6
+ t.timestamps
7
+ end
8
+
9
+ add_index "experiments", "test_name"
10
+ #add_index "experiments", "created_on"
11
+
12
+ create_table "alternatives", :force => true do |t|
13
+ t.integer :experiment_id
14
+ t.string :content
15
+ t.string :lookup, :limit => 32
16
+ t.integer :weight, :default => 1
17
+ t.integer :participants, :default => 0
18
+ t.integer :conversions, :default => 0
19
+ end
20
+
21
+ add_index "alternatives", "experiment_id"
22
+ add_index "alternatives", "lookup" #Critical for speed, since we'll primarily be updating by that.
23
+ end
24
+
25
+ def self.down
26
+ drop_table :experiments
27
+ drop_table :alternatives
28
+ end
29
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate abingo_migration Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,8 @@
1
+ class AbingoViewsGenerator < Rails::Generators::Base
2
+ source_root File.expand_path('../templates', __FILE__)
3
+
4
+ def copy_views
5
+ copy_file "views/ab_dashboard/_experiment.html.erb", "app/views/ab_dashboard/_experiment.html.erb"
6
+ copy_file "views/ab_dashboard/index.html.erb", "app/views/ab_dashboard/index.html.erb"
7
+ end
8
+ end
@@ -0,0 +1,43 @@
1
+ <h3><%= experiment.test_name.titleize %> <%= %Q|<i>(Test completed)</i>| if experiment.status != "Live" %> </h3>
2
+ <% short_circuit = Abingo.cache.read("Abingo::Experiment::short_circuit(#{experiment.test_name})".gsub(" ", "")) %>
3
+ <table class="experiment" style="border: 1px black;">
4
+ <tr class="header_row">
5
+ <th>Name</th>
6
+ <th>Participants</th>
7
+ <th>Conversions</th>
8
+ <th>Notes</th>
9
+ </tr>
10
+ <tr class="experiment_row">
11
+ <td>Experiment Total: </td>
12
+ <td><%= experiment.participants %> </td>
13
+ <td><%= experiment.conversions %> (<%= experiment.pretty_conversion_rate %>)</td>
14
+ <td></td>
15
+ </tr>
16
+ <% experiment.alternatives.each do |alternative| %>
17
+ <tr class="alternative_row">
18
+ <td>
19
+ <%= h alternative.content %>
20
+ </td>
21
+ <td><%= alternative.participants %></td>
22
+ <td><%= alternative.conversions %> (<%= alternative.pretty_conversion_rate %>)</td>
23
+ <td>
24
+ <% unless experiment.status != "Live" %>
25
+ <%= link_to("End experiment, picking this.", url_for(:id => alternative.id,
26
+ :action => "end_experiment"),
27
+ :method => :post,
28
+ :confirm => "Are you sure you want to terminate this experiment? This is not reversible."
29
+ ) %>
30
+ <% else %>
31
+ <% if alternative.content == short_circuit %>
32
+ <b>(All users seeing this.)</b>
33
+ <% end %>
34
+ <% end %>
35
+ </td>
36
+ </tr>
37
+ <% end %>
38
+ <tr>
39
+ <td colspan="4">
40
+ <b>Significance test results: </b><%= experiment.describe_result_in_words %>
41
+ </td>
42
+ </tr>
43
+ </table>
@@ -0,0 +1,20 @@
1
+ <div id="abingo_dashboard">
2
+ <p><h1>Welcome to your A/Bingo dashboard!</h1>
3
+
4
+ See <a href="http://www.bingocardcreator.com/abingo">the official site</a> for documentation.
5
+ I encourage you to customize this page to fit your needs. See /vendor/plugins/abingo/views for
6
+ the view templates. Hack them to pieces -- please!
7
+ </p>
8
+
9
+ <p>
10
+ <% if flash[:notice] %>
11
+ <span style="color: green;"><%= flash[:notice] %> </span>
12
+ <% end %>
13
+ <h2>All Experiments</h2>
14
+
15
+ <% @experiments.each do |experiment| %>
16
+ <%= render :partial => "dashboard/experiment", :locals => {:experiment => experiment} %>
17
+ <br/>
18
+ <% end %>
19
+ </p>
20
+ </div>
@@ -0,0 +1,64 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{profitably-abingo}
8
+ s.version = "0.1.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Patrick McKenzie", "Wildfalcon", "Matthias Bauer"]
12
+ s.date = %q{2011-10-25}
13
+ s.description = %q{Rails A/B testing. One minute to install. One line to set up a new A/B test. One line to track conversion.}
14
+ s.email = %q{admin@profitably.com}
15
+ s.extra_rdoc_files = [
16
+ "README.md"
17
+ ]
18
+ s.files = [
19
+ "MIT-LICENSE",
20
+ "README.md",
21
+ "Rakefile",
22
+ "VERSION",
23
+ "init.rb",
24
+ "install.rb",
25
+ "lib/abingo.rb",
26
+ "lib/abingo/alternative.rb",
27
+ "lib/abingo/controller/dashboard.rb",
28
+ "lib/abingo/conversion_rate.rb",
29
+ "lib/abingo/experiment.rb",
30
+ "lib/abingo/rails/controller/dashboard.rb",
31
+ "lib/abingo/railtie.rb",
32
+ "lib/abingo/statistics.rb",
33
+ "lib/abingo/views/ab_dashboard/_experiment.erb",
34
+ "lib/abingo/views/ab_dashboard/index.erb",
35
+ "lib/abingo_sugar.rb",
36
+ "lib/abingo_view_helper.rb",
37
+ "lib/generators/abingo_migration/USAGE",
38
+ "lib/generators/abingo_migration/abingo_migration_generator.rb",
39
+ "lib/generators/abingo_migration/templates/create_abingo_tables.rb",
40
+ "lib/generators/abingo_views/USAGE",
41
+ "lib/generators/abingo_views/abingo_views_generator.rb",
42
+ "lib/generators/abingo_views/templates/views/ab_dashboard/_experiment.html.erb",
43
+ "lib/generators/abingo_views/templates/views/ab_dashboard/index.html.erb",
44
+ "profitably-abingo.gemspec",
45
+ "strip.rb",
46
+ "test/abingo_test.rb",
47
+ "test/test_helper.rb",
48
+ "uninstall.rb"
49
+ ]
50
+ s.homepage = %q{https://github.com/profitably/abingo}
51
+ s.require_paths = ["lib"]
52
+ s.rubygems_version = %q{1.5.3}
53
+ s.summary = %q{A/B Testing for Rails}
54
+
55
+ if s.respond_to? :specification_version then
56
+ s.specification_version = 3
57
+
58
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
59
+ else
60
+ end
61
+ else
62
+ end
63
+ end
64
+
data/strip.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'find'
2
+ require 'fileutils'
3
+ def find_and_delete(path, pattern)
4
+ Find.find(path) do |f|
5
+ if !File.file?(f) and f[pattern]
6
+ FileUtils.rm_rf(f)
7
+ end
8
+ end
9
+ end
10
+ # print all the ruby files
11
+ find_and_delete(".", /\.svn$/)
@@ -0,0 +1,187 @@
1
+ require 'test_helper'
2
+
3
+ class AbingoTest < ActiveSupport::TestCase
4
+
5
+ #Wipes cache, D/B prior to doing a test run.
6
+ Abingo.cache.clear
7
+ Abingo::Experiment.delete_all
8
+ Abingo::Alternative.delete_all
9
+
10
+ test "identity automatically assigned" do
11
+ assert Abingo.identity != nil
12
+ end
13
+
14
+ test "alternative parsing" do
15
+ array = %w{a b c}
16
+ assert_equal array, Abingo.parse_alternatives(array)
17
+ assert_equal 65, Abingo.parse_alternatives(65).size
18
+ assert_equal 4, Abingo.parse_alternatives(2..5).size
19
+ assert !(Abingo.parse_alternatives(2..5).include? 1)
20
+ end
21
+
22
+ test "experiment creation" do
23
+ assert_equal 0, Abingo::Experiment.count
24
+ assert_equal 0, Abingo::Alternative.count
25
+ alternatives = %w{A B}
26
+ alternative_selected = Abingo.test("unit_test_sample_A", alternatives)
27
+ assert_equal 1, Abingo::Experiment.count
28
+ assert_equal 2, Abingo::Alternative.count
29
+ assert alternatives.include?(alternative_selected)
30
+ end
31
+
32
+ test "exists works right" do
33
+ Abingo.test("exist works right", %w{does does_not})
34
+ assert Abingo::Experiment.exists?("exist works right")
35
+ end
36
+
37
+ test "alternatives picked consistently" do
38
+ alternative_picked = Abingo.test("consistency_test", 1..100)
39
+ 100.times do
40
+ assert_equal alternative_picked, Abingo.test("consistency_test", 1..100)
41
+ end
42
+ end
43
+
44
+ test "participation works" do
45
+ new_tests = %w{participationA participationB participationC}
46
+ new_tests.map do |test_name|
47
+ Abingo.test(test_name, 1..5)
48
+ end
49
+
50
+ participating_tests = Abingo.cache.read("Abingo::participating_tests::#{Abingo.identity}") || []
51
+
52
+ new_tests.map do |test_name|
53
+ assert participating_tests.include? test_name
54
+ end
55
+ end
56
+
57
+ test "participants counted" do
58
+ test_name = "participants_counted_test"
59
+ alternative = Abingo.test(test_name, %w{a b c})
60
+
61
+ ex = Abingo::Experiment.find_by_test_name(test_name)
62
+ lookup = Abingo::Alternative.calculate_lookup(test_name, alternative)
63
+ chosen_alt = Abingo::Alternative.find_by_lookup(lookup)
64
+ assert_equal 1, ex.participants
65
+ assert_equal 1, chosen_alt.participants
66
+ end
67
+
68
+ test "conversion tracking by test name" do
69
+ test_name = "conversion_test_by_name"
70
+ alternative = Abingo.test(test_name, %w{a b c})
71
+ Abingo.bingo!(test_name)
72
+ ex = Abingo::Experiment.find_by_test_name(test_name)
73
+ lookup = Abingo::Alternative.calculate_lookup(test_name, alternative)
74
+ chosen_alt = Abingo::Alternative.find_by_lookup(lookup)
75
+ assert_equal 1, ex.conversions
76
+ assert_equal 1, chosen_alt.conversions
77
+ Abingo.bingo!(test_name)
78
+
79
+ #Should still only have one because this conversion should not be double counted.
80
+ #We haven't specified that in the test options.
81
+ assert_equal 1, Abingo::Experiment.find_by_test_name(test_name).conversions
82
+ end
83
+
84
+ test "conversion tracking by conversion name" do
85
+ conversion_name = "purchase"
86
+ tests = %w{conversionTrackingByConversionNameA conversionTrackingByConversionNameB conversionTrackingByConversionNameC}
87
+ tests.map do |test_name|
88
+ Abingo.test(test_name, %w{A B}, :conversion => conversion_name)
89
+ end
90
+
91
+ Abingo.bingo!(conversion_name)
92
+ tests.map do |test_name|
93
+ assert_equal 1, Abingo::Experiment.find_by_test_name(test_name).conversions
94
+ end
95
+ end
96
+
97
+ test "short circuiting works" do
98
+ conversion_name = "purchase"
99
+ test_name = "short circuit test"
100
+ alt_picked = Abingo.test(test_name, %w{A B}, :conversion => conversion_name)
101
+ ex = Abingo::Experiment.find_by_test_name(test_name)
102
+ alt_not_picked = (%w{A B} - [alt_picked]).first
103
+
104
+ ex.end_experiment!(alt_not_picked, conversion_name)
105
+
106
+ ex.reload
107
+ assert_equal "Finished", ex.status
108
+
109
+ Abingo.bingo!(test_name) #Should not be counted, test is over.
110
+ assert_equal 0, ex.conversions
111
+
112
+ old_identity = Abingo.identity
113
+ Abingo.identity = "shortCircuitTestNewIdentity"
114
+ Abingo.test(test_name, %w{A B}, :conversion => conversion_name)
115
+ Abingo.identity = old_identity
116
+ ex.reload
117
+ assert_equal 1, ex.participants #Original identity counted, new identity not counted b/c test stopped
118
+ end
119
+
120
+ test "proper experiment creation in high concurrency" do
121
+ conversion_name = "purchase"
122
+ test_name = "high_concurrency_test"
123
+ alternatives = %w{foo bar}
124
+
125
+ threads = []
126
+ 5.times do
127
+ threads << Thread.new do
128
+ Abingo.test(test_name, alternatives, conversion_name)
129
+ 1
130
+ end
131
+ end
132
+ sleep(10)
133
+ assert_equal 1, Abingo::Experiment.count_by_sql(["select count(id) from experiments where test_name = ?", test_name])
134
+ end
135
+
136
+ test "non-humans are ignored for participation and conversions if not explicitly counted" do
137
+ Abingo.options[:count_humans_only] = true
138
+ Abingo.options[:expires_in] = 1.hour
139
+ Abingo.options[:expires_in_for_bots] = 3.seconds
140
+ first_identity = Abingo.identity = "unsure_if_human#{Time.now.to_i}"
141
+ test_name = "are_you_a_human"
142
+ Abingo.test(test_name, %w{does_not matter})
143
+
144
+ assert_false Abingo.is_human?, "Identity not marked as human yet."
145
+
146
+ ex = Abingo::Experiment.find_by_test_name(test_name)
147
+ Abingo.bingo!(test_name)
148
+ assert_equal 0, ex.participants, "Not human yet, so should have no participants."
149
+ assert_equal 0, ex.conversions, "Not human yet, so should have no conversions."
150
+
151
+ Abingo.human!
152
+
153
+ #Setting up second participant who doesn't convert.
154
+ Abingo.identity = "unsure_if_human_2_#{Time.now.to_i}"
155
+ Abingo.test(test_name, %w{does_not matter})
156
+ Abingo.human!
157
+
158
+ ex = Abingo::Experiment.find_by_test_name(test_name)
159
+ assert_equal 2, ex.participants, "Now that we're human, our participation should matter."
160
+ assert_equal 1, ex.conversions, "Now that we're human, our conversions should matter, but only one of us converted."
161
+ end
162
+
163
+ test "Participating tests for a given identity" do
164
+ Abingo.identity = "test_participant"
165
+ test_names = (1..3).map {|t| "participating_test_test_name #{t}"}
166
+ test_alternatives = %w{yes no}
167
+ test_names.each {|test_name| Abingo.test(test_name, test_alternatives)}
168
+ ex = Abingo::Experiment.last
169
+ ex.end_experiment!("no") #End final of 3 tests, leaving 2 presently running
170
+
171
+ assert_equal 2, Abingo.participating_tests.size #Pairs for two tests
172
+ Abingo.participating_tests.each do |key, value|
173
+ assert test_names.include? key
174
+ assert test_alternatives.include? value
175
+ end
176
+
177
+ assert_equal 3, Abingo.participating_tests(false).size #pairs for three tests
178
+ Abingo.participating_tests(false).each do |key, value|
179
+ assert test_names.include? key
180
+ assert test_alternatives.include? value
181
+ end
182
+
183
+ Abingo.identity = "test_nonparticipant"
184
+ assert_equal({}, Abingo.participating_tests)
185
+ end
186
+
187
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'active_support'
3
+ require 'active_support/test_case'
data/uninstall.rb ADDED
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: profitably-abingo
3
+ version: !ruby/object:Gem::Version
4
+ hash: 31
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 2
10
+ version: 0.1.2
11
+ platform: ruby
12
+ authors:
13
+ - Patrick McKenzie
14
+ - Wildfalcon
15
+ - Matthias Bauer
16
+ autorequire:
17
+ bindir: bin
18
+ cert_chain: []
19
+
20
+ date: 2011-10-25 00:00:00 -04:00
21
+ default_executable:
22
+ dependencies: []
23
+
24
+ description: Rails A/B testing. One minute to install. One line to set up a new A/B test. One line to track conversion.
25
+ email: admin@profitably.com
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files:
31
+ - README.md
32
+ files:
33
+ - MIT-LICENSE
34
+ - README.md
35
+ - Rakefile
36
+ - VERSION
37
+ - init.rb
38
+ - install.rb
39
+ - lib/abingo.rb
40
+ - lib/abingo/alternative.rb
41
+ - lib/abingo/controller/dashboard.rb
42
+ - lib/abingo/conversion_rate.rb
43
+ - lib/abingo/experiment.rb
44
+ - lib/abingo/rails/controller/dashboard.rb
45
+ - lib/abingo/railtie.rb
46
+ - lib/abingo/statistics.rb
47
+ - lib/abingo/views/ab_dashboard/_experiment.erb
48
+ - lib/abingo/views/ab_dashboard/index.erb
49
+ - lib/abingo_sugar.rb
50
+ - lib/abingo_view_helper.rb
51
+ - lib/generators/abingo_migration/USAGE
52
+ - lib/generators/abingo_migration/abingo_migration_generator.rb
53
+ - lib/generators/abingo_migration/templates/create_abingo_tables.rb
54
+ - lib/generators/abingo_views/USAGE
55
+ - lib/generators/abingo_views/abingo_views_generator.rb
56
+ - lib/generators/abingo_views/templates/views/ab_dashboard/_experiment.html.erb
57
+ - lib/generators/abingo_views/templates/views/ab_dashboard/index.html.erb
58
+ - profitably-abingo.gemspec
59
+ - strip.rb
60
+ - test/abingo_test.rb
61
+ - test/test_helper.rb
62
+ - uninstall.rb
63
+ has_rdoc: true
64
+ homepage: https://github.com/profitably/abingo
65
+ licenses: []
66
+
67
+ post_install_message:
68
+ rdoc_options: []
69
+
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ hash: 3
78
+ segments:
79
+ - 0
80
+ version: "0"
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ requirements: []
91
+
92
+ rubyforge_project:
93
+ rubygems_version: 1.5.3
94
+ signing_key:
95
+ specification_version: 3
96
+ summary: A/B Testing for Rails
97
+ test_files: []
98
+