light_abtest 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: aa63219217431598713e4e282e97d02e5e80a207
4
+ data.tar.gz: 7537c7efdb247566dad435674beedc3f7d09d774
5
+ SHA512:
6
+ metadata.gz: ced67ea256d17fffab5216e0957df806fecdab9d5597e962dae7c6e52761d482f8c2d5765db0b1106145335c84c91bbce73f8dd9b3ba863c147529f2d8fba1ba
7
+ data.tar.gz: 078436dd1bdeb8cd04fbb0da069916cebdcc7c3bc9e0d7373e163a8e88de09870dbedb6a0f0ea96891e03171c98280cfecc7a24f6907396f99598356572bd636
data/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in light_abtest.gemspec
4
+ gemspec
5
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Mo Lin
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # LightAbtest
2
+
3
+ This is a light weight, easy to use AB testing framework gem for backend algorithm test
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'light_abtest'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install light_abtest
20
+
21
+ ## Usage
22
+
23
+ This gem is very light weight and easy to use. The framework is based on redis.
24
+ Example of usage:
25
+ ```ruby
26
+ require 'light_abtest'
27
+ redis = Redis.new(:host => "localhost", :port => 6379, :db => 0)
28
+ ```
29
+ the input will be:
30
+ number of parts you want to split, weight of each part, your redis server
31
+ after you initialize the LightAbtest object, it will store your split rate into redis, the key is called "abtest_rate:"
32
+ ```ruby
33
+ abtest = LightAbtest.new(3, [0.5, 0.3, 0.2], redis)
34
+ ```
35
+ then using split method to split your users, assume you have users
36
+ ```ruby
37
+ users = [0,1,2,3,4,5,6,7,8,9]
38
+ abtest.split(users)
39
+ ```
40
+ then you should see keys "ab:0", "ab:1", ..., "ab:9" in your redis db, and the value will be 0 or 1 or 2 as algo_id
41
+
42
+ the add_method function will let you associate your algorithms to these algo_ids
43
+ for example you have three recommendation algorithms, you can do
44
+ ```ruby
45
+ abtest.add_method(0, "RecommendAlgo1.process")
46
+ abtest.add_method(1, "RecommendAlgo2.process")
47
+ abtest.add_method(2, "RecommendAlgo3.process")
48
+ ```
49
+
50
+ then you will have below information stored in your redis db
51
+ key: "algo_id:0", value: "RecommendAlgo1.process"
52
+ key: "algo_id:1", value: "RecommendAlgo2.process"
53
+ key: "algo_id:2", value: "RecommendAlgo3.process"
54
+ then whenever you want to do recommendation for your user and test these three algorithm
55
+ you just need to retrieve the user's algo_id by
56
+
57
+ ```ruby
58
+ algo_id = redis.get("ab:#{user_id}")
59
+ eval(redis.get("algo_id:" + algo_id))
60
+ ```
61
+
62
+ ## Contributing
63
+
64
+ 1. Fork it ( https://github.com/[my-github-username]/light_abtest/fork )
65
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
66
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
67
+ 4. Push to the branch (`git push origin my-new-feature`)
68
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/lib/.DS_Store ADDED
Binary file
@@ -0,0 +1,3 @@
1
+ module LightAbtest
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,48 @@
1
+ require "light_abtest/version"
2
+ require "redis"
3
+
4
+ class LightAbtest
5
+ def initialize
6
+ end
7
+
8
+ def set_split_rate(n, rate, redis)
9
+ @n = n
10
+ @ratio = ratio
11
+ @split_results = {}
12
+ @redis = redis
13
+ store_split_rate
14
+ end
15
+
16
+ def split(target)
17
+ full_size = target.size
18
+ (0..@n-1).each do |i|
19
+ split_result = target.sample(@ratio[i]*full_size)
20
+ target -= split_result
21
+ @split_results[i] = split_result
22
+ end
23
+ if target.size > 0
24
+ @split_results[0] += target
25
+ end
26
+ save_split_to_redis
27
+ end
28
+
29
+ def add_method(algo_id, code)
30
+ key = "algo_id:" + algo_id.to_s
31
+ @redis.set(key, code)
32
+ end
33
+
34
+ def save_split_to_redis
35
+ @split_results.keys.each do |i|
36
+ @split_results[i].each do |j|
37
+ key = "ab:" + j.to_s
38
+ @redis.set(key, i)
39
+ end
40
+ end
41
+ end
42
+
43
+ def store_split_rate
44
+ key = "abtest_rate:"
45
+ @redis.set(key, @ratio)
46
+ end
47
+ end
48
+
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'light_abtest/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "light_abtest"
8
+ spec.version = LightAbtest::VERSION
9
+ spec.authors = ["Mo Lin"]
10
+ spec.email = ["ml3309@columbia.edu"]
11
+ spec.summary = "This is a light weight, easy to use AB testing framework gem for backend algorithm test"
12
+ spec.description = ""
13
+ spec.homepage = "https://github.com/madnoodlesmlin/RubyLightWeightABTesting"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency 'rspec'
24
+ spec.add_development_dependency 'redis'
25
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: light_abtest
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Mo Lin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: redis
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: ''
70
+ email:
71
+ - ml3309@columbia.edu
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .DS_Store
77
+ - .gitignore
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - lib/.DS_Store
83
+ - lib/light_abtest.rb
84
+ - lib/light_abtest/version.rb
85
+ - light_abtest.gemspec
86
+ homepage: https://github.com/madnoodlesmlin/RubyLightWeightABTesting
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.0.14
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: This is a light weight, easy to use AB testing framework gem for backend
110
+ algorithm test
111
+ test_files: []