diff --git a/lib/queries.rb b/lib/queries.rb index ad5ad34..584be9d 100644 --- a/lib/queries.rb +++ b/lib/queries.rb @@ -85,6 +85,11 @@ class Queries "id": -15, "name": "Total topics assigned per user", "description": "Count of assigned topis per user linking to assign list" + }, + "poll-results": { + "id": -16, + "name": "Poll results report", + "description": "Details of a poll result, including details about each vote and voter, useful for analyzing results in external software." } }.with_indifferent_access @@ -455,6 +460,29 @@ class Queries ORDER BY count(*) DESC, username_lower SQL + queries["poll-results"]["sql"] = <<~SQL + -- [params] + -- string :poll_name + -- int :post_id + + SELECT + poll_votes.updated_at AS vote_time, + poll_votes.poll_option_id AS vote_option, + users.id AS user_id, + users.username, + users.name, + users.trust_level + FROM + poll_votes + INNER JOIN + polls ON polls.id = poll_votes.poll_id + INNER JOIN + users ON users.id = poll_votes.user_id + WHERE + polls.name = :poll_name AND + polls.post_id = :post_id + SQL + # convert query ids from "mostcommonlikers" to "-1", "mostmessages" to "-2" etc. queries.transform_keys!.with_index { |key, idx| "-#{idx + 1}" } queries