Guest User

Untitled

a guest
Feb 9th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. (ns akvo.lumen.admin.stats.example
  2. (:require [cheshire.core :as json]
  3. [clojure.pprint :refer [pprint]]))
  4.  
  5. (comment
  6.  
  7. ;; # 1 Get list of tenants on form "tenant1,tenant2,..."
  8. ;; $ docker exec -i -t akvolumen_backend_1 env ENCRYPTION_KEY=... KC_URL=... KC_SECRET=<SECRET> PG_HOST=... PG_DATABASE=... PG_USER=... PG_PASSWORD=... lein run -m akvo.lumen.admin.stats.run-manager-query "SELECT label from tenants;" > tenants.edn
  9.  
  10. ;; Now massage the contents of tenants.edn Replace " with \" and put the list
  11. ;; of comma separated tenants in a string ("tenants1,tenant2")
  12. ;;
  13. ;; Make sure the list includes only tenants you want to include
  14.  
  15. (def all-tenants (json/decode "[{\"label\":\"daniel\"},{\"label\":\"demo\"}]"))
  16. (def set-of-non-production-tenants #{"daniel" "nadia" "gabe"})
  17.  
  18. (def tenants (json/encode
  19. (reduce (fn [m {:strs [label]}]
  20. (if-not (contains? set-of-non-production-tenants label)
  21. (conj m label)
  22. m))
  23. []
  24. all-tenants)))
  25.  
  26. (prn (count tenants))
  27.  
  28. ;; # 2 Get dataset data
  29. ;; $ docker exec -i -t akvolumen_backend_1 env ENCRYPTION_KEY=... KC_URL=... KC_SECRET=<SECRET> PG_HOST=... PG_DATABASE=... PG_USER=... PG_PASSWORD=... lein run -m akvo.lumen.admin.stats.run-query "demo,tenant1,..." "SELECT count(id) from dataset" > datasets.edn
  30.  
  31. ;; # 3 Get dashboard data
  32. ;; $ docker exec -i -t akvolumen_backend_1 env ENCRYPTION_KEY=... KC_URL=... KC_SECRET=<SECRET> PG_HOST=... PG_DATABASE=... PG_USER=... PG_PASSWORD=... lein run -m akvo.lumen.admin.stats.run-query "demo,tenant1,..." "SELECT count(id) from dashboard" > dashboard.edn
  33.  
  34. ;; # 4 Sum up data in scratch
  35. ;; Replace " with \" and put it all in "" to get json, which we then decode.
  36.  
  37. (require '[cheshire.core :as json])
  38.  
  39. (def datasets (json/decode "[[\"tenant1\",[{\"count\":2}]],[\"demo\",[{\"count\":91}]]]"))
  40.  
  41. (println "datasets")
  42. (prn (reduce (fn [m [_ [{:strs [count]}]]]
  43. (+ m count))
  44. 0
  45. datasets))
  46.  
  47. (def dashboards (json/decode "[[\"tenant1\",[{\"count\":9}]],[\"demo\",[{\"count\":27}]]]"))
  48. (prn (reduce (fn [m [_ [{:strs [count]}]]]
  49. (+ m count))
  50. 0
  51. dashboards))
  52.  
  53. )
Add Comment
Please, Sign In to add comment