-
Notifications
You must be signed in to change notification settings - Fork 15
/
meta_data.clj
51 lines (47 loc) · 1.94 KB
/
meta_data.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
(ns io.meta-data
(:require
[clojure.data.csv :as csv]
[clojure.tools.cli :refer [parse-opts]]
[clojure.java.io :as io]
[utils.core :refer [hash-by csv-data->maps output-file-type]]))
; ==================================
; Command Line Options
; ==================================
(def options [["-t" "--type TYPE" "File Type (json or edn)"
:default :edn
:parse-fn keyword
:validate [#(or (= % :edn) (= % :json)) "Must be json or edn"]]])
(def args (-> *command-line-args* (parse-opts options)))
(def file-type (-> args :options :type))
(def errors (-> args :errors))
; ==================================
; IO
; ==================================
(let [path "data/meta/"
meta ["event.csv" "position.csv" "schemes.csv" "tags.csv"]
get-file (fn [f] (-> f
(#(io/resource (str path %)))
slurp
csv/read-csv
csv-data->maps))
reduce-by (fn [prop v] (reduce (partial hash-by prop) (sorted-map) v))
data (-> (map get-file meta))]
(if (-> errors some? not)
(let [[event position schemes tags] data
format-data
{:sub-events (->> event
(map (fn [v] (assoc v
:event (-> v :event Integer.)
:sub-event (-> v :sub-event Integer.))))
(reduce-by :sub-event))
:position (->> position (reduce-by :code))
:schemes (->> schemes (reduce-by :scheme))
:tags (->> tags
(map (fn [v] (assoc v
:tag (-> v :tag Integer.))))
(reduce-by :tag))}]
(-> format-data
(#(spit
(str "src/main/data/meta/meta" "." (name file-type))
((output-file-type file-type) %)))))
(print errors)))