This is a project to attempt the completion of a Ruby port of Facebook's PlanOut experiment framework. There was a rough implementation but hadn't been updated in a while and Food52 has decided it would be beneficial to take this port a little further.
This is a line-by-line port and should produce identical results to the Python reference design. Additional features ported by Food52 are:
- Namespace Support
- Additional Testing
- Breakout of gem from
planouttoplan_out
Much credit is due to users @mohnish, @eytan, and @felixonmars for a lot of work on the initial port.
Add this line to your application's Gemfile:
gem 'planout'And then execute:
$ bundleOr install it yourself as:
$ gem install planoutThis defines a simple experiment that randomly assigns three variables, foo, bar, and baz.
foo and baz use userid as input, while bar uses a pair, namely userid combined with the value of foo from the prior step.
module PlanOut
class VotingExperiment < SimpleExperiment
# Experiment#assign takes params and an input array
def assign(params, **inputs)
userid = inputs[:userid]
params[:button_color] = UniformChoice.new({
choices: ['ff0000', '#00ff00'],
unit: userid
})
params[:button_text] = UniformChoice.new({
choices: ["I'm voting", "I'm a voter"],
unit: userid,
salt:'x'
})
end
end
endThen, we can examine the assignments produced for a few input userids. Note that since exposure logging is enabled by default, all of the experiments' inputs, configuration information, timestamp, and parameter assignments are pooped out via the Logger class.
my_exp = PlanOut::VotingExperiment.new(userid: 14)
my_button_color = my_exp.get(:button_color)
button_text = my_exp.get(:button_text)
puts "button color is #{my_button_color} and button text is #{button_text}."The output of the Ruby script looks something like this:
logged data: {"name":"PlanOut::VotingExperiment","time":1404944726,"salt":"PlanOut::VotingExperiment","inputs":{"userid":14},"params":{"button_color":"ff0000","button_text":"I'm a voter"},"event":"exposure"}
button color is ff0000 and button text is I'm a voter.For examples please refer to the examples directory.
Make sure you're in the ruby implementation directory of PlanOut and run
rake or rake test
to run the entire test suite.
If you wish to run a specific test, run
rake test TEST=test/testname.rb or even better ruby test/testname.rb