-
-
Save mmower/d170188fcf88d8208ee8 to your computer and use it in GitHub Desktop.
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
(defn car-model | |
[year engine kind] | |
(str year "/" (format "%.1f" (float (read-string engine))) "/" (clojure.string/capitalize kind))) | |
(defn group-car-data-by-model | |
[car-data] | |
(reduce (fn [results row] | |
(let [[year reg engine mileage price kind] row | |
model (car-model year engine kind) | |
cars (get-in results [model] [])] | |
(assoc-in results [model] (conj cars {:mileage mileage | |
:price price})))) {} car-data)) | |
(defn get-grouped-car-data | |
[in-path] | |
(with-open [in-file (io/reader in-path)] | |
(group-car-data-by-model (csv/read-csv in-file)))) | |
(keys (get-grouped-car-data (project-path "mx5.csv"))) | |
; ("2011/1.8/Convertible" "2012/1.8/Convertible" "2008/2.0/Convertible" "2008/1.8/Coupe" "2009/1.8/Coupe" "2009/2.0/Convertible" "2006/1.8/Convertible" "2008/1.8/Convertible" "2009/1.8/Convertible" "2010/2.0/Coupe" "2011/2.0/Coupe" "2010/1.8/Coupe" "2010/2.0/Convertible" "2011/2.0/Convertible" "2011/1.8/Coupe" "2012/1.8/Coupe" "2008/2.0/Coupe" "2009/2.0/Coupe" "2010/1.8/Convertible") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment