Neat! I can't find anything in Clojure that does that, so I guess I'd have to use java.util.zip via Clojure ineterop. But making records and doing queries is easy:
> generate classes at runtime using the headers in each CSV
In Clojure:
(ns gtfs.core (:require [clojure.data.csv :as csv])) (defn load-records [f] (let [csv-data (csv/read-csv (slurp f))] (map zipmap (->> (first csv-data) ;; First row is the header (map keyword) repeat) (rest csv-data)))) (def agency-maps (load-records "data/agency.txt")) (def routes-maps (load-records "data/routes.txt")) ;; etc. (count routes-maps) ;; 30 (first routes-maps) ;; {: route_id "1-100", ;; :route_short_name "1", ;; :route_long_name "Ligne 1", ;; :route_desc "", ;; :route_type "3", ;; :route_url "", ;; :route_color "#B22E75"}
;; Query for long_name and route_color (def route_ln_color (map #(select-keys % [:route_long_name :route_color]) routes-maps)) (take 2 route_ln_color) ;; ({:route_long_name "Ligne 1", :route_color "#B22E75"} ;; {:route_long_name "Ligne 2", :route_color "#B22E75"})
Neat! I can't find anything in Clojure that does that, so I guess I'd have to use java.util.zip via Clojure ineterop. But making records and doing queries is easy:
> generate classes at runtime using the headers in each CSV
In Clojure:
> defines a 'select' function to make queries easy to write