FEATURE: Add a poll results query
This commit is contained in:
parent
f1d463ecb0
commit
3ea9a77b27
|
@ -85,6 +85,11 @@ class Queries
|
||||||
"id": -15,
|
"id": -15,
|
||||||
"name": "Total topics assigned per user",
|
"name": "Total topics assigned per user",
|
||||||
"description": "Count of assigned topis per user linking to assign list"
|
"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
|
}.with_indifferent_access
|
||||||
|
|
||||||
|
@ -455,6 +460,29 @@ class Queries
|
||||||
ORDER BY count(*) DESC, username_lower
|
ORDER BY count(*) DESC, username_lower
|
||||||
SQL
|
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.
|
# convert query ids from "mostcommonlikers" to "-1", "mostmessages" to "-2" etc.
|
||||||
queries.transform_keys!.with_index { |key, idx| "-#{idx + 1}" }
|
queries.transform_keys!.with_index { |key, idx| "-#{idx + 1}" }
|
||||||
queries
|
queries
|
||||||
|
|
Loading…
Reference in New Issue