Skip to content
Snippets Groups Projects
Commit 582850d7 authored by Cam Saul's avatar Cam Saul
Browse files

Make sample data generation a separate lein task

parent 19e2fee7
No related branches found
No related tags found
No related merge requests found
......@@ -22,3 +22,4 @@ profiles.clj
/node_modules/
/.babel_cache
/coverage
/resources/sample-dataset-*
......@@ -5,7 +5,8 @@
:description "Metabase Community Edition"
:url "http://metabase.com/"
:min-lein-version "2.5.0"
:aliases {"test" ["with-profile" "+expectations" "expectations"]}
:aliases {"test" ["with-profile" "+expectations" "expectations"]
"generate-sample-dataset" ["with-profile" "+generate-sample-dataset" "run"]}
:dependencies [[org.clojure/clojure "1.7.0"]
[org.clojure/core.logic "0.8.10"]
[org.clojure/core.match "0.3.0-alpha4"] ; optimized pattern matching library for Clojure
......@@ -30,9 +31,7 @@
[com.novemberain/monger "3.0.0"] ; MongoDB Driver
[compojure "1.4.0"] ; HTTP Routing library built on Ring
[environ "1.0.0"] ; easy environment management
[faker "0.2.2"] ; Fake data generator -- port of Perl/Ruby
[hiccup "1.0.5"] ; HTML templating
[incanter/incanter-core "1.5.6"] ; Satistical functions like normal distibutions
[korma "0.4.2"] ; SQL lib
[log4j/log4j "1.2.17"
:exclusions [javax.mail/mail
......@@ -92,4 +91,9 @@
"-Dmb.api.key=test-api-key"
"-Xverify:none"]} ; disable bytecode verification when running tests so they start slightly faster
:uberjar {:aot :all
:prep-tasks ^:replace ["npm" "webpack" "javac" "compile"]}})
:prep-tasks ^:replace ["npm" "webpack" "generate-sample-dataset" "javac" "compile"]}
:generate-sample-dataset {:dependencies [[faker "0.2.2"] ; Fake data generator -- port of Perl/Ruby
[incanter/incanter-core "1.5.6"]] ; Satistical functions like normal distibutions}})
:source-paths ["sample_dataset"]
:global-vars {*warn-on-reflection* false}
:main ^:skip-aot metabase.sample-dataset.generate}})
(ns metabase.sample-data.generate
(ns metabase.sample-dataset.generate
(:require [clojure.math.numeric-tower :as math]
[clojure.string :as s]
(faker [address :as address]
......@@ -11,6 +11,11 @@
[db :as kdb]))
(:import java.util.Date))
(def ^:private ^:const sample-dataset-version "1.0.0")
(def ^:private ^:const sample-dataset-filename
(str (System/getProperty "user.dir") (format "/resources/sample-dataset-%s.db" sample-dataset-version)))
(defn- normal-distribution-rand [mean median]
(dist/draw (dist/normal-distribution mean median)))
......@@ -345,7 +350,7 @@
;; Insert the data
(println "Inserting data...")
(metabase.util/pdoseq [[table rows] (seq data)]
(doseq [[table rows] (seq data)]
(assert (keyword? table))
(assert (sequential? rows))
(let [entity (-> (k/create-entity (s/upper-case (name table)))
......@@ -362,3 +367,8 @@
(k/exec-raw db (format "GRANT SELECT ON %s TO GUEST;" (s/upper-case (name table)))))
(println "Done."))))
(defn -main [& [filename]]
(let [filename (or filename sample-dataset-filename)]
(println (format "Writing sample dataset to %s..." filename))
(create-h2-db filename)))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment