Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial commit

  • Loading branch information...
commit f529cf677872051e70313c432f25d4fd7c5800e4 0 parents
@andrew andrew authored
4 .gitignore
@@ -0,0 +1,4 @@
+*.gem
+.bundle
+Gemfile.lock
+pkg/*
4 Gemfile
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in split-export.gemspec
+gemspec
20 LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2011 Andrew Nesbitt
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
6 Rakefile
@@ -0,0 +1,6 @@
+require 'bundler/gem_tasks'
+require 'rspec/core/rake_task'
+
+RSpec::Core::RakeTask.new('spec')
+
+task :default => :spec
51 Readme.mdown
@@ -0,0 +1,51 @@
+# Split::Export
+
+An extension to [Split](http://github.com/andrew/split) to allow for easy exporting of AB testing data.
+
+## Requirements
+
+The split gem and its dependencies.
+
+## Setup
+
+If you are using bundler add split to your Gemfile:
+
+ gem 'split-export', :require => 'split/export'
+
+Then run:
+
+ bundle install
+
+Otherwise install the gem:
+
+ gem install split-export
+
+and require it in your project:
+
+ require 'split/export'
+
+## Usage
+
+ require 'split/export'
+ Split::Export.to_csv
+
+## Development
+
+Source hosted at [GitHub](http://github.com/andrew/split-export).
+Report Issues/Feature requests on [GitHub Issues](http://github.com/andrew/split-export/issues).
+
+Tests can be ran with `rake spec`
+
+### Note on Patches/Pull Requests
+
+ * Fork the project.
+ * Make your feature addition or bug fix.
+ * Add tests for it. This is important so I don't break it in a
+ future version unintentionally.
+ * Commit, do not mess with rakefile, version, or history.
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
+ * Send me a pull request. Bonus points for topic branches.
+
+## Copyright
+
+Copyright (c) 2011 Andrew Nesbitt. See LICENSE for details.
36 lib/split/export.rb
@@ -0,0 +1,36 @@
+require 'split'
+require 'csv'
+require 'bigdecimal'
+
+if CSV.const_defined? :Reader
+ require 'fastercsv'
+ CSV = FasterCSV
+end
+
+module Split
+ module Export
+ extend self
+
+ def round(number, precision = 2)
+ BigDecimal.new(number.to_s).round(precision).to_f
+ end
+
+ def to_csv
+ csv = CSV.generate do |csv|
+ csv << ['Experiment', 'Alternative', 'Participants', 'Completed', 'Conversion Rate', 'Z score', 'Control', 'Winner']
+ Split::Experiment.all.each do |experiment|
+ experiment.alternatives.each do |alternative|
+ csv << [experiment.name,
+ alternative.name,
+ alternative.participant_count,
+ alternative.completed_count,
+ round(alternative.conversion_rate, 3),
+ round(alternative.z_score, 3),
+ alternative.control?,
+ alternative.to_s == experiment.winner.to_s]
+ end
+ end
+ end
+ end
+ end
+end
5 lib/split/export/version.rb
@@ -0,0 +1,5 @@
+module Split
+ module Export
+ VERSION = "0.2.2"
+ end
+end
19 spec/export_spec.rb
@@ -0,0 +1,19 @@
+require 'spec_helper'
+
+describe Split::Export do
+ before :each do
+ experiment = Split::Experiment.find_or_create('link_color', 'blue', 'red', 'green')
+ blue = Split::Alternative.find('blue', 'link_color')
+ blue.participant_count = 5
+ blue.completed_count = 3
+ blue.save
+ red = Split::Alternative.find('red', 'link_color')
+ red.participant_count = 6
+ red.completed_count = 4
+ red.save
+ end
+
+ it "should generate a csv of split data" do
+ Split::Export.to_csv.should eql("Experiment,Alternative,Participants,Completed,Conversion Rate,Z score,Control,Winner\nlink_color,blue,5,3,0.6,0.0,true,false\nlink_color,red,6,4,0.667,0.215,false,false\n")
+ end
+end
4 spec/spec_helper.rb
@@ -0,0 +1,4 @@
+require 'rubygems'
+require 'bundler/setup'
+require 'split'
+require 'split/export'
23 split-export.gemspec
@@ -0,0 +1,23 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "split/export/version"
+
+Gem::Specification.new do |s|
+ s.name = "split-export"
+ s.version = Split::Export::VERSION
+ s.authors = ["Andrew Nesbitt"]
+ s.email = ["andrewnez@gmail.com"]
+ s.homepage = "https://github.com/andrew/split-export"
+ s.summary = %q{Split extension to export your data}
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+
+ s.add_dependency(%q<split>, ["~> 0.2.2"])
+ s.add_dependency(%q<fastercsv>, ['>= 1.2.0'])
+
+ # Development Dependencies
+ s.add_development_dependency(%q<rspec>, ["~> 2.6"])
+end
Please sign in to comment.
Something went wrong with that request. Please try again.