DEV: FakeData for all reports (#32)

This commit is contained in:
Rafael dos Santos Silva 2025-11-26 15:50:18 -03:00 committed by GitHub
parent f4560c2292
commit 09ee91ad67
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 243 additions and 0 deletions

View File

@ -6,7 +6,31 @@
module DiscourseRewind
module Action
class AiUsage < BaseReport
FakeData = {
data: {
total_requests: 247,
total_tokens: 156_890,
request_tokens: 45_230,
response_tokens: 111_660,
feature_usage: {
"chat_composer_helper" => 89,
"post_summarizer" => 56,
"semantic_search" => 42,
"topic_gist" => 38,
"similar_topics" => 22,
},
model_usage: {
"gpt-4" => 123,
"claude-3-5-sonnet" => 89,
"gpt-3.5-turbo" => 35,
},
success_rate: 94.7,
},
identifier: "ai-usage",
}
def call
return FakeData if Rails.env.development?
return if !enabled?
base_query = AiApiRequestStat.where(user_id: user.id).where(bucket_date: date)

View File

@ -5,7 +5,19 @@
module DiscourseRewind
module Action
class Assignments < BaseReport
FakeData = {
data: {
total_assigned: 24,
completed: 18,
pending: 6,
assigned_by_user: 15,
completion_rate: 75.0,
},
identifier: "assignments",
}
def call
return FakeData if Rails.env.development?
return if !enabled?
# Assignments made to the user

View File

@ -3,7 +3,37 @@
module DiscourseRewind
module Action
class BestPosts < BaseReport
FakeData = {
data: [
{
post_number: 5,
topic_id: 42,
like_count: 23,
reply_count: 8,
excerpt: "This is a great explanation of how ActiveRecord works under the hood...",
},
{
post_number: 12,
topic_id: 89,
like_count: 19,
reply_count: 5,
excerpt:
"Here's a comprehensive guide to testing Rails applications with RSpec and system tests...",
},
{
post_number: 3,
topic_id: 156,
like_count: 15,
reply_count: 12,
excerpt:
"The key to understanding PostgreSQL performance is looking at your query plans...",
},
],
identifier: "best-posts",
}
def call
return FakeData if Rails.env.development?
best_posts =
Post
.where(user_id: user.id)

View File

@ -3,7 +3,32 @@
module DiscourseRewind
module Action
class BestTopics < BaseReport
FakeData = {
data: [
{
topic_id: 1,
title: "How to get started with Rails",
excerpt: "A comprehensive guide to getting started with Ruby on Rails...",
yearly_score: 42.5,
},
{
topic_id: 2,
title: "Best practices for database optimization",
excerpt: "Learn how to optimize your database queries for better performance...",
yearly_score: 38.2,
},
{
topic_id: 3,
title: "Understanding ActiveRecord associations",
excerpt: "Deep dive into has_many, belongs_to, and other associations...",
yearly_score: 35.7,
},
],
identifier: "best-topics",
}
def call
return FakeData if Rails.env.development?
best_topics =
TopTopic
.includes(:topic)

View File

@ -5,7 +5,27 @@
module DiscourseRewind
module Action
class ChatUsage < BaseReport
FakeData = {
data: {
total_messages: 342,
favorite_channels: [
{ channel_id: 1, channel_name: "general", message_count: 156 },
{ channel_id: 2, channel_name: "tech-talk", message_count: 89 },
{ channel_id: 3, channel_name: "random", message_count: 45 },
{ channel_id: 4, channel_name: "dev", message_count: 32 },
{ channel_id: 5, channel_name: "announcements", message_count: 12 },
],
dm_message_count: 87,
unique_dm_channels: 12,
messages_with_reactions: 42,
total_reactions_received: 156,
avg_message_length: 78.5,
},
identifier: "chat-usage",
}
def call
return FakeData if Rails.env.development?
return if !enabled?
messages =

View File

@ -15,7 +15,47 @@ module DiscourseRewind
}ix
MAX_RESULTS = 5
FakeData = {
data: {
favorite_gifs: [
{
url: "https://media.giphy.com/media/111ebonMs90YLu/giphy.gif",
usage_count: 12,
likes: 45,
reactions: 23,
},
{
url: "https://media.giphy.com/media/JIX9t2j0ZTN9S/giphy.gif",
usage_count: 8,
likes: 32,
reactions: 18,
},
{
url: "https://media1.tenor.com/m/XnODae53zvYAAAAd/joke-stickfigure.gif",
usage_count: 7,
likes: 28,
reactions: 15,
},
{
url: "https://c.tenor.com/tX_T48A14BwAAAAd/khaby-really.gif",
usage_count: 5,
likes: 20,
reactions: 12,
},
{
url: "https://media.giphy.com/media/3oriO0OEd9QIDdllqo/giphy.gif",
usage_count: 4,
likes: 15,
reactions: 8,
},
],
total_gif_usage: 36,
},
identifier: "favorite-gifs",
}
def call
return FakeData if Rails.env.development?
gif_data = {}
# Get GIFs from posts

