Skip to content

Instantly share code, notes, and snippets.

@ithayer
Last active December 13, 2015 20:09
Show Gist options
  • Save ithayer/4967981 to your computer and use it in GitHub Desktop.
Save ithayer/4967981 to your computer and use it in GitHub Desktop.
;; Babbage provides some built-in simple accumulators.
user> (use 'babbage.core)
user> (require '[babbage.provided.core :as p])
nil
;; Create several sets of interest.
user> (def mysets
(sets {:firefox? #(-> % :browser (= :firefox))
:chrome? #(-> % :browser (= :chrome))
:ie? #(-> % :browser #{:ie-7 :ie-8 :ie-9 :ie-10})
:spent-at-all? #(-> % :spend (> 0))}))
;; Using the result from before, compute the mean of the "spend" field for each set.
user> (->> (all-visitors) :compile-all
(calculate mysets {:spend (stats :spend p/mean)}))
;; We get back the mean for each set.
user> (->> (all-visitors) :compile-all
(calculate mysets {:spend (stats :spend p/mean)}))
{:all {:spend {:mean 3.0, :sum 9, :count 3}},
:firefox? {:spend {:mean 3.0, :sum 9, :count 3}},
:chrome? nil,
:ie? nil,
:spent-at-all? {:spend {:mean 4.5, :sum 9, :count 2}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment