Skip to content

Instantly share code, notes, and snippets.

@quaat
Created June 16, 2013 19:48
Show Gist options
  • Save quaat/5793173 to your computer and use it in GitHub Desktop.
Save quaat/5793173 to your computer and use it in GitHub Desktop.
(ns offset.core
(:use (incanter core stats charts datasets))
(:use [clojure.math.combinatorics])
(:require [clojure.string :as cstr]
[clojure.data.csv :as csv]
[clojure.java.io :as io]))
(defn- to-dec [t]
(if (= 1 (count t))
(first t)
(let [v (+ (Math/abs (first t)) (second t))]
(if (neg? (first t))
(- v)
v))))
(def inch-to-cm 2.54)
(defn- round [x p]
(let [scale (Math/pow 10 p)]
(-> x (* scale) Math/round (/ scale))))
(defn- inch-str-to-cm [x]
(cond
(nil? x) nil
(empty? (cstr/trim x)) nil
:else (round(->>
(cstr/split (str x) #"\s+")
(map read-string)
to-dec
(* inch-to-cm)) 1)))
(defn store-csv [filename, data]
(with-open [out-file (io/writer filename)]
(csv/write-csv out-file data)))
(defn read-csv [filename]
(with-open [in-file (io/reader filename)]
(map (fn [xs] (map #(cstr/trim %) xs))
(doall
(csv/read-csv in-file)))))
(defn convert-data [header data]
(dataset header (map (fn [xs](map #(inch-str-to-cm %) xs)) data)))
(def bow (convert-data ["pos" "r-perim" "c-perim" "thigh-brace"] (read-csv "bow.csv")))
(def cockpit (convert-data ["pos" "r-perim" "c-perim" "thigh-brace"] (read-csv "cockpit.csv")))
(def recess-back (convert-data ["pos", "inside", "outside"] (read-csv "back.csv")))
(def stern (convert-data (read-csv "stern.csv")))
(view (scatter-plot ($ :length bow) ($ :stem bow)))
(view (scatter-plot ($ :length bow) ($ :edge bow)))
(view cockpit)
(view (scatter-plot ($ :pos cockpit) ($ :r-perim cockpit)))
(view (scatter-plot ($ :pos cockpit) ($ :c-perim cockpit)))
(view (scatter-plot ($ :pos cockpit) ($ :thigh-brace cockpit)))
(def m-cockpit (conj-cols (conj-cols (sel cockpit :except-cols :pos) (map #(round (+ % 41.6) 1) ($ :pos cockpit))) (range 1 100)))
(view m-cockpit)
(view recess-back)
(view (scatter-plot ($ :pos recess-back) ($ :inside recess-back)))
(view (scatter-plot ($ :pos recess-back) ($ :outside recess-back)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment