yacc-vanity 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/CHANGELOG +243 -0
  2. data/Gemfile +24 -0
  3. data/MIT-LICENSE +21 -0
  4. data/README.rdoc +74 -0
  5. data/Rakefile +189 -0
  6. data/bin/vanity +69 -0
  7. data/lib/vanity.rb +36 -0
  8. data/lib/vanity/adapters/abstract_adapter.rb +135 -0
  9. data/lib/vanity/adapters/active_record_adapter.rb +304 -0
  10. data/lib/vanity/adapters/mock_adapter.rb +157 -0
  11. data/lib/vanity/adapters/mongodb_adapter.rb +162 -0
  12. data/lib/vanity/adapters/redis_adapter.rb +154 -0
  13. data/lib/vanity/backport.rb +26 -0
  14. data/lib/vanity/commands/list.rb +21 -0
  15. data/lib/vanity/commands/report.rb +64 -0
  16. data/lib/vanity/commands/upgrade.rb +34 -0
  17. data/lib/vanity/experiment/ab_test.rb +482 -0
  18. data/lib/vanity/experiment/base.rb +212 -0
  19. data/lib/vanity/frameworks/rails.rb +245 -0
  20. data/lib/vanity/helpers.rb +59 -0
  21. data/lib/vanity/metric/active_record.rb +83 -0
  22. data/lib/vanity/metric/base.rb +244 -0
  23. data/lib/vanity/metric/google_analytics.rb +83 -0
  24. data/lib/vanity/metric/remote.rb +53 -0
  25. data/lib/vanity/playground.rb +332 -0
  26. data/lib/vanity/templates/_ab_test.erb +26 -0
  27. data/lib/vanity/templates/_experiment.erb +5 -0
  28. data/lib/vanity/templates/_experiments.erb +7 -0
  29. data/lib/vanity/templates/_metric.erb +14 -0
  30. data/lib/vanity/templates/_metrics.erb +13 -0
  31. data/lib/vanity/templates/_report.erb +27 -0
  32. data/lib/vanity/templates/flot.min.js +1 -0
  33. data/lib/vanity/templates/jquery.min.js +19 -0
  34. data/lib/vanity/templates/vanity.css +26 -0
  35. data/lib/vanity/templates/vanity.js +82 -0
  36. data/lib/vanity/version.rb +11 -0
  37. data/test/experiment/ab_test.rb +700 -0
  38. data/test/experiment/base_test.rb +136 -0
  39. data/test/experiments/age_and_zipcode.rb +19 -0
  40. data/test/experiments/metrics/cheers.rb +3 -0
  41. data/test/experiments/metrics/signups.rb +2 -0
  42. data/test/experiments/metrics/yawns.rb +3 -0
  43. data/test/experiments/null_abc.rb +5 -0
  44. data/test/metric/active_record_test.rb +249 -0
  45. data/test/metric/base_test.rb +293 -0
  46. data/test/metric/google_analytics_test.rb +104 -0
  47. data/test/metric/remote_test.rb +108 -0
  48. data/test/myapp/app/controllers/application_controller.rb +2 -0
  49. data/test/myapp/app/controllers/main_controller.rb +7 -0
  50. data/test/myapp/config/boot.rb +110 -0
  51. data/test/myapp/config/environment.rb +10 -0
  52. data/test/myapp/config/environments/production.rb +0 -0
  53. data/test/myapp/config/routes.rb +3 -0
  54. data/test/passenger_test.rb +43 -0
  55. data/test/playground_test.rb +10 -0
  56. data/test/rails_test.rb +294 -0
  57. data/test/test_helper.rb +134 -0
  58. data/vanity.gemspec +25 -0
  59. metadata +161 -0
@@ -0,0 +1,243 @@
1
+ == 1.5.1 (2010-12-20)
2
+
3
+ Fixes some minor bugs in RoR when including the Dashboard (netguru)
4
+
5
+
6
+ == 1.5.0 (2010-10-23)
7
+
8
+ Note: MongoDB URI scheme changed from mongo: to mongodb: to be consistent with
9
+ the rest of the civilized world. If you get an error because Vanity can't find
10
+ the MongoDB adapter, fear not! It's still there, just need to update your
11
+ config/vanity.yml file.
12
+
13
+
14
+ Rails 3 support (Adam Keys, Stephen Celis, Brian Leonard, Ryan Carver)
15
+
16
+ Changed MongoDB URI scheme from 'mongo://' to the standard 'mongodb://' and
17
+ renamed the mongodb adapter filename to make it match (JS Boulanger)
18
+
19
+ Added support for ERB in YAML configuration files (JS Boulanger)
20
+
21
+ Fixed initialization of playground's Rails defaults such that they can be
22
+ overriden in the environment (JS Boulanger)
23
+
24
+
25
+ == 1.4.0 (2010-08-06)
26
+
27
+ Note: Run this command to upgrade your database to 1.4, or you will not have
28
+ access to collected metrics and experiment data:
29
+
30
+ vanity upgrade
31
+
32
+
33
+ Connection adapters! We have a new way for managing connections which extends
34
+ to multiple adapters (not just Redis). The easiest is to use the configuration
35
+ file config/vanity.yml. For example:
36
+
37
+ development:
38
+ adapter: redis
39
+ production:
40
+ adapter: mongodb
41
+
42
+ We get to keep Redis, add new MongoDB adapter, but lose Mock. It's still there,
43
+ but there's a new way to use Vanity outside production: you can turn data
44
+ collection on/off.
45
+
46
+ Under Rails, data collection is turned off in all environments except
47
+ production. To turn if on/off:
48
+
49
+ Vanity.playground.collecting = true/false.
50
+
51
+
52
+ This release switches to latest Redis gem and uses redis-namespace (what took
53
+ me so long?) If your own code relies on the Redis gem, watch out: there are
54
+ some subtle incompatibilities between 1.x and 2.x.
55
+
56
+
57
+ Now using RVM, gemsets and Bundler to test Vanity in different configurations.
58
+ To run the full set of tests in all the supported versions of Ruby:
59
+ rake test:rubies
60
+ To test specific version of Ruby:
61
+ rake test:rubies[1.8.7]
62
+ To switch around:
63
+ rvm 1.9.2@vanity
64
+
65
+ * Added: Adapter API, see Vanity::Adapters::AbstractAdapter and
66
+ Vanity::Adapters::RedisAdapter.
67
+ * Added: MongoDB support.
68
+ * Added: Upgrade command.
69
+ * Added: Metric.last_update_at.
70
+ * Added: Vanity.playground.collecting. You want this to be true only in
71
+ production environment. When false, disables collecting of metric and
72
+ experiment data.
73
+ * Added: Remote metrics. Push data to remote service.
74
+ * Added: Partial support for multi-series metrics. Laying the ground for the
75
+ future.
76
+ * Change: Vanity.playground.redis and redis= methods are deprecated, use
77
+ connection and establish_connection instead.
78
+ * Removed: Metric.created_at, derived from experiment and never used.
79
+
80
+
81
+ == 1.3.0 (2010-03-01)
82
+
83
+ This release adds support for Google Analytics, AdWords and forking servers
84
+ (Passenger, Unicorn).
85
+
86
+ To view Google Analytics metrics from within Vanity, first make sure you are
87
+ using Garb. For example, in your Gemfile:
88
+
89
+ gem "vanity", "1.3.0"
90
+ gem "garb", "0.5.0"
91
+
92
+ Next, authenticate using your account credentials. For example, in your
93
+ config/environments/production.rb:
94
+
95
+ require "garb"
96
+ Garb::Session.login('..email..', '..password..', account_type: "GOOGLE") rescue nil
97
+
98
+ Last, define Vanity metrics that tap to Google Analytics metrics. For example:
99
+
100
+ metric "Acquisition: Visitors" do
101
+ description "Unique visitors on any given page, as tracked by Google Analytics"
102
+ google_analytics "UA-1828623-6", :visitors
103
+ end
104
+
105
+ * Added: Support for Google Analytics metrics, thanks to Tony Pitale's Garb and blog post: http://www.viget.com/extend/user-goal-tracking-in-rails-with-vanity-and-google-analytics/
106
+ * Added: Vanity query parameter that you can use to choose a particular alternative, e.g. to tie an advertisement banner with content of the site.
107
+ * Added: Command line "vanity list" catalogs all ongoing experiments, their alternatives (and fingerprints) and all metrics.
108
+ * Added: Playground.reconnect!, particularly useful when forking (Passenger, Unicorn, etc).
109
+ * Added: Vanity loads Redis configuration from config/redis.yml (if you have such a file).
110
+ * Changed: New way to specify connection configuration: Vanity.playground.redis = "localhost:6379". Use this instead of the separate host/port/db attribute.
111
+ * Changed: Rails integration now separates use_vanity method, filters and helpers.
112
+ * Changed: Explicit vanity_context_filter and vanity_reload_filter so you can skip them, or order filters relative to them.
113
+ * Fixed: If metric cannot be loaded (e.g. offline, no db access) show error message for that metric but don't break dashboard.
114
+ * Fixed: AbTest incorrectly calls identify method instead of identity (issue #2)
115
+ * Fixed: Running vanity command, automatically detects and loads Rails.
116
+ * Fixed: Vanity now picks up on load_path set from within config/environment.rb.
117
+ * Removed: Vanity.playground.define is deprecated. Bad choice for a method name. If you need this feature, make a suggestion and let's create a better API.
118
+
119
+ == 1.2.0 (2009-12-14)
120
+ This release introduces metrics backed by ActiveRecord. Use them when your model is already tracking a metric, and you get instant historical data.
121
+
122
+ Example, track sign ups using User model:
123
+
124
+ metric "Signups" do
125
+ model Account
126
+ end
127
+
128
+ Example, track satisfaction using Survey model:
129
+ metric "Satisfaction" do
130
+ model Survey, :average=>:rating
131
+ end
132
+
133
+ Example, track only high ratings:
134
+ metric "High ratings" do
135
+ model Rating, :conditions=>["stars >= 4"]
136
+ end
137
+
138
+ There's no need to call track! on these metrics.
139
+
140
+ * Added: Metrics backed by ActiveRecord.
141
+ * Added: track! and ab_test methods now available from Object (i.e. everywhere).
142
+ * Added: Playground.load!. Now loading all metrics and experiments from Rails initializer.
143
+ * Changed: Decoupled metric name from identifier. You can now define a metric with more descriptive name, e.g. "Cheers per second (user satisfaction)" and keep their ID simple. Identifier is matched against the file name (for metrics loaded from experiments/metrics).
144
+ * Changed: Metrics no longer defined on-demand, i.e. calling playground.metric either returns existing metric or raises exception.
145
+ * Changed: Playground.experiments returns hash instead of array.
146
+ * Changed: All dates in report are UTC, since we don't know which locale to use.
147
+ * Removed: Object.experiment is deprecated, please call Vanity.playground.experiment directly.
148
+ * Fixed: Playground no longer changes logging level on supplied logger.
149
+
150
+ == 1.1.1 (2009-12-4)
151
+ * Fixed: Binding issue that shows up on 1.8.6/7.
152
+
153
+ == 1.1.0 (2009-12-4)
154
+ This release introduces metrics. Metrics are the gateway drug to better software.
155
+
156
+ It’s as simple as defining a metric:
157
+
158
+ metric "Cheers" do
159
+ description "They love us, don't they?"
160
+ end
161
+
162
+ Tracking it from your code:
163
+
164
+ track! :cheers
165
+
166
+ And watching the graph from the Dashboard.
167
+
168
+ You can (should) also use metrics with your A/B tests, for example:
169
+
170
+ ab_test "Pricing options" do
171
+ metrics :signup
172
+ alternatives 15, 25, 29
173
+ end
174
+
175
+ This new usage may become requirement in a future release.
176
+
177
+ Much thanks to Ian Sefferman for fixing issues with Ruby 1.8.7 and Rails support.
178
+
179
+ * Added: Metrics.
180
+ * Added: Use Vanity.playground.mock! when running tests and you'd rather not access a live Redis server.
181
+ * Changed: A/B tests now using metrics for tracking.
182
+ * Changed: Now throwing NameError instead of LoadError when failing to load experiment/metric. NameError can be rescued on same line.
183
+ * Changed: New, easier URL mapping for Dashboard: map.vanity "/vanity", :controller=>:vanity.
184
+ * Changed: All tests are green on Ruby 1.8.6, 1.8.7 and 1.9.1.
185
+ * Changed: Switched to redis-rb from http://github.com/ezmobius/redis-rb.
186
+ * Deprecated: Please call experiment method with experiment identifier (a symbol) and not experiment name.
187
+
188
+ == 1.0.0 (2009-11-19)
189
+ This release changes the way you define a new experiment. You can use a method suitable for the type of experiment you want to define, or call the generic define method (previously: experiment method). For example:
190
+
191
+ ab_test "My A/B test" do
192
+ alternatives :a, :b
193
+ end
194
+
195
+ The experiment method is no longer overloaded: it looks up an experiment (loading its definition if necessary), but does not define an experiment. The ab_test method is overloaded, though this may change in the future.
196
+
197
+ In addition, the ab_goal! method is now track!. This method may be used for other tests in the future.
198
+
199
+ * Added: A/B test report now showing number of participants.
200
+ * Added: AbTest.score method accepts minimum probability (default 90), and
201
+ * Removed: Experiment.reset! method. Destroy and save have the same effect.
202
+ * Changed: Playground.define now requires an experiment type, ab_test is not the default any more.
203
+ * Changed: When you run Vanity in development mode (configuration.cache_classes = false), it will reload experiments on each request. You can also Vanity.playground.reload!.
204
+ * Changed: Fancy AJAX trickery in Rails console.
205
+ * Changed: You can break long experiment descriptions into multiple paragraphs using two consecutive newlines.
206
+ * Changed: AbTest confidence becomes probability; only returns choice alternative with probability equal or higher than that.
207
+ * Changed: ab_goal! becomes track!.
208
+ * Changed: Console becomes Dashboard, which is less confusing with rails console (script/console).
209
+
210
+ == 0.3.1 (2009-11-13)
211
+ * Changed: Redis 1.0 is now vendored into Vanity. This means one less dependecy ... actually two, since Redis brings with it RSpec.
212
+
213
+ == 0.3.0 (2009-11-13)
214
+ * Added: score now includes least performing alternatives, names and values.
215
+ * Added: shiny reports.
216
+ * Added: Rails console shows current experiments status and also allows you to choose which alternative you want to see.
217
+ * Changed: letters instead of numbers for options (option 1 => option A).
218
+ * Changed: experiment.alternatives is now an immutable snapshot.
219
+ * Changed: experiment.score returns populated alternative objects instead of structs.
220
+ * Changed: experiment.chooses uses Redis to store state, better for (when we get to) browser integration.
221
+ * Changed: experiment.chooses skips recording participant or conversion.
222
+ * Changed: to MIT license.
223
+
224
+ == 0.2.2 (2009-11-12)
225
+ * Added: vanity binary, with single command for generating a report.
226
+ * Added: return alternative by value from experiment.alternative(val) method.
227
+ * Added: reset an experiment by calling reset!.
228
+ * Added: experiment alternative name (option 1, option 2, etc).
229
+ * Added: new scoring algorithm: use experiment.score instead of alternative.z_score/confidence.
230
+ * Added: experiment.conclusion for plain English results.
231
+
232
+ == 0.2.1 (2009-11-11)
233
+ * Added: z-score and confidence level for A/B test alternatives.
234
+ * Added: test auto-completion and auto-outcome (complete_it, outcome_is).
235
+ * Changed: default alternatives are now false/true, so if can't decide outcome, fall back on false.
236
+
237
+ == 0.2.0 (2009-11-10)
238
+ * Added: experiment method on object, used to define and access experiments.
239
+ * Added: playground configuration (Vanity.playground.namespace = , etc).
240
+ * Added: use_vanity now accepts block instead of symbol.
241
+ * Changed: Vanity::Helpers becomes Vanity::Rails.
242
+ * Changed: A/B test experiments alternatives now handled using Alternatives object.
243
+ * Removed: A/B test measure method no longer in use.
data/Gemfile ADDED
@@ -0,0 +1,24 @@
1
+ source :rubygems
2
+ gemspec
3
+
4
+ group :development do
5
+ gem "jekyll"
6
+ gem "rake"
7
+ gem "RedCloth"
8
+ gem "yard"
9
+ end
10
+
11
+ group :test do
12
+ gem "bson_ext"
13
+ gem "garb"
14
+ gem "mocha"
15
+ gem "mongo"
16
+ gem "passenger"
17
+ gem "rails", "2.3.8"
18
+ gem "rack", "1.1.0"
19
+ gem "shoulda"
20
+ gem "sqlite3-ruby", "1.2.5" # 1.3.0 doesn't like Ruby 1.9.1
21
+ gem "timecop"
22
+ #gem "SystemTimer"
23
+ gem "webmock"
24
+ end
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2010 Assaf Arkin
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
@@ -0,0 +1,74 @@
1
+ Vanity is an Experiment Driven Development framework for Rails.
2
+
3
+ * All about Vanity: http://vanity.labnotes.org
4
+ * On github: http://github.com/assaf/vanity
5
+
6
+ http://farm3.static.flickr.com/2540/4099665871_497f274f68_o.jpg
7
+
8
+
9
+ == A/B Testing With Rails (In 5 Easy Steps)
10
+
11
+ <b>Step 1:</b> Start using Vanity in your Rails application:
12
+
13
+ Rails::Initializer.run do |config|
14
+ gem.config "vanity"
15
+
16
+ config.after_initialize do
17
+ require "vanity"
18
+ end
19
+ end
20
+
21
+ And:
22
+
23
+ class ApplicationController < ActionController::Base
24
+ use_vanity :current_user
25
+ end
26
+
27
+ <b>Step 2:</b> Define your first A/B test. This experiment goes in the file <code>experiments/price_options.rb</code>:
28
+
29
+ ab_test "Price options" do
30
+ description "Mirror, mirror on the wall, who's the better price of all?"
31
+ alternatives 19, 25, 29
32
+ metrics :signups
33
+ end
34
+
35
+ <b>Step 3:</b> Present the different options to your users:
36
+
37
+ <h2>Get started for only $<%= ab_test :price_options %> a month!</h2>
38
+
39
+ <b>Step 4:</b> Measure conversion:
40
+
41
+ class SignupController < ApplicationController
42
+ def signup
43
+ @account = Account.new(params[:account])
44
+ if @account.save
45
+ track! :signups
46
+ redirect_to @acccount
47
+ else
48
+ render action: :offer
49
+ end
50
+ end
51
+ end
52
+
53
+ <b>Step 5:</b> Check the report:
54
+
55
+ vanity report --output vanity.html
56
+
57
+
58
+ == Contributing
59
+
60
+ * Fork the project
61
+ * Please use a topic branch to make your changes, it's easier to test them that way
62
+ * Fix, patch, enhance, document, improve, sprinkle pixie dust
63
+ * At minimum run rake test, if possible, please run rake test:all
64
+ * Tests. Please. Run rake test, of if you can, rake test:all
65
+ * Send a pull request on GitHub
66
+
67
+
68
+ == Credits/License
69
+
70
+ Original code, copyright of Assaf Arkin, released under the MIT license.
71
+
72
+ Documentation available under the Creative Commons Attribution license.
73
+
74
+ For full list of credits and licenses: http://vanity.labnotes.org/credits.html.
@@ -0,0 +1,189 @@
1
+ require "rake/testtask"
2
+
3
+ # -- Building stuff --
4
+
5
+ spec = Gem::Specification.load(Dir["*.gemspec"].first)
6
+
7
+ desc "Build the Gem"
8
+ task :build do
9
+ sh "gem build #{spec.name}.gemspec"
10
+ end
11
+
12
+ desc "Install #{spec.name} locally"
13
+ task :install=>:build do
14
+ sudo = "sudo" unless File.writable?( Gem::ConfigMap[:bindir])
15
+ sh "#{sudo} gem install #{spec.name}-#{spec.version}.gem"
16
+ end
17
+
18
+ desc "Push new release to gemcutter and git tag"
19
+ task :push=>["test:all", "build"] do
20
+ sh "git push"
21
+ puts "Tagging version #{spec.version} .."
22
+ sh "git tag v#{spec.version}"
23
+ sh "git push --tag"
24
+ puts "Building and pushing gem .."
25
+ sh "gem push #{spec.name}-#{spec.version}.gem"
26
+ end
27
+
28
+
29
+ # -- Testing stuff --
30
+
31
+ desc "Test everything"
32
+ task "test:all"=>"test:rubies"
33
+
34
+ # Ruby versions we're testing with.
35
+ RUBIES = %w{1.8.7 1.9.2}
36
+
37
+ # Use rake test:rubies to run all combination of tests (see test:adapters) using
38
+ # all the versions of Ruby specified in RUBIES. Or to test a specific version of
39
+ # Ruby, rake test:rubies[1.8.7].
40
+ #
41
+ # This task uses RVM to install all the Ruby versions it needs, and creates a
42
+ # vanity gemset in each one that includes Bundler and all the gems specified in
43
+ # Gemfile. If anything goes south you can always wipe these gemsets or uninstall
44
+ # these Rubies and start over.
45
+ desc "Test using multiple versions of Ruby"
46
+ task "test:rubies", :ruby do |t, args|
47
+ rubies = args.ruby ? [args.ruby] : RUBIES
48
+ rubies.each do |ruby|
49
+ puts "** Setup #{ruby}"
50
+ sh "env rvm_install_on_use_flag=1 rvm_gemset_create_on_use_flag=1 rvm use #{ruby}@vanity"
51
+ sh "rvm #{ruby}@vanity rake test:setup"
52
+ puts
53
+ puts "** Test using #{ruby}"
54
+ sh "rvm #{ruby}@vanity -S bundle exec rake test:adapters #{'--trace' if Rake.application.options.trace}"
55
+ end
56
+ end
57
+
58
+ task "test:setup" do
59
+ # Intended to be used from test:rubies, within specific RVM context.
60
+ begin # Make sure we got Bundler installed.
61
+ require "bundler"
62
+ rescue LoadError
63
+ sh "gem install bundler"
64
+ end
65
+ begin # Make sure we got all the dependencies
66
+ sh "bundle exec ruby -e puts > /dev/null"
67
+ rescue
68
+ sh "bundle install"
69
+ end
70
+ end
71
+
72
+ # These are all the adapters we're going to test with.
73
+ ADAPTERS = %w{redis mongodb}
74
+
75
+ desc "Test using different back-ends"
76
+ task "test:adapters", :adapter do |t, args|
77
+ adapters = args.adapter ? [args.adapter] : ADAPTERS
78
+ adapters.each do |adapter|
79
+ puts "** Testing #{adapter} adapter"
80
+ sh "rake test ADAPTER=#{adapter} #{'--trace' if Rake.application.options.trace}"
81
+ end
82
+ end
83
+
84
+ # Run the test suit.
85
+
86
+ task :default=>:test
87
+ desc "Run all tests"
88
+ Rake::TestTask.new do |task|
89
+ task.test_files = FileList['test/**/*_test.rb']
90
+ if Rake.application.options.trace
91
+ #task.warning = true
92
+ task.verbose = true
93
+ elsif Rake.application.options.silent
94
+ task.ruby_opts << "-W0"
95
+ else
96
+ task.verbose = true
97
+ end
98
+ task.ruby_opts << "-I."
99
+ end
100
+
101
+ task(:clobber) { rm_rf "tmp" }
102
+
103
+
104
+ # -- Documenting stuff --
105
+
106
+ begin
107
+ require "yard"
108
+ YARD::Rake::YardocTask.new(:yardoc) do |task|
109
+ task.files = FileList["lib/**/*.rb"].exclude("lib/vanity/backport.rb")
110
+ task.options = "--output", "html/api", "--title", "Vanity #{spec.version}", "--main", "README.rdoc", "--files", "CHANGELOG"
111
+ end
112
+ rescue LoadError
113
+ end
114
+
115
+ desc "Jekyll generates the main documentation (sans API)"
116
+ task(:jekyll) { sh "jekyll", "doc", "html" }
117
+ file "html/vanity.pdf"=>:jekyll do |t|
118
+ pages = %w{index metrics ab_testing rails identity configuring contributing}.map{ |p| "html/#{p}.html" }
119
+ args = %w{--disable-javascript --outline --title Vanity --header-html doc/_layouts/_header.html --print-media-type}
120
+ args.concat %w{--margin-left 20 --margin-right 20 --margin-top 20 --margin-bottom 20 --header-spacing 5}
121
+ args.concat pages << t.name
122
+ sh "wkhtmltopdf", *args
123
+ end
124
+
125
+ file "html/vanity-api.zip"=>:yardoc do |t|
126
+ Dir.chdir "html" do
127
+ sh "zip vanity-api.zip -r api"
128
+ end
129
+ end
130
+ desc "Create documentation in docs directory (including API)"
131
+ task :docs=>[:jekyll, :yardoc, "html/vanity-api.zip", "html/vanity.pdf"]
132
+ desc "Remove temporary files and directories"
133
+ task(:clobber) { rm_rf "html" ; rm_rf ".yardoc" }
134
+
135
+ desc "Publish documentation to vanity.labnotes.org"
136
+ task :publish=>[:clobber, :docs] do
137
+ sh "rsync -cr --del --progress html/ labnotes.org:/var/www/vanity/"
138
+ end
139
+
140
+
141
+ # -- Misc --
142
+
143
+ task :report do
144
+ $LOAD_PATH.unshift "lib"
145
+ require "vanity"
146
+ require "timecop"
147
+ Vanity.playground.load_path = "test/experiments"
148
+ Vanity.playground.experiments.values.each(&:destroy)
149
+ Vanity.playground.metrics.values.each(&:destroy!)
150
+ Vanity.playground.reload!
151
+
152
+ # Control 182 35 19.23% N/A
153
+ # Treatment A 180 45 25.00% 1.33
154
+ # Treatment B 189 28 14.81% -1.13
155
+ # Treatment C 188 61 32.45% 2.94
156
+ Vanity.playground.experiment(:null_abc).instance_eval do
157
+ fake nil=>[182,35], :red=>[180,45], :green=>[189,28], :blue=>[188,61]
158
+ @created_at = (Date.today - 40).to_time
159
+ @completed_at = (Date.today - 35).to_time
160
+ end
161
+
162
+ Vanity.playground.experiment(:age_and_zipcode).instance_eval do
163
+ fake false=>[80,35], true=>[84,32]
164
+ @created_at = (Date.today - 30).to_time
165
+ @completed_at = (Date.today - 15).to_time
166
+ end
167
+
168
+ Vanity.context = Object.new
169
+ Vanity.context.instance_eval { def vanity_identity ; 0 ; end }
170
+ signups = 50
171
+ (Date.today - 90..Date.today).each do |date|
172
+ Timecop.travel date do
173
+ signups += rand(15) - 5
174
+ Vanity.playground.track! :signups, signups
175
+ end
176
+ end
177
+
178
+ cheers, yawns = 0, 0
179
+ (Date.today - 80..Date.today).each do |date|
180
+ Timecop.travel date do
181
+ cheers = cheers - 5 + rand(20)
182
+ Vanity.playground.track! :yawns, cheers
183
+ yawns = yawns - 5 + rand(30)
184
+ Vanity.playground.track! :cheers, yawns
185
+ end
186
+ end
187
+
188
+ Vanity::Commands.report ENV["OUTPUT"]
189
+ end