Guest User

Untitled

a guest
Dec 11th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. (def vote-results-query
  2. '[$votes
  3. [:find ?issue, ?proposal-name, (count ?vote) :as vote-count
  4. :in $ ?issue
  5. :where
  6. [?ballot :ballot/issue ?issue]
  7. ;; Bind the proposal
  8. [?proposal :proposal/name ?proposal-name]
  9. ;; Count only votes for this Ballot
  10. [?vote :voter/ballot ?ballot]
  11. ;; Bind the votes for this proposal
  12. [?vote :voter/vote-on-proposal ?proposal]]
  13.  
  14. $most-voted
  15. [:find (max ?vote-count) :as winning-vote-count .
  16. ;-- this statement:
  17. :within $votes
  18. ;-- gets rewritten as:
  19. :in [[?issue ?proposal-name ?vote-count]]]
  20. ;--
  21.  
  22. $winners
  23. [:find ?proposal-name ?proposal-votes
  24. ;-- this statement:
  25. :within $votes $most-voted
  26. ;-- gets rewritten as:
  27. :in [[?issue ?proposal-name ?vote-count]] ?winning-vote-count
  28. ;--
  29. :where [(= ?winning-vote-count ?proposal-votes)]]])
Add Comment
Please, Sign In to add comment