Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
ptaoussanis committed Mar 19, 2013
2 parents f08cd38 + b0bd903 commit 9331c90
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 29 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Current [semantic](http://semver.org/) version:

```clojure
[com.taoensso/touchstone "0.13.1"]
[com.taoensso/touchstone "0.14.0"]
```

# Touchstone, a Clojure split-testing library
Expand All @@ -26,7 +26,7 @@ Touchstone is an attempt to bring **dead-simple, high-power split-testing** to a
Depend on Touchstone in your `project.clj`:

```clojure
[com.taoensso/touchstone "0.13.1"]
[com.taoensso/touchstone "0.14.0"]
```

and `require` the library:
Expand All @@ -49,7 +49,7 @@ Traditional split-testing consists of 4 steps:

The particular multi-armed bandit technique used by Touchstone means that we only concern ourselves with steps 1 and 3. Steps 2 and 4 are handled automatically by the algorithm.

**To optimize a Ring web application**, start by adding `(taoensso.touchstone.ring/make-wrap-random-test-subject-id)` to your middleware stack.
**To optimize a Ring web application**, start by adding `(taoensso.touchstone.ring/wrap-random-test-subject-id)` to your middleware stack.

One or more named-test selectors can then be used as part of your page content:

Expand Down
4 changes: 2 additions & 2 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
(defproject com.taoensso/touchstone "0.13.1"
(defproject com.taoensso/touchstone "0.14.0"
:description "Clojure split-testing library"
:url "https://github.com/ptaoussanis/touchstone"
:license {:name "Eclipse Public License"}
:dependencies [[org.clojure/clojure "1.3.0"]
[org.clojure/tools.macro "0.1.1"]
[com.taoensso/carmine "1.1.0"]
[com.taoensso/carmine "1.6.0"]
[org.clojure/math.combinatorics "0.0.3"]]
:profiles {:1.3 {:dependencies [[org.clojure/clojure "1.3.0"]]}
:1.4 {:dependencies [[org.clojure/clojure "1.4.0"]]}
Expand Down
9 changes: 4 additions & 5 deletions src/taoensso/touchstone.clj
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,16 @@
;;;; Config & bindings

(utils/defonce* config
"This map atom controls everything about the way Touchstone operates.
See source code for details.
WARNING: per-test config API very likely to change before 1.x release."
"Alpha - subject to change.
This map atom controls everything about the way Touchstone operates.
See source code for details."
(atom {:carmine {:pool (car/make-conn-pool)
:spec (car/make-conn-spec)}
:tests {:default {:test-session-ttl 7200 ; Last activity +2hrs
;; Turn on for engagement testing:
:count-duplicate-activity? false}}}))

(defn set-config! [[k & ks] val] (swap! config assoc-in (cons k ks) val))
(defn set-config! [ks val] (swap! config assoc-in ks val))

(defn test-config "Returns per-test config, merged over defaults."
[test-name]
Expand Down
34 changes: 19 additions & 15 deletions src/taoensso/touchstone/ring.clj
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,25 @@

(comment (bot-user-agent? {"user-agent" "GoogleBot"}))

(defn make-wrap-random-test-subject-id
"Returns Ring middleware that generates, sessionizes, and binds a test-subject
id for requests eligible for split-testing (by default this excludes clients
that report themselves as bots)."
[& {:keys [eligible?-fn]
(defn wrap-random-test-subject-id
"Ring middleware that generates, sessionizes, and binds a test-subject id for
requests eligible for split-testing (by default this excludes clients that
report themselves as bots)."
[handler
& {:keys [eligible?-fn]
:or {eligible?-fn (fn [request] (not (bot-user-agent? (:headers request))))}}]
(fn [handler]
(fn [request]
(if-not (eligible?-fn request)
(handler request)
(fn [request]
(if-not (eligible?-fn request)
(handler request)

(if (contains? (:session request) :mab-subject-id)
(let [sessionized-id (get-in request [:session :mab-subject-id])]
(touchstone/with-test-subject sessionized-id (handler request)))

(if (contains? (:session request) :mab-subject-id)
(let [sessionized-id (get-in request [:session :mab-subject-id])]
(touchstone/with-test-subject sessionized-id (handler request)))
(let [new-id (str (rand-int 2147483647))
response (touchstone/with-test-subject new-id (handler request))]
(assoc-in response [:session :mab-subject-id] new-id))))))

(let [new-id (str (rand-int 2147483647))
response (touchstone/with-test-subject new-id (handler request))]
(assoc-in response [:session :mab-subject-id] new-id)))))))
(defn make-wrap-random-test-subject-id
"DEPRECATED. Please use `wrap-random-test-subject-id."
[& args] (fn [handler] (apply wrap-random-test-subject-id handler args)))
6 changes: 2 additions & 4 deletions src/taoensso/touchstone/utils.clj
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,5 @@
(time (dotimes [_ 10000] (name :foo)))
(time (dotimes [_ 10000] (scoped-name :foo))))

(defn approx=
[x y & {:keys [significance]
:or {significance 0.001}}]
(< (- x y) significance))
(defn approx= [x y & [signf]]
(< (Math/abs (double (- x y))) (or signf 0.001)))

0 comments on commit 9331c90

Please sign in to comment.