ablab 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ablab/version.rb +1 -1
- data/lib/ablab.rb +17 -4
- data/spec/ablab_spec.rb +50 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d558894e13e626caa2bd6375a6eea7b30f32769f
|
4
|
+
data.tar.gz: 095902b47a9baf06fd1a98c61fd5c4e3aa4540b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b9fc6b731810bfc862ec838cc823e06672da11ad25972a2af3fce833314f49ecd15f5b7806b5f56c8bf2ad61bc1ad1a1fe79cb8d4a4db7d20e092165319971e
|
7
|
+
data.tar.gz: e443c648d9bbb7b9e5674ef69c8a9557edc07c3e911fbc5a43ead35cafff2de87d19f27e7738211b6f2ef5a2673ceba4e563ed20248da939e6a0d13f8bc362fe
|
data/lib/ablab/version.rb
CHANGED
data/lib/ablab.rb
CHANGED
@@ -46,12 +46,13 @@ module Ablab
|
|
46
46
|
extend ModuleMethods
|
47
47
|
|
48
48
|
class Experiment
|
49
|
-
attr_reader :name, :groups, :control
|
49
|
+
attr_reader :name, :groups, :control, :callbacks
|
50
50
|
|
51
51
|
def initialize(name, &block)
|
52
|
-
@name
|
53
|
-
@control
|
54
|
-
@groups
|
52
|
+
@name = name.to_sym
|
53
|
+
@control = Group.new(:control, 'control group')
|
54
|
+
@groups = [@control]
|
55
|
+
@callbacks = []
|
55
56
|
instance_exec(&block)
|
56
57
|
end
|
57
58
|
|
@@ -75,6 +76,10 @@ module Ablab
|
|
75
76
|
@groups << group
|
76
77
|
end
|
77
78
|
|
79
|
+
def on_track(&block)
|
80
|
+
@callbacks << block
|
81
|
+
end
|
82
|
+
|
78
83
|
def results
|
79
84
|
@result ||= Result.new(self)
|
80
85
|
@result.data
|
@@ -98,10 +103,12 @@ module Ablab
|
|
98
103
|
|
99
104
|
def track_view!
|
100
105
|
Ablab.tracker.track_view!(experiment.name, group, session_id)
|
106
|
+
perform_callbacks!(:view)
|
101
107
|
end
|
102
108
|
|
103
109
|
def track_success!
|
104
110
|
Ablab.tracker.track_success!(experiment.name, group, session_id)
|
111
|
+
perform_callbacks!(:success)
|
105
112
|
end
|
106
113
|
|
107
114
|
def group
|
@@ -116,6 +123,12 @@ module Ablab
|
|
116
123
|
exp_hash = Digest::SHA1.hexdigest(experiment.name.to_s)[-8..-1].to_i(16)
|
117
124
|
(sid_hash ^ exp_hash) % 1000
|
118
125
|
end
|
126
|
+
|
127
|
+
def perform_callbacks!(event)
|
128
|
+
experiment.callbacks.each do |cbk|
|
129
|
+
cbk.call(event, experiment.name, group, session_id)
|
130
|
+
end
|
131
|
+
end
|
119
132
|
end
|
120
133
|
|
121
134
|
class Group
|
data/spec/ablab_spec.rb
CHANGED
@@ -150,6 +150,10 @@ describe Ablab do
|
|
150
150
|
end
|
151
151
|
end
|
152
152
|
|
153
|
+
let(:run) do
|
154
|
+
Ablab::Run.new(experiment, '86wfd8w6df')
|
155
|
+
end
|
156
|
+
|
153
157
|
it 'gets assigned to the right group' do
|
154
158
|
run = Ablab::Run.new(experiment, 0)
|
155
159
|
allow(run).to receive(:draw).and_return 0
|
@@ -191,6 +195,52 @@ describe Ablab do
|
|
191
195
|
d2 = `bundle exec ruby -I#{dir} -e "require 'ablab'; require 'ostruct'; puts Ablab::Run.new(OpenStruct.new(name: :foo), '8asd7f8asf7').draw"`
|
192
196
|
expect(d1).to eq(d2.to_i)
|
193
197
|
end
|
198
|
+
|
199
|
+
it "returns an integer number < 1000" do
|
200
|
+
expect(
|
201
|
+
(0..100).map { |i| Ablab::Run.new(experiment, "#{i}").draw }.all? { |x| x.is_a?(Integer) && x < 1000 }
|
202
|
+
).to be(true)
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
describe "#group" do
|
207
|
+
it "returns one of the groups" do
|
208
|
+
expect(Ablab::Run.new(experiment, rand(12345).to_s).group).to be_in([:a, :b, :control])
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
describe "#track_view!" do
|
213
|
+
it "tracks the view" do
|
214
|
+
expect(Ablab.tracker).to receive(:track_view!)
|
215
|
+
.with(run.experiment.name, run.group, run.session_id)
|
216
|
+
run.track_view!
|
217
|
+
end
|
218
|
+
|
219
|
+
it "performs callbacks" do
|
220
|
+
x = nil
|
221
|
+
experiment.on_track do |event, experiment, group, session|
|
222
|
+
x = [event, experiment, group, session]
|
223
|
+
end
|
224
|
+
run.track_view!
|
225
|
+
expect(x).to eq([:view, :foo, run.group, run.session_id])
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
describe "#track_success!" do
|
230
|
+
it "tracks the success" do
|
231
|
+
expect(Ablab.tracker).to receive(:track_success!)
|
232
|
+
.with(run.experiment.name, run.group, run.session_id)
|
233
|
+
run.track_success!
|
234
|
+
end
|
235
|
+
|
236
|
+
it "performs callbacks" do
|
237
|
+
x = nil
|
238
|
+
experiment.on_track do |event, experiment, group, session|
|
239
|
+
x = [event, experiment, group, session]
|
240
|
+
end
|
241
|
+
run.track_success!
|
242
|
+
expect(x).to eq([:success, :foo, run.group, run.session_id])
|
243
|
+
end
|
194
244
|
end
|
195
245
|
end
|
196
246
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ablab
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luca Ongaro
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|