Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE: Add a poll results query #43

Merged
merged 1 commit into from Nov 23, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 28 additions & 0 deletions lib/queries.rb
Expand Up @@ -85,6 +85,11 @@ def self.default
"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

Expand Down Expand Up @@ -455,6 +460,29 @@ def self.default
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
Expand Down