Skip to content
It's not all that much, really.
Ruby
Find file
Pull request Compare This branch is 74 commits behind causes:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
lib fixed the :with bug Apr 29, 2010
spec
test/myapp
vendor
.braids
.gitignore
LICENSE
README
Rakefile
init.rb

README

Modesty is a really simple metrics and a/b testing framework that doesn't really do all that much.  It was inspired by assaf's Vanity (github.com/assaf/vanity).

## Usage
  Modesty.new_metric :foo do |foo|
    foo.submetric :bar
    foo.submetric :baz do |baz|
      baz.submetric :zot
    end
  end

This will create the following metrics:
>> Modesty.metrics.keys
[ :foo, :foo/:bar, :foo/:baz, :foo/:baz/:zot ]

Here's how you use a metric:
>> Modesty.track! :foo
=> 1
>> Modesty.metrics.map { |k,v| [k, v.values] } 
=> [[:foo, 1], [:"foo/bar", 0], [:"foo/baz", 0], [:"foo/baz/zot", 0]]
>> Modesty.track! :foo/:bar
=> 1
>> Modesty.metrics.map { |k,v| [k, v.values] } 
=> [[:foo, 2], [:"foo/bar", 1], [:"foo/baz", 0], [:"foo/baz/zot", 0]]
>> Modesty.track! :foo/:baz/:zot
=> 1
>> Modesty.metrics.map { |k,v| [k, v.values] } 
=> [[:foo, 3], [:"foo/bar", 1], [:"foo/baz", 1], [:"foo/baz/zot", 1]]

Make sense?  Tracking a metric tracks all its parents.

Experiments are similar.  Here's how you make an experiment:
  
  Modesty.new_experiment :button_size do |e|
    e.metrics :conversions, :views
    e.alternatives :huge, :medium, :small
  end

Then, you can do something like this (in a controller, say)

  Modesty.identify! viewer.id
  @button_size = case Modesty.ab_test :button_size
    when :huge; 500
    when :medium; 300
    when :small; 2
  end
   
If you have to do something a little more in-depth, you could use this pattern:

  Modesty.identify! viewer.id
  Modesty.ab_test :button_size/:huge do
    # render something for this group
  end
  Modesty.ab_test :button_size/:medium do
    #etc
  end

Lastly, you can directly test whether we're in a particular group with 
  if Modesty.ab_test? :button_size/:small
    #something
  else
    #something else
  end

Sweet.

##Datastores

Right now there are two datastores available: Redis and a sweet mock Redis for testing.  To switch between them, use

  Modesty.data = :redis
  Modesty.data = :mock

If you need to pass in more options, use

  Modesty.set_store :redis, :port => 8888, :host => '123.123.123.1'

## Rails

By default, Modesty looks in configy/modesty.yml for something like:

  datastore:
    type: redis
    port: 6739
    host: localhost

  paths:
    experiments: experiments
    metrics: metrics

In this, the default setup, Modesty will look for experiments in #{Rails.root}/experiments, and metrics in #{Rails.root}/metrics.  If no config file is found, or you omit something, Modesty will use these settings.

Have fun!
Something went wrong with that request. Please try again.