Add a default query for showing the number of replies created by members of a given group (#34)
This commit is contained in:
parent
5f3bcab2f8
commit
c8ca1e1426
|
@ -62,17 +62,17 @@ class Queries
|
||||||
"active-lurkers": {
|
"active-lurkers": {
|
||||||
"id": -11,
|
"id": -11,
|
||||||
"name": "Most Active Lurkers",
|
"name": "Most Active Lurkers",
|
||||||
"description": "active users without posts and excessive read times, it accepts a post_read_count paramteter that sets the threshold for posts read."
|
"description": "active users without posts and excessive read times, it accepts a post_read_count parameter that sets the threshold for posts read."
|
||||||
},
|
},
|
||||||
"topic-user-notification-level": {
|
"topic-user-notification-level": {
|
||||||
"id": -12,
|
"id": -12,
|
||||||
"name": "List of topics a user is watching/tracking/muted",
|
"name": "List of topics a user is watching/tracking/muted",
|
||||||
"description": "The query requires a ‘notification_level’ parameter. Use 0 for muted, 1 for regular, 2 for tracked and 3 for watched topics."
|
"description": "The query requires a ‘notification_level’ parameter. Use 0 for muted, 1 for regular, 2 for tracked and 3 for watched topics."
|
||||||
},
|
},
|
||||||
"assigned-topics-report": {
|
"group-members-reply-count": {
|
||||||
"id": -13,
|
"id": -13,
|
||||||
"name": "List of assigned topics by user",
|
"name": "Group Members Reply Count",
|
||||||
"description": "This report requires the assign plugin, it will find all assigned topics"
|
"description": "Number of replies by members of a group over a given time period. Requires 'group_name', 'start_date', and 'end_date' parameters. Dates need to be in the form 'yyyy-mm-dd'. Accepts an 'include_pms' parameter."
|
||||||
}
|
}
|
||||||
}.with_indifferent_access
|
}.with_indifferent_access
|
||||||
|
|
||||||
|
@ -378,14 +378,47 @@ class Queries
|
||||||
ORDER BY tu.last_visited_at DESC
|
ORDER BY tu.last_visited_at DESC
|
||||||
SQL
|
SQL
|
||||||
|
|
||||||
queries["assigned-topics-report"]["sql"] = <<~SQL
|
queries["group-members-reply-count"]["sql"] = <<~SQL
|
||||||
SELECT value::int user_id, topic_id
|
-- [params]
|
||||||
FROM topic_custom_fields tf
|
-- date :start_date
|
||||||
JOIN topics t on t.id = topic_id
|
-- date :end_date
|
||||||
JOIN users u on u.id = value::int
|
-- string :group_name
|
||||||
WHERE tf.name = 'assigned_to_id'
|
-- boolean :include_pms = false
|
||||||
AND t.deleted_at IS NULL
|
|
||||||
ORDER BY username, topic_id
|
WITH target_users AS (
|
||||||
|
SELECT
|
||||||
|
u.id AS user_id
|
||||||
|
FROM users u
|
||||||
|
JOIN group_users gu
|
||||||
|
ON gu.user_id = u.id
|
||||||
|
JOIN groups g
|
||||||
|
ON g.id = gu.group_id
|
||||||
|
WHERE g.name = :group_name
|
||||||
|
AND gu.created_at::date <= :end_date
|
||||||
|
),
|
||||||
|
target_posts AS (
|
||||||
|
SELECT
|
||||||
|
p.id,
|
||||||
|
p.user_id
|
||||||
|
FROM posts p
|
||||||
|
JOIN topics t
|
||||||
|
ON t.id = p.topic_id
|
||||||
|
WHERE CASE WHEN :include_pms THEN true ELSE t.archetype = 'regular' END
|
||||||
|
AND t.deleted_at IS NULL
|
||||||
|
AND p.deleted_at IS NULL
|
||||||
|
AND p.created_at::date >= :start_date
|
||||||
|
AND p.created_at::date <= :end_date
|
||||||
|
AND p.post_number > 1
|
||||||
|
)
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
tu.user_id,
|
||||||
|
COALESCE(COUNT(tp.id), 0) AS reply_count
|
||||||
|
FROM target_users tu
|
||||||
|
LEFT OUTER JOIN target_posts tp
|
||||||
|
ON tp.user_id = tu.user_id
|
||||||
|
GROUP BY tu.user_id
|
||||||
|
ORDER BY reply_count DESC, tu.user_id
|
||||||
SQL
|
SQL
|
||||||
|
|
||||||
# convert query ids from "mostcommonlikers" to "-1", "mostmessages" to "-2" etc.
|
# convert query ids from "mostcommonlikers" to "-1", "mostmessages" to "-2" etc.
|
||||||
|
|
Loading…
Reference in New Issue