Created
October 22, 2015 19:13
-
-
Save gphilipp/fe3684bdb31ff2101485 to your computer and use it in GitHub Desktop.
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
(require '[datomic.api :as d]) | |
(def dburi "datomic:dev://localhost:4334/koturo") | |
;; failed projects | |
(map first (d/q '[:find (pull ?p [*]) | |
:where | |
[?p :project/closed true] | |
[?p :project/successful false] | |
] | |
(d/db (d/connect dburi)))) | |
;; failed projects | |
(map first (d/q '[:find (pull ?p [:project/name :project/successful :project/closed | |
:project/fixed-rate :project/average-rate]) | |
:where | |
(or (and [?p :project/fixed-rate ?rate] | |
[(>= ?rate 8.0)]) | |
(and [?p :project/average-rate ?rate] | |
[(>= ?rate 8.0)])) | |
] | |
(d/db (d/connect dburi)))) | |
(map first (d/q '[:find (pull ?p [*]) | |
:where | |
[?p :project/url ?url] | |
(or [?p :project/fixed-rate ?rate] | |
[?p :project/average-rate ?rate]) | |
[(>= ?rate 9.5)] | |
] | |
(d/db (d/connect dburi)))) | |
(d/q '[:find | |
?platform ?terms (avg ?rate) | |
:with ?p | |
:where | |
[?p :project/successful true] | |
[?p :project/terms ?terms] | |
[?p :project/platform ?platform] | |
(or [?p :project/fixed-rate ?rate] | |
[?p :project/average-rate ?rate]) | |
] | |
(d/db (d/connect dburi))) | |
(d/q '[:find | |
?platform ?terms (avg ?rate) | |
:with ?p | |
:where | |
[?p :project/successful true] | |
[?p :project/end-date ?end-date] | |
;(> ?end-date #inst "2015-10-01") | |
[?p :project/terms ?terms] | |
[?p :project/platform ?platform] | |
(or [?p :project/fixed-rate ?rate] | |
[?p :project/average-rate ?rate]) | |
] | |
(d/db (d/connect dburi))) | |
(d/q '[:find | |
(avg ?rate) | |
:with ?p | |
:where | |
[?p :project/successful true] | |
[?p :project/terms 48] | |
[?p :project/platform ?platform] | |
(or [?p :project/fixed-rate ?rate] | |
[?p :project/average-rate ?rate]) | |
] | |
(d/db (d/connect dburi))) | |
(defn funded-projects-sorted-by-end-date [terms] | |
(->> (d/q '[:find (pull ?p [*]) | |
:in $ ?terms | |
:where | |
[?p :project/successful true] | |
[?p :project/terms ?terms]] | |
(d/db (d/connect dburi)) | |
terms) | |
(map first) | |
(sort-by :project/end-date) | |
reverse)) | |
(defn average-rates-on-10-last [] | |
(let [last-projects (take 10 (funded-projects-sorted-by-end-date 48)) | |
sum-of-target-amounts (reduce + (map :project/target-amount last-projects))] | |
(->> (map #(let [{:keys [project/fixed-rate | |
project/average-rate | |
project/target-amount | |
]} % | |
rate (or fixed-rate average-rate)] | |
(/ (* target-amount rate) sum-of-target-amounts)) | |
last-projects) | |
(reduce +)))) | |
(comment | |
(funded-projects-sorted-by-end-date 48) | |
(average-rates-on-10-last) | |
) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment