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

round all floats to 2 decimals

parent 225f4d0f
Branches
Tags
No related merge requests found
......@@ -42,9 +42,9 @@
(api/read-check Field)
(f/fingerprint {:max-cost (max-cost max_query_cost
max_computation_cost)})
f/prettify))
f/x-ray))
(api/defendpoint GET "/table/:id/:max_query_cost/:max_computation_cost"
(api/defendpoint GET "/table/:id"
"Get fingerprint for a `Tield` with ID."
[id max_query_cost max_computation_cost]
{max_query_cost MaxQueryCost
......@@ -53,7 +53,7 @@
(api/read-check Table)
(f/fingerprint {:max-cost (max-cost max_query_cost
max_computation_cost)})
f/prettify))
f/x-ray))
(api/defendpoint GET "/segment/:id"
"Get fingerprint for a `Segment` with ID."
......@@ -64,7 +64,7 @@
(api/read-check Segment)
(f/fingerprint {:max-cost (max-cost max_query_cost
max_computation_cost)})
f/prettify))
f/x-ray))
(api/defendpoint GET "/card/:id"
"Get fingerprint for a `Card` with ID."
......@@ -75,7 +75,7 @@
(api/read-check Card)
(f/fingerprint {:max-cost (max-cost max_query_cost
max_computation_cost)})
f/prettify))
f/x-ray))
(api/defendpoint GET "/metric/:mid/field/:fid"
"Get fingerprint for `Metric` by Field."
......@@ -83,7 +83,7 @@
{max_query_cost MaxQueryCost
max_computation_cost MaxComputationCost
scale Scale}
(f/prettify
(f/x-ray
(f/multifield-fingerprint
{:max-cost (max-cost max_query_cost max_computation_cost)
:scale (or (keyword scale) :day)}
......@@ -101,7 +101,7 @@
(apply f/multifield-fingerprint
{:max-cost (max-cost max_query_cost max_computation_cost)
:scale (or (keyword scale) :day)})
f/prettify))
f/x-ray))
(api/defendpoint GET "/compare/fields/:id1/:id2"
"Get comparison fingerprints for `Field`s with ID1 and ID2."
......@@ -112,7 +112,7 @@
(map (partial api/read-check Field))
(apply f/compare-fingerprints
{:max-cost (max-cost max_query_cost max_computation_cost)})
f/prettify))
f/x-ray))
(api/defendpoint GET "/compare/tables/:id1/:id2"
"Get comparison fingerprints for `Table`s with ID1 and ID2."
......@@ -123,7 +123,7 @@
(map (partial api/read-check Table))
(apply f/compare-fingerprints
{:max-cost (max-cost max_query_cost max_computation_cost)})
f/prettify))
f/x-ray))
(api/defendpoint GET "/compare/cards/:id1/:id2"
"Get comparison fingerprints for `Card`s with ID1 and ID2."
......@@ -134,7 +134,7 @@
(map (partial api/read-check Card))
(apply f/compare-fingerprints
{:max-cost (max-cost max_query_cost max_computation_cost)})
f/prettify))
f/x-ray))
(api/defendpoint GET "/compare/segments/:id1/:id2"
"Get comparison fingerprints for `Segment`s with ID1 and ID2."
......@@ -145,14 +145,14 @@
(map (partial api/read-check Segment))
(apply f/compare-fingerprints
{:max-cost (max-cost max_query_cost max_computation_cost)})
f/prettify))
f/x-ray))
(api/defendpoint GET "/compare/segment/:sid/table/:tid"
"Compare `Segment` with `Table`."
[sid tid max_query_cost max_computation_cost]
{max_query_cost MaxQueryCost
max_computation_cost MaxComputationCost}
(f/prettify
(f/x-ray
(f/compare-fingerprints
{:max-cost (max-cost max_query_cost max_computation_cost)}
(api/read-check Segment sid)
......
(ns metabase.fingerprinting.core
"Fingerprinting (feature extraction) for various models."
(:require [metabase.db.metadata-queries :as metadata]
(:require [clojure.walk :refer [postwalk]]
[metabase.db.metadata-queries :as metadata]
[metabase.fingerprinting
[comparison :as comparison]
[costs :as costs]
......@@ -12,6 +13,7 @@
[metric :refer [Metric]]
[segment :refer [Segment]]
[table :refer [Table]]]
[metabase.util :as u]
[redux.core :as redux]))
(defn- fingerprint-field
......@@ -71,7 +73,8 @@
(merge (extract-query-opts opts)
(-> card :dataset_query :query)))
{:keys [breakout aggregation]} (group-by :source cols)
fields [(first breakout) (or (first aggregation) (second breakout))]]
fields [(first breakout)
(or (first aggregation) (second breakout))]]
{:constituents [(fingerprint-field opts (first fields) (map first rows))
(fingerprint-field opts (second fields) (map second rows))]
:fingerprint (merge (fingerprint-field opts fields rows)
......@@ -137,20 +140,29 @@
(comparison/fingerprint-distance a b))])
a b))}))
(defn- add-descriptions
(def ^:private ^{:arglists '([fingerprint])} add-descriptions
(partial m/map-kv (fn [k v]
(if (#{:field :type :table :card :segment} k)
[k v]
[k {:value v
:label k
:descripttion k}]))))
(defn- trim-decimals
[decimal-places fingerprint]
(postwalk
(fn [x]
(if (float? x)
(u/round-to-decimals (+ (- (min (long (f/order-of-magnitude x)) 0))
decimal-places)
x)
x))
fingerprint))
(defn x-ray
"Turn the fingerprint structure into an x-ray."
[fingerprint]
(into {}
(map (fn [[k v]]
(if (#{:field :type :table :card :segment} k)
[k v]
[k {:value v
:label k
:descripttion k}])))
fingerprint))
(defn prettify
"Walk the fingerprint structure and prettify all fingerprints within."
[fingerprint]
(-> fingerprint
(update :fingerprint (comp add-descriptions f/prettify))
(update :constituents (partial map (comp add-descriptions f/prettify)))))
(let [x-ray (comp add-descriptions (partial trim-decimals 2) f/x-ray)]
(-> fingerprint
(update :fingerprint x-ray)
(update :constituents (partial map x-ray)))))
......@@ -87,7 +87,8 @@
(let [scale (/ precision)]
(/ (floor (* x scale)) scale)))
(defn- order-of-magnitude
;;;;;;;; cast to long
(defn order-of-magnitude
[x]
(floor (/ (Math/log x) (Math/log 10))))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment