Last active
December 28, 2015 05:59
-
-
Save yayitswei/7454198 to your computer and use it in GitHub Desktop.
find the change in a value over time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn find-case-insensitive | |
[db attr val] | |
(let [a (dq/qe-or-nil | |
'[:find ?account | |
:in $ ?pattern ?attr | |
:where | |
[?account ?attr ?name] | |
[(re-find ?pattern ?name)]] | |
db | |
(re-pattern (str "(?i)^" val "$")) attr)] | |
(when (account? a) a))) | |
(defn find-by-name | |
"Case-insensitive search for account name" | |
[db account-name] | |
(find-case-insensitive db :account/name (name account-name))) | |
(defn get-level [db name] | |
(-> (find-by-name db name) :account/level)) | |
(defn change-since [past-date db] | |
(- (or (get-level db :my-username) 0) | |
(or (get-level (d/as-of db past-date) :my-username) 0))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment