          delays)
        (zip/next loc)))))
 
+(defn build-tree-from-source [id]
+  (let [origin (mc/find-map-by-id @db "origins" id)
+        tree (compute-impact-tree origin)]
+    {:title (:title (mc/find-map-by-id @db "articles" (:article origin)))
+     :tree tree
+     :analysis (analyze-tree tree)}))
 
 (defn random-tree []
   (let [origin (rand-nth (mc/find-maps @db "origins" {:source {$in news-accounts}}))

    (view (line-chart time tweet-count))
    (view (line-chart (range 24) avg-tweets-per-hour)))

  (let [days-running (t/in-days (t/interval (t/date-time 2014 7 2) (t/date-time 2014 9 12)))
        dates (take days-running (p/periodic-seq (t/date-time 2014 7 2) (t/days 1)))
        tweet-count (map #(mc/count @db "tweets" {:created_at {$gte % $lt (t/plus % (t/days 1))}}) dates)
        time (range days-running)]
    (view (line-chart time tweet-count)))

  (->> (mc/count @db "tweets" {:created_at {$gt (t/date-time 2014 9 18)}})
       aprint)




      (:_id x)
      (update-in x [:created_at] #(f/parse custom-formatter (:created_at %))) )))


  (def some-tree (build-tree-from-source (ObjectId. "53fcc425e4b09b711bdec9a9" )))

  ;; "53fcc425e4b09b711bdec9a9" "53fe02bbe4b09b711bdf26f2" "53f33d9ee4b0c2a12eb4a339" "53ff738fe4b09b711bdfa9c7"


  (def rand-tree (random-tree))

  (-> rand-tree :analysis :height)

  (-> rand-tree :analysis :size)

  (-> rand-tree :tree ffirst second :_id aprint)

  (-> rand-tree :analysis aprint)

  (def g
    (let [vertices (loop [nodes []
                          loc (:tree some-tree)]
                     (if (zip/end? loc)
                       nodes
                       (recur
                        (if-let [node (zip/node loc)]
                          (if (= (zip/root loc) node)
                            (conj nodes (-> node :tweet :id_str))
                            (conj nodes [(-> loc zip/up zip/node :tweet :id_str) (-> node :tweet :id_str)]))
                          nodes)
                        (zip/next loc))))]
      (apply lg/digraph vertices)))

  (lio/view g)

