Created
September 30, 2012 02:17
-
-
Save kenrestivo/3805658 to your computer and use it in GitHub Desktop.
Formatting JLR's zombie table into JSON so that Flot can deal with it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require '[clojure.string :as s]) | |
;; install is a wrapper in utilza around pomegranate's add-dependencies | |
(install '[[cheshire "4.0.0"]]) | |
(use 'cheshire.core) | |
(defn get-lines [f] | |
(-> f | |
slurp | |
(s/split #"\n"))) | |
(defn make-series [d n] | |
(let [label (-> d (nth n) first)] | |
[label | |
{:label label | |
:data | |
(->> (zipmap (first d) (nth d n)) | |
(into (sorted-map)) | |
butlast)}])) | |
(defn parse [f] | |
(->> f | |
get-lines | |
(map #(s/split % #"\s+")) | |
(apply map vector))) ;; transpose | |
(defn jsonify [d] | |
(->> (map #(make-series d %) | |
(range 1 (count d))) | |
(into {}) | |
encode)) | |
(->> "/home/localkens/misctech/webdev/zombies/data.txt" | |
parse | |
jsonify | |
(spit "/home/localkens/misctech/webdev/zombies/data.json")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fun! How about infra- and inter-category comparison? See each "undead" vs. all others (zombies, vampires, and mummies) or see "undead" collectively vs. "monster" (dragons, dinosaurs, and aliens, maybe?).