Skip to content

Instantly share code, notes, and snippets.

@kenrestivo
Created September 30, 2012 02:17
Show Gist options
  • Save kenrestivo/3805658 to your computer and use it in GitHub Desktop.
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
(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"))
@jacobrose
Copy link

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?).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment