This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Add charting.

  • Loading branch information...
technomancy committed Jan 25, 2012
1 parent 7635d87 commit 128c01c8bc7dbb42bc41662e17edb6f7db570fb2
Showing with 61 additions and 2 deletions.
  1. +1 −1 project.clj
  2. +60 −1 src/lein_survey/results.clj
View
@@ -1,7 +1,7 @@
(defproject lein-survey "1.0.0-SNAPSHOT"
:description "Survey for Leiningen users"
:dependencies [[clojure "1.3.0"]
- [compojure "1.0.1"]
+ [incanter/incanter-charts "1.2.4"]
[org.clojure/java.jdbc "0.1.1"]
[postgresql "8.4-702.jdbc4"]
[hiccup "0.3.8"]
@@ -1,6 +1,9 @@
(ns lein-survey.results
(:require [clojure.java.jdbc :as sql]
[clojure.pprint :as pprint]
+ [clojure.string :as string]
+ [incanter.core :as incanter]
+ [incanter.charts :as charts]
[lein-survey.questions :as q]))
(defn setize [x]
@@ -61,4 +64,60 @@
(defn summary []
(let [results (get-results)]
(into [:div.summary]
- (map (partial summarize-question results) q/questions))))
+ (map (partial summarize-question results) q/questions))))
+
+(def os-map {"Debian/Ubuntu" :linux
+ "Fedora/other RPM-based" :linux
+ "Arch" :linux
+ "Gentoo" :linux
+ ;; "Nix" :other
+ "Other GNU/Linux" :linux
+ "Mac OS X with Homebrew" :mac
+ "Mac OS X with Macports" :mac
+ "Mac OS X with Fink" :mac
+ "Mac OS X with no package manager" :mac
+ "Windows with Powershell" :windows
+ "Windows without Powershell" :windows
+ "Windows with Cygwin" :windows
+ ;; "Solaris" :other
+ ;; "BSD" :other
+ ;; "other" :other
+ })
+
+(defn os-lookup [q result]
+ (let [q-result (get result q)
+ result-set (if (coll? q-result)
+ (set q-result)
+ (hash-set q-result))]
+ (set (for [[name type] os-map
+ :when (result-set name)]
+ type))))
+
+(def pie-overrides {"Your OS and package manager(s)" os-lookup})
+
+(defn pie
+ ([q results] (pie q results (pie-overrides q (fn [q result] (get result q)))))
+ ([q results lookup]
+ (let [freqs (dissoc (frequencies (map (partial lookup q) results))
+ nil "I don't remember" #{})
+ freqs (sort-by (comp str key) freqs)]
+ (charts/pie-chart (map str (keys freqs)) (vals freqs)
+ :title q :legend true))))
+
+(defn bar
+ ([q results] (bar q results (fn [q result] (get result q))))
+ ([q results lookup]
+ (let [q-results (map (partial lookup q) results)
+ q-results-spread (apply concat (for [r q-results]
+ (if (coll? r) r [r])))
+ freqs (dissoc (frequencies q-results-spread)
+ nil "I don't remember" #{} [] "")
+ freqs (sort-by (comp str key) freqs)
+ ;; TODO: make threshhold customizable?
+ freqs (filter (fn [[x n]] (> n 3)) freqs)
+ ]
+ (charts/bar-chart (map str (keys freqs)) (vals freqs)
+ :title "Favourite Plugins" :vertical false))))
+
+;; (incanter/view (bar "Favourite plugins? (comma-separated)" (get-results)
+;; (fn [q result] (vec (.split (get result q) ", *")))))

0 comments on commit 128c01c

Please sign in to comment.