          loc tree]
     (if (zip/end? loc)
       {:size size
+       :source (-> (zip/root tree) :source)
        :height max-path}
       (recur
        (if (zip/node loc) (inc size) size)

            [clj-time.periodic :as p]
            [clojure.pprint :refer [pprint]]
            [opennlp.nlp :refer [make-tokenizer make-detokenizer]]
            [incanter.stats :refer [mean variance quantile]]
            [loom.graph :as lg]
            [loom.io :as lio]
            [ceres.collector :refer [db custom-formatter news-accounts store]])

         (sort-by first >)
         time))

  (def all-delays
    (let [users (map :_id (mc/find-maps @db "users" {:screen_name {$in news-accounts}}))]
      (->> (mc/find-maps @db "publications" {:user {$in users}
                                             :ts {$lt (t/date-time 2014 9 1)}})
           (pmap (comp :delays analyze-delays full-reaction-tree :_id)))))

  (defn dispatch-types [type]
    (case type
      "source" 0
      "retweet" 1
      "reply" 2
      "share" 3
      4))

  (let [source-uids (map :_id (mc/find-maps @db "users" {:screen_name {$in news-accounts}}))
        graph (->> (mc/find-maps @db "publications" {:user {$in source-uids}})
             (pmap (comp summary reaction-tree :_id))
             (sort-by :size >)
             (take 3)
             last
             :source
             full-reaction-tree
             create-d3-graph)
        types (:types graph)
        cleaned-graph (update-in
                       (dissoc graph :types)
                       [:nodes]
                       #(mapv
                         (fn [k]
                           {:name k
                            :group (dispatch-types (get types k))})
                         %))]
    (with-open [w (clojure.java.io/writer "resources/graph-3b.edn")]
      (binding [*print-length* false
                *out* w]
        (pr cleaned-graph))))


  ;; find all related shares
  (let [origins (mc/find-maps @db "origins" {:source nil
                                             :ts {$gt (t/date-time 2014 8 1)
                                                  $lt (t/date-time 2014 9 1)}})]
    (->> origins
         (map (comp :in_reply_to_status_id #(mc/find-map-by-id @db "tweets" (:tweet %))))
         (take 10)
         aprint))


  (->> (mc/find-maps @db "publications" {:type :share})
       (pmap (comp #(mc/find-one-as-map @db "reactions" {:publication %}) :_id))
       (remove nil?)
       count
       aprint
       time)

  ((comp float /) (mc/count @db "reactions" {:source nil})
     (mc/count @db "reactions"))


  (mc/find-maps @db "origins" {:source nil
                               :ts {$gt (t/date-time 2014 8 1)
                                    $lt (t/date-time 2014 9 1)}})

)
