dat-science 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -115,8 +115,8 @@ By default the results of an experiment are discarded. This isn't very useful.
115
115
  `Experiment#publish` can be overridden to publish results via any
116
116
  instrumentation mechansim, which makes it easy to graph durations or
117
117
  matches/mismatches and store results. The only two events published by an
118
- experiment are `match` when the result of the control and candidate behaviors
119
- are the same, and `mismatch` when they aren't.
118
+ experiment are `:match` when the result of the control and candidate behaviors
119
+ are the same, and `:mismatch` when they aren't.
120
120
 
121
121
  ```ruby
122
122
  def publish(event, payload)
@@ -129,6 +129,8 @@ The published `payload` is a Symbol-keyed Hash:
129
129
  ```ruby
130
130
  {
131
131
  :experiment => "widget-permissions",
132
+ :first => :control,
133
+ :timestamp => <a-Time-instance>,
132
134
 
133
135
  :candidate => {
134
136
  :duration => 2.5,
@@ -140,32 +142,31 @@ The published `payload` is a Symbol-keyed Hash:
140
142
  :duration => 25.0,
141
143
  :exception => nil,
142
144
  :value => 24
143
- },
144
-
145
- :first => :control
145
+ }
146
146
  }
147
147
  ```
148
148
 
149
+ `:experiment` is the name of the experiment. `:first` is either `:candidate` or
150
+ `:control`, depending on which block was run first during the experiment.
151
+ `:timestamp` is the Time when the experiment started.
152
+
149
153
  The `:candidate` and `:control` Hashes have the same keys:
150
154
 
151
155
  * `:duration` is the execution in ms, expressed as a float.
152
156
  * `:exception` is a reference to any raised exception or `nil`.
153
157
  * `:value` is the result of the block.
154
158
 
155
- `:first` is either `:candidate` or `:control`, depending on which block was run
156
- first during the experiment. `:experiment` is the name of the experiment.
157
-
158
159
  #### Adding context
159
160
 
160
161
  It's often useful to add more information to your results, and
161
162
  `Experiment#context` makes it easy:
162
163
 
163
164
  ```ruby
164
- science "widget-permissions" do |experiment|
165
- experiment.context :user => user
165
+ science "widget-permissions" do |e|
166
+ e.context :user => user
166
167
 
167
- experiment.control { model.check_user(user).valid? } # old way
168
- experiment.candidate { user.can? :read, model } # new way
168
+ e.control { model.check_user(user).valid? } # old way
169
+ e.candidate { user.can? :read, model } # new way
169
170
  end
170
171
  ```
171
172
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = "dat-science"
3
- gem.version = "1.0.0"
3
+ gem.version = "1.1.0"
4
4
  gem.authors = ["John Barnette", "Rick Bradley"]
5
5
  gem.email = ["jbarnette@github.com"]
6
6
  gem.description = "Gradually test, measure, and track refactored code."
@@ -50,6 +50,8 @@ module Dat
50
50
  def run
51
51
  return run_control unless candidate? && enabled?
52
52
 
53
+ timestamp = Time.now
54
+
53
55
  if control_runs_first?
54
56
  control = observe_control
55
57
  candidate = observe_candidate
@@ -59,6 +61,7 @@ module Dat
59
61
  end
60
62
 
61
63
  payload = {
64
+ :timestamp => timestamp,
62
65
  :candidate => candidate.payload,
63
66
  :control => control.payload,
64
67
  :first => control_runs_first? ? :control : :candidate
@@ -106,6 +106,8 @@ class DatScienceExperimentTest < MiniTest::Unit::TestCase
106
106
  assert_equal "foo", payload[:experiment]
107
107
  assert_equal :control, payload[:first]
108
108
 
109
+ assert_in_delta Time.now.to_f, payload[:timestamp].to_f, 2.0
110
+
109
111
  assert payload[:control][:duration]
110
112
  assert_nil payload[:control][:exception]
111
113
  assert_equal :foo, payload[:control][:value]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dat-science
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: