     {:graph (simplify-tree tree)
      :height (tree-height tree)
      :size (compute-dfs tree)}))
+
+
+(defn analyze-tree [tree]
+  (loop [counter 0
+         max-path 0
+         users []
+         hashtags []
+         delays []
+         loc tree]
+    (if (zip/end? loc)
+      {:size counter
+       :height max-path
+       :users users
+       :hashtags (vec (into #{} (map :text hashtags)))
+       :delays delays}
+      (recur
+       (if (zip/node loc)
+         (inc counter)
+         counter)
+       (if (zip/node loc)
+         (-> loc zip/path count (max max-path))
+         max-path)
+       (if-let [node (zip/node loc)]
+         (let [user (-> node :tweet :user)]
+             (conj users (-> {:name (:screen_name user) :followers (:followers_count user)})))
+         users)
+       (if-let [node (zip/node loc)]
+         (->> node :tweet :entities :hashtags (into hashtags))
+         hashtags)
+       (if (zip/node loc)
+         (let [pub-time (-> (zip/root tree) :source :ts)
+               post-delay (if (t/after? (-> loc zip/node :tweet :created_at) pub-time)
+                            (t/interval pub-time (-> loc zip/node :tweet :created_at))
+                            (t/interval (-> loc zip/node :tweet :created_at) pub-time))]
+           (conj delays (t/in-hours post-delay)))
+         delays)
+       (zip/next loc)))))
+
+
+(defn compute-summary [source]
+  (let [impact-forest (compute-impact-forest source)
+        analytics (map analyze-tree impact-forest)
+        sizes (map :size analytics)
+        heights (map :height analytics)
+        users (frequencies (flatten (map :users analytics)))
+        hashtags (frequencies (flatten (map :hashtags analytics)))
+        overall-size (reduce + sizes)]
+    {:source source
+     :articles (count impact-forest)
+     :top-users (take 50 (sort-by second > users))
+     :hastags (take 50 (sort-by second > hashtags))
+     :total-impact overall-size
+     :avg-impact (float (/ overall-size (count sizes)))
+     :no-reactions (float (/ (count (filter #(< % 1) heights)) (count heights)))
+     :avg-height (float (/ (reduce + heights) (count heights)))}))
 
 
 ;; --- MONGO DATA EXPORT/IMPORT ---

         max-path)
       (zip/next loc)))))


(defn example-tree []
  (let [tree (compute-impact-tree (mc/find-map-by-id db "origins" (ObjectId. "53de1541657a439ad20d6859")))] ; alternativ "53de3d68657a74caed255892" "53d7a7ad657ad4126658d0ba" "53de089f657a439ad20d6133"
    {:graph (simplify-tree tree)
     :height (tree-height tree)
     :size (compute-dfs tree)}))

            [clj-time.core :as t]
            [clj-time.format :as f]
            [clj-time.coerce :as c]
            [clojure.pprint :refer [pprint]]
            [clojure.java.shell :refer [sh]]
            [opennlp.nlp :refer [make-tokenizer make-detokenizer]]
            [ceres.collector :refer [db custom-formatter news-accounts store]])
