Skip to content
Snippets Groups Projects
Commit 3f9f16d9 authored by Simon Belak's avatar Simon Belak
Browse files

Add YAML frontend

parent 85a5ab23
No related branches found
No related tags found
No related merge requests found
......@@ -63,6 +63,9 @@
[hiccup "1.0.5"] ; HTML templating
[honeysql "0.8.2"] ; Transform Clojure data structures to SQL
[io.crate/crate-jdbc "2.1.6"] ; Crate JDBC driver
[io.forward/yaml "1.0.6" ; Clojure wrapper for SnakeYAML
:exclusions [org.clojure/clojure
org.yaml/snakeyaml]]
[kixi/stats "0.3.10" ; Various statistic measures implemented as transducers
:exclusions [org.clojure/test.check ; test.check and AVL trees are used in kixi.stats.random. Remove exlusion if using.
org.clojure/data.avl]]
......
bindings:
fields:
- named:
- [total, 1.0]
- [amount, 0.9]
- [income, 1.0]
- [price, 0.6]
type: Number
as: income
table: ?orders
- named:
- [created_at, 1.0]
- [timestamp, 1.0]
- [date, 0.8]
type: DateTime
as: timestamp
table: ?orders
- named:
- [user, 1.0]
- [account, 0.9]
- [customer, 0.9]
- [email, 0.3]
type:
- [FK, 1.0]
- [String, 0.8]
- [Integer, 0.4]
as: user
table: ?orders
tables:
- named:
- [orders, 1.0]
- [transactions, 1.0]
- [sales, 1.0]
- [products, 0.0]
as: orders
cards:
- dashboard: Orders autogenerated
visualization: line
title: Income by month
description: Total income by month
query:
source_table: "?orders"
breakout: [datetime-field, [field-id, "?timestamp"], month]
aggregation: [sum, [field-id, "?income"]]
- dashboard: Orders autogenerated
visualization: line
title: Unique users by month
description: How many unique users have placed and order in a given month
query:
source_table: "?orders"
breakout: [datetime-field, [field-id, "?timestamp"], month]
aggregation: [distinct, [field-id, "?user"]]
......@@ -15,41 +15,8 @@
[table :refer [Table]]]
[toucan
[db :as db]
[hydrate :refer [hydrate]]]))
(def rules
[{:bindings {:fields [{:named [["total" 1.0] ["amount" 0.9] ["income" 1.0] ["price" 0.6]]
:type :type/Number
:as "income"
:table "?orders"}
{:named [["created_at" 1.0] ["timestamp" 1.0] ["date" 0.8]]
:type :type/DateTime
:as "timestamp"
:table "?orders"}
{:named [["user" 1.0] ["account" 0.9] ["customer" 0.9]
["email" 0.3]]
:type [[:type/FK 1.0]
[:type/String 0.8]
[:type/Integer 0.4]]
:as "user"
:table "?orders"}]
:tables [{:named [["orders" 1.0] ["transactions" 1.0] ["sales" 1.0]
["products" 0.0]]
:as "orders"}]}
:cards [{:dashboard "orders autogenerated"
:visualization :line
:title "Income by month"
:description ""
:query {:source_table "?orders"
:breakout [[:datetime-field [:field-id "?timestamp"] :month]]
:aggregation [:sum [:field-id "?income"]]}}
{:dashboard "orders autogenerated"
:visualization :line
:title "Unique users by month"
:description ""
:query {:source_table "?orders"
:breakout [[:datetime-field [:field-id "?timestamp"] :month]]
:aggregation [:distinct [:field-id "?user"]]}}]}])
[hydrate :refer [hydrate]]]
[yaml.core :as yaml]))
(defn- boolean->probability
[x]
......@@ -82,8 +49,9 @@
(defn- type-is?
[t {:keys [base_type special_type]}]
(or (isa? base_type t)
(isa? special_type t)))
(let [t (keyword "type" t)]
(or (isa? base_type t)
(isa? special_type t))))
(defmulti constraint
^{:doc ""
......@@ -228,9 +196,20 @@
(hydrate card :creator :dashboard_count :labels :can_write :collection)
(add-to-dashboard! dashboard card)))))
(def ^:private rules-dir "resources/automagic_dashboards")
(defn- load-rules
[]
(->> rules-dir
clojure.java.io/file
file-seq
(filter #(.isFile %))
; Workaround for https://github.com/owainlewis/yaml/issues/11
(map (comp yaml/parse-string slurp))))
(defn populate-dashboards
[database]
(->> rules
(->> (load-rules)
(mapcat (fn [{:keys [bindings cards]}]
(let [[tables fields] (bind-models database bindings)]
(keep (fn [card]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment