-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore.clj
55 lines (46 loc) · 1.71 KB
/
core.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
52
53
(ns sync-file-generator.core
(:require [sync-file-generator.name-data :as data :refer [rand-element rand-element-weighted]]
[clojure.java.io :as io])
(:import (java.util UUID)))
(def default-columns [:id :first :last :title :site :dept :email :active :policy-tech-active])
(def header-labels
{:id "CustomID"
:first "First Name"
:last "Last Name"
:title "Title"
:site "Site"
:dept "Dept"
:email "Email"
:active "Active"
:policy-tech-active "PolicyTech Active"})
(defn random-record []
(let [first-name (rand-element data/first-names)
last-name (rand-element data/last-names)
email (str first-name "." last-name "@foo.test")]
{:id (str (UUID/randomUUID))
:first first-name
:last last-name
:title (rand-element-weighted data/titles)
:site (rand-element-weighted data/sites)
:dept (rand-element-weighted data/depts)
:email email
:active "y"
:policy-tech-active "y"}))
(defn convert-to-tsv [columns record]
(let [values (mapv record columns)]
(clojure.string/join "\t" values)))
(def random-records (repeatedly random-record))
(defn flat-file-records [n]
(concat [header-labels]
(take n random-records)))
(defn create-sync-file
([file-path]
(create-sync-file 20 file-path))
([line-count file-path]
(create-sync-file default-columns line-count file-path))
([columns line-count file-path]
(let [lines (map (partial convert-to-tsv columns) (flat-file-records line-count))]
(with-open [wrtr (io/writer file-path)]
(binding [*out* wrtr]
(doseq [line lines]
(println line)))))))