From 2f7cd88bf25b33722d48aa9e2cd15d59991d84c2 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Thu, 9 Jan 2025 17:55:58 +0100 Subject: [PATCH] more reports and fake data --- .../rewind/action/activity_calendar.rb | 10 +++ .../rewind/action/{.fbff.rb => fbff.rb} | 20 +++-- .../rewind/action/reactions.rb | 78 ++++++++++++------- .../components/reports/best-topics copy.gjs | 1 - .../components/reports/best-topics.gjs | 1 - .../discourse/components/reports/fbff.gjs | 24 ++++-- .../components/reports/reactions.gjs | 7 +- .../discourse/components/rewind.gjs | 23 +----- 8 files changed, 101 insertions(+), 63 deletions(-) rename app/services/discourse_rewind/rewind/action/{.fbff.rb => fbff.rb} (89%) diff --git a/app/services/discourse_rewind/rewind/action/activity_calendar.rb b/app/services/discourse_rewind/rewind/action/activity_calendar.rb index 8bdc7cb..6fd1fda 100644 --- a/app/services/discourse_rewind/rewind/action/activity_calendar.rb +++ b/app/services/discourse_rewind/rewind/action/activity_calendar.rb @@ -4,7 +4,17 @@ # https://docs.github.com/assets/cb-35216/mw-1440/images/help/profile/contributions-graph.webp module DiscourseRewind class Rewind::Action::ActivityCalendar < Rewind::Action::BaseReport + FakeData = { + data: + (Date.new(2024, 1, 1)..Date.new(2024, 12, 31)).map do |date| + { date:, post_count: rand(0..20), visited: false } + end, + identifier: "activity-calendar", + } + def call + return FakeData if Rails.env.development? + calendar = Post .unscoped diff --git a/app/services/discourse_rewind/rewind/action/.fbff.rb b/app/services/discourse_rewind/rewind/action/fbff.rb similarity index 89% rename from app/services/discourse_rewind/rewind/action/.fbff.rb rename to app/services/discourse_rewind/rewind/action/fbff.rb index 14de726..24dbef5 100644 --- a/app/services/discourse_rewind/rewind/action/.fbff.rb +++ b/app/services/discourse_rewind/rewind/action/fbff.rb @@ -4,9 +4,9 @@ # Score is informative only, do not show in UI module DiscourseRewind class Rewind::Action::Fbff < Rewind::Action::BaseReport - MAX_SUMMARY_RESULTS = 50 - LIKE_SCORE = 1 - REPLY_SCORE = 10 + MAX_SUMMARY_RESULTS ||= 50 + LIKE_SCORE ||= 1 + REPLY_SCORE ||= 10 def call most_liked_users = @@ -58,15 +58,21 @@ module DiscourseRewind apply_score(users_i_most_replied, REPLY_SCORE), ] - fbffs = + fbff_id = fbffs .flatten .inject { |h1, h2| h1.merge(h2) { |_, v1, v2| v1 + v2 } } .sort_by { |_, v| -v } - .first(6) - .to_h + .first + .first - { data: fbffs, identifier: "fbff" } + { + data: { + fbff: BasicUserSerializer.new(User.find(fbff_id), root: false).as_json, + yourself: BasicUserSerializer.new(user, root: false).as_json, + }, + identifier: "fbff", + } end def post_query(user, date) diff --git a/app/services/discourse_rewind/rewind/action/reactions.rb b/app/services/discourse_rewind/rewind/action/reactions.rb index 7ab2554..6641edc 100644 --- a/app/services/discourse_rewind/rewind/action/reactions.rb +++ b/app/services/discourse_rewind/rewind/action/reactions.rb @@ -6,10 +6,32 @@ module DiscourseRewind FakeData = { data: { post_received_reactions: { - "open_mouth" => 10, + "open_mouth" => 2, + "cat" => 32, + "dog" => 34, + "heart" => 45, + "grinning" => 82, }, post_used_reactions: { - "open_mouth" => 10, + "open_mouth" => 2, + "cat" => 32, + "dog" => 34, + "heart" => 45, + "grinning" => 82, + }, + chat_used_reactions: { + "open_mouth" => 2, + "cat" => 32, + "dog" => 34, + "heart" => 45, + "grinning" => 82, + }, + chat_received_reactions: { + "open_mouth" => 2, + "cat" => 32, + "dog" => 34, + "heart" => 45, + "grinning" => 82, }, }, identifier: "reactions", @@ -21,34 +43,38 @@ module DiscourseRewind data = {} if defined?(DiscourseReactions::Reaction) # This is missing heart reactions (default like) - data[:post_used_reactions] = DiscourseReactions::Reaction - .by_user(user) - .where(created_at: date) - .group(:reaction_value) - .count + data[:post_used_reactions] = sort_and_limit( + DiscourseReactions::Reaction + .by_user(user) + .where(created_at: date) + .group(:reaction_value) + .count, + ) - data[:post_received_reactions] = DiscourseReactions::Reaction - .includes(:post) - .where(posts: { user_id: user.id }) - .where(created_at: date) - .group(:reaction_value) - .limit(5) - .count + data[:post_received_reactions] = sort_and_limit( + DiscourseReactions::Reaction + .includes(:post) + .where(posts: { user_id: user.id }) + .where(created_at: date) + .group(:reaction_value) + .limit(5) + .count, + ) end if SiteSetting.chat_enabled - data[:chat_used_reactions] = Chat::MessageReaction - .where(user: user) - .where(created_at: date) - .group(:emoji) - .count + data[:chat_used_reactions] = sort_and_limit( + Chat::MessageReaction.where(user: user).where(created_at: date).group(:emoji).count, + ) - data[:chat_received_reactions] = Chat::MessageReaction - .includes(:chat_message) - .where(chat_message: { user_id: user.id }) - .where(created_at: date) - .group(:emoji) - .count + data[:chat_received_reactions] = sort_and_limit( + Chat::MessageReaction + .includes(:chat_message) + .where(chat_message: { user_id: user.id }) + .where(created_at: date) + .group(:emoji) + .count, + ) end { data:, identifier: "reactions" } @@ -59,7 +85,7 @@ module DiscourseRewind end def sort_and_limit(reactions) - reactions.sort_by { |_, v| -v }.first(6).to_h + reactions.sort_by { |_, v| -v }.first(5).to_h end end end diff --git a/assets/javascripts/discourse/components/reports/best-topics copy.gjs b/assets/javascripts/discourse/components/reports/best-topics copy.gjs index dc578ed..e24958f 100644 --- a/assets/javascripts/discourse/components/reports/best-topics copy.gjs +++ b/assets/javascripts/discourse/components/reports/best-topics copy.gjs @@ -24,7 +24,6 @@ export default class BestTopics extends Component {

Your 3 best topics