Miki Tebeka  committed 515ecc8

Start of plotting

  • Participants
  • Parent commits 8c28d17

Comments (0)

Files changed (1)

File src/clj2010.clj

 (ns clj2010
   (:require [apricot-soup :as soup])
-  (:use [clj-time.core :only (minutes date-time plus year month day)]
+  (:use [clj-time.core :only (date-time plus minutes year month day)]
+        [clj-time.coerce :only (to-long)]
+        [clj-time.format :only (formatter unparse)]
+        [incanter.core :only (view)]
+        [incanter.charts :only (bar-chart)]
         [clojure.contrib.string :only (trim lower-case split)])
     (map #(str root "/" %) files)))
 (defn load-data [root]
-  (flatten (map process-logfile (log-files root))))
+  (flatten (pmap process-logfile (log-files root))))
 (defn flatten1 
   "Flatten one level"
   (let [ks (keys map-result)]
     (zipmap ks (pmap #(reducer % (map-result %)) ks))))
-(defn map-reduce [job records]
-  (reduce-stage (:reduce job) (map-stage (:map job) records)))
+(defn map-reduce [mapper reducer records]
+  (reduce-stage reducer (map-stage mapper records)))
 (defn month-only [time]
   (date-time (year time) (month time)))
 (def numlogs {
     :map (fn [record] [[(month-only (:time record)) 1]])
-    :reduce (fn [key values] (reduce + values))})
+    :reduce (fn [key values] (reduce + values))
+    :title "# of logs by month"
+    :x-label "Month"
+    :y-label "Number of logs"
+    :x-format (fn [dt] (unparse (formatter "MMM") dt)) })
+(defn run-job [job records]
+  (let [result (map-reduce (:map job) (:reduce job) records)
+        xs (sort (keys result))
+        ys (map #(result %) xs)
+        fxs (map (:x-format job) xs)]
+    (bar-chart fxs ys :title (:title job) :x-label (:x-label job) 
+               :y-label (:y-label job))))
 (defn -main []
   (let [records (load-data "logs")]