82 lines
2.6 KiB
Ruby
Raw Permalink Normal View History

FEATURE: Add seven new metrics to Discourse Rewind reports (#26) ## 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>
2025-10-30 11:18:35 -03:00
# frozen_string_literal: true
# Invite statistics
# Shows how many users this user invited and the impact of those invitees
module DiscourseRewind
module Action
class Invites < BaseReport
def call
# Get all invites created by this user in the date range
invites = Invite.where(invited_by_id: user.id).where(created_at: date)
total_invites = invites.count
return if total_invites == 0
# Redeemed invites (users who actually joined)
redeemed_count = invites.where("redemption_count > 0").count
FEATURE: Add seven new metrics to Discourse Rewind reports (#26) ## 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>
2025-10-30 11:18:35 -03:00
# Get the users who were invited (via InvitedUser or redeemed invites)
invited_user_ids = InvitedUser.where(invite: invites).pluck(:user_id).compact
invited_users = User.where(id: invited_user_ids)
# Calculate impact of invitees
invitee_post_count =
Post.where(user_id: invited_user_ids).where(created_at: date).where(deleted_at: nil).count
FEATURE: Add seven new metrics to Discourse Rewind reports (#26) ## 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>
2025-10-30 11:18:35 -03:00
invitee_topic_count =
Topic
.where(user_id: invited_user_ids)
.where(created_at: date)
.where(deleted_at: nil)
.count
invitee_like_count =
UserAction
.where(user_id: invited_user_ids)
.where(action_type: UserAction::LIKE)
.where(created_at: date)
.count
# Calculate average trust level of invitees
avg_trust_level = invited_users.average(:trust_level)&.to_f&.round(1) || 0
# Most active invitee
most_active_invitee = nil
if invited_user_ids.any?
most_active_id =
Post
.where(user_id: invited_user_ids)
.where(created_at: date)
.where(deleted_at: nil)
.group(:user_id)
.count
.max_by { |_, count| count }
&.first
if most_active_id
most_active_user = User.find_by(id: most_active_id)
most_active_invitee =
BasicUserSerializer.new(most_active_user, root: false).as_json if most_active_user
end
end
{
data: {
total_invites: total_invites,
redeemed_count: redeemed_count,
redemption_rate:
total_invites > 0 ? (redeemed_count.to_f / total_invites * 100).round(1) : 0,
invitee_post_count: invitee_post_count,
invitee_topic_count: invitee_topic_count,
invitee_like_count: invitee_like_count,
avg_trust_level: avg_trust_level,
most_active_invitee: most_active_invitee,
},
identifier: "invites",
}
end
end
end
end