View File

@ -9,7 +9,26 @@ module DiscourseRewind
LIKE_SCORE = 1
REPLY_SCORE = 10
FakeData = {
data: {
fbff: {
id: 2,
username: "codingpal",
name: "Coding Pal",
avatar_template: "/letter_avatar_proxy/v4/letter/c/3be4f8/{size}.png",
},
yourself: {
id: 1,
username: "you",
name: "You",
avatar_template: "/letter_avatar_proxy/v4/letter/y/f05b48/{size}.png",
},
},
identifier: "fbff",
}
def call
return FakeData if Rails.env.development?
most_liked_users =
like_query(date)
.where(acting_user_id: user.id)

View File

@ -5,7 +5,27 @@
module DiscourseRewind
module Action
class Invites < BaseReport
FakeData = {
data: {
total_invites: 18,
redeemed_count: 12,
redemption_rate: 66.7,
invitee_post_count: 145,
invitee_topic_count: 23,
invitee_like_count: 89,
avg_trust_level: 1.8,
most_active_invitee: {
id: 42,
username: "newbie_123",
name: "New User",
avatar_template: "/letter_avatar_proxy/v4/letter/n/8c91d9/{size}.png",
},
},
identifier: "invites",
}
def call
return FakeData if Rails.env.development?
# Get all invites created by this user in the date range
invites = Invite.where(invited_by_id: user.id).where(created_at: date)

View File

@ -5,7 +5,21 @@
module DiscourseRewind
module Action
class NewUserInteractions < BaseReport
FakeData = {
data: {
total_interactions: 127,
likes_given: 45,
replies_to_new_users: 62,
mentions_to_new_users: 20,
topics_with_new_users: 8,
unique_new_users: 24,
new_users_count: 156,
},
identifier: "new-user-interactions",
}
def call
return FakeData if Rails.env.development?
year_start = Date.new(date.first.year, 1, 1)
# Find users who created accounts this year

View File

@ -10,7 +10,46 @@ module DiscourseRewind
NIGHT_OWL_THRESHOLD_PM = 22..23
NIGHT_OWL_THRESHOLD_AM = 0..2
FakeData = {
data: {
activity_by_hour: {
0 => 12,
1 => 8,
2 => 5,
3 => 2,
4 => 1,
5 => 3,
6 => 8,
7 => 15,
8 => 25,
9 => 32,
10 => 28,
11 => 24,
12 => 22,
13 => 20,
14 => 26,
15 => 30,
16 => 28,
17 => 22,
18 => 18,
19 => 16,
20 => 14,
21 => 18,
22 => 22,
23 => 15,
},
most_active_hour: 9,
personality: {
type: "early_bird",
percentage: 28.5,
},
total_activities: 414,
},
identifier: "time-of-day-activity",
}
def call
return FakeData if Rails.env.development?
# Get activity by hour of day (in user's timezone)
activity_by_hour = get_activity_by_hour