mirror of
https://github.com/discourse/discourse-rewind.git
synced 2025-12-12 18:33:30 +00:00
## Summary Adds seven new metrics to the Discourse Rewind plugin, significantly expanding the types of insights users can get about their annual activity. These new reports cover temporal patterns, community engagement, plugin integrations, and content analysis. ## New Reports ### 1. Time of Day Activity (`time-of-day-activity`) - Analyzes user activity by hour in their timezone - Determines personality type: "early bird" (6-9am), "night owl" (10pm-2am), or "balanced" - Aggregates posts, chat messages, and page views ### 2. New User Interactions (`new-user-interactions`) - Tracks veteran mentorship and community building behavior - Measures likes, replies, and mentions to users who joined this year - Shows unique new users interacted with and total engagement ### 3. Chat Usage (`chat-usage`) - Total messages and average message length - Top 5 favorite channels with message counts - DM statistics (message count, unique conversations) - Reactions received on messages ### 4. AI Usage (`ai-usage`) - Integrates with `discourse-ai` plugin - Total requests, tokens consumed (request/response breakdown) - Top 5 most used features and AI models - Success rate calculation ### 5. Favorite GIFs (`favorite-gifs`) - Extracts GIFs from posts and chat messages - Ranks by engagement score (usage × 10 + likes + reactions) - Supports Giphy, Tenor, and direct GIF URLs - Shows top 5 GIFs with usage statistics ### 6. Assignments (`assignments`) - Integrates with `discourse-assign` plugin - Tracks assignments received and given - Shows completion rate and pending assignments ### 7. Invites (`invites`) - Total invites sent and redemption rate - Impact metrics: invitee posts, topics, and likes created - Most active invitee identification - Average trust level of invitees ## Technical Details - All reports extend `BaseReport` class - Include proper enablement checks for plugin dependencies - Use efficient database queries with proper joins and aggregations - Return `nil` when no relevant data exists Co-authored-by: Martin Brennan <mjrbrennan@gmail.com>
63 lines
1.8 KiB
Ruby
63 lines
1.8 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
# Assignment statistics using discourse-assign plugin data
|
|
# Shows how many assignments, completed, pending, etc.
|
|
module DiscourseRewind
|
|
module Action
|
|
class Assignments < BaseReport
|
|
def call
|
|
return if !enabled?
|
|
|
|
# Assignments made to the user
|
|
assignments_scope =
|
|
Assignment
|
|
.where(assigned_to_id: user.id, assigned_to_type: "User")
|
|
.where(created_at: date)
|
|
|
|
total_assigned = assignments_scope.count
|
|
|
|
# Completed assignments (topics that were assigned and then closed or unassigned)
|
|
completed_count =
|
|
assignments_scope
|
|
.joins(:topic)
|
|
.where(
|
|
"topics.closed = true OR assignments.active = false OR assignments.updated_at > assignments.created_at",
|
|
)
|
|
.distinct
|
|
.count
|
|
|
|
# Currently pending (still open and assigned)
|
|
pending_count =
|
|
Assignment
|
|
.where(assigned_to_id: user.id, assigned_to_type: "User", active: true)
|
|
.joins(:topic)
|
|
.where(topics: { closed: false })
|
|
.count
|
|
|
|
# Assignments made by the user to others
|
|
assigned_by_user =
|
|
Assignment
|
|
.where(assigned_by_user_id: user.id)
|
|
.where(created_at: date)
|
|
.count
|
|
|
|
{
|
|
data: {
|
|
total_assigned: total_assigned,
|
|
completed: completed_count,
|
|
pending: pending_count,
|
|
assigned_by_user: assigned_by_user,
|
|
completion_rate:
|
|
total_assigned > 0 ? (completed_count.to_f / total_assigned * 100).round(1) : 0,
|
|
},
|
|
identifier: "assignments",
|
|
}
|
|
end
|
|
|
|
def enabled?
|
|
defined?(Assignment) && SiteSetting.assign_enabled
|
|
end
|
|
end
|
|
end
|
|
end
|