Last active
December 23, 2015 22:29
-
-
Save aamedina/6703237 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 usd | |
| [n] | |
| (/ n 1e6)) | |
| (defn avg-daily-budget | |
| [campaigns] | |
| (->> (project campaigns [:daily-budget-amount-local-micro]) | |
| (map vals) | |
| (map first) | |
| (reduce +) | |
| (#(/ % (count campaigns))) | |
| usd)) | |
| (defn all-avg-daily-budgets | |
| [accounts] | |
| (->> @accounts | |
| (map (fn [acct] (fetch! (campaign (account :for acct))))) | |
| (map (fn [campaign-promise] | |
| (let [budget-promise (promise)] | |
| (if (realized? campaign-promise) | |
| (deliver budget-promise (avg-daily-budget @campaign-promise)) | |
| (go (deliver budget-promise | |
| (avg-daily-budget (<! @campaign-promise))))) | |
| budget-promise))))) | |
| (def accounts (account)) | |
| (fetch! accounts) | |
| (def budgets (all-avg-daily-budgets accounts)) | |
| (println budgets) | |
| (#<Promise: 970.5888235294118> #<Promise: 312.000449995> #<Promise: 534.84559523809\ | |
| 53> #<Promise: 6110.439461538462> #<Promise: 479.1666666666667> #<Promise: NaN> #<P\ | |
| romise: 283.68333333333334> #<Promise: 431.13014598540144> #<Promise: 3135.86> #<Pr\ | |
| omise: 110.55555555555556> #<Promise: 9741.30605> #<Promise: 782.5121951219512> #<P\ | |
| romise: 1801.639888888889> #<Promise: 950> #<Promise: 47.285714285714285> #<Promise\ | |
| : 753.3> #<Promise: 421.3793103448276> #<Promise: 782.9351851851852> #<Promise: 288\ | |
| 7.8846153846152> #<Promise: 77.45> #<Promise: 2.1916666666666664> #<Promise: 1996> \ | |
| #<Promise: 32.611111111111114> #<Promise: 5762.411764705882> #<Promise: 294.375> #<\ | |
| Promise: 1544.535> #<Promise: 219.9> #<Promise: 21.717391304347824> #<Promise: 18.8\ | |
| 8888888888889> #<Promise: 142.92592592592595> #<Promise: 706.117397260274> #<Promis\ | |
| e: 813.2352941176471> #<Promise: 4620.372881355932> #<Promise: 71.25> #<Promise: 0>\ | |
| #<Promise: 657.820749995> #<Promise: 47.611111111111114> #<Promise: 40.75050504040\ | |
| 404>) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment