more reports and fake data

This commit is contained in:
Joffrey JAFFEUX 2025-01-09 17:55:58 +01:00
parent 88d928c315
commit 2f7cd88bf2
8 changed files with 101 additions and 63 deletions

View File

@ -4,7 +4,17 @@
# https://docs.github.com/assets/cb-35216/mw-1440/images/help/profile/contributions-graph.webp # https://docs.github.com/assets/cb-35216/mw-1440/images/help/profile/contributions-graph.webp
module DiscourseRewind module DiscourseRewind
class Rewind::Action::ActivityCalendar < Rewind::Action::BaseReport 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 def call
return FakeData if Rails.env.development?
calendar = calendar =
Post Post
.unscoped .unscoped

View File

@ -4,9 +4,9 @@
# Score is informative only, do not show in UI # Score is informative only, do not show in UI
module DiscourseRewind module DiscourseRewind
class Rewind::Action::Fbff < Rewind::Action::BaseReport class Rewind::Action::Fbff < Rewind::Action::BaseReport
MAX_SUMMARY_RESULTS = 50 MAX_SUMMARY_RESULTS ||= 50
LIKE_SCORE = 1 LIKE_SCORE ||= 1
REPLY_SCORE = 10 REPLY_SCORE ||= 10
def call def call
most_liked_users = most_liked_users =
@ -58,15 +58,21 @@ module DiscourseRewind
apply_score(users_i_most_replied, REPLY_SCORE), apply_score(users_i_most_replied, REPLY_SCORE),
] ]
fbffs = fbff_id =
fbffs fbffs
.flatten .flatten
.inject { |h1, h2| h1.merge(h2) { |_, v1, v2| v1 + v2 } } .inject { |h1, h2| h1.merge(h2) { |_, v1, v2| v1 + v2 } }
.sort_by { |_, v| -v } .sort_by { |_, v| -v }
.first(6) .first
.to_h .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 end
def post_query(user, date) def post_query(user, date)

View File

@ -6,10 +6,32 @@ module DiscourseRewind
FakeData = { FakeData = {
data: { data: {
post_received_reactions: { post_received_reactions: {
"open_mouth" => 10, "open_mouth" => 2,
"cat" => 32,
"dog" => 34,
"heart" => 45,
"grinning" => 82,
}, },
post_used_reactions: { 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", identifier: "reactions",
@ -21,34 +43,38 @@ module DiscourseRewind
data = {} data = {}
if defined?(DiscourseReactions::Reaction) if defined?(DiscourseReactions::Reaction)
# This is missing heart reactions (default like) # This is missing heart reactions (default like)
data[:post_used_reactions] = DiscourseReactions::Reaction data[:post_used_reactions] = sort_and_limit(
.by_user(user) DiscourseReactions::Reaction
.where(created_at: date) .by_user(user)
.group(:reaction_value) .where(created_at: date)
.count .group(:reaction_value)
.count,
)
data[:post_received_reactions] = DiscourseReactions::Reaction data[:post_received_reactions] = sort_and_limit(
.includes(:post) DiscourseReactions::Reaction
.where(posts: { user_id: user.id }) .includes(:post)
.where(created_at: date) .where(posts: { user_id: user.id })
.group(:reaction_value) .where(created_at: date)
.limit(5) .group(:reaction_value)
.count .limit(5)
.count,
)
end end
if SiteSetting.chat_enabled if SiteSetting.chat_enabled
data[:chat_used_reactions] = Chat::MessageReaction data[:chat_used_reactions] = sort_and_limit(
.where(user: user) Chat::MessageReaction.where(user: user).where(created_at: date).group(:emoji).count,
.where(created_at: date) )
.group(:emoji)
.count
data[:chat_received_reactions] = Chat::MessageReaction data[:chat_received_reactions] = sort_and_limit(
.includes(:chat_message) Chat::MessageReaction
.where(chat_message: { user_id: user.id }) .includes(:chat_message)
.where(created_at: date) .where(chat_message: { user_id: user.id })
.group(:emoji) .where(created_at: date)
.count .group(:emoji)
.count,
)
end end
{ data:, identifier: "reactions" } { data:, identifier: "reactions" }
@ -59,7 +85,7 @@ module DiscourseRewind
end end
def sort_and_limit(reactions) 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 end
end end

View File

@ -24,7 +24,6 @@ export default class BestTopics extends Component {
<div class="rewind-report-page -best-topics"> <div class="rewind-report-page -best-topics">
<h2 class="rewind-report-title">Your 3 best topics</h2> <h2 class="rewind-report-title">Your 3 best topics</h2>
<div class="rewind-report-container"> <div class="rewind-report-container">
{{log @report.data}}
<div class="rewind-card"> <div class="rewind-card">
{{#each @report.data as |topic idx|}} {{#each @report.data as |topic idx|}}
<a <a

View File

@ -24,7 +24,6 @@ export default class BestTopics extends Component {
<div class="rewind-report-page -best-topics"> <div class="rewind-report-page -best-topics">
<h2 class="rewind-report-title">Your 3 best topics</h2> <h2 class="rewind-report-title">Your 3 best topics</h2>
<div class="rewind-report-container"> <div class="rewind-report-container">
{{log @report.data}}
<div class="rewind-card"> <div class="rewind-card">
{{#each @report.data as |topic idx|}} {{#each @report.data as |topic idx|}}
<a <a

View File

@ -1,13 +1,25 @@
import Component from "@glimmer/component"; import Component from "@glimmer/component";
import { hash } from "@ember/helper";
import avatar from "discourse/helpers/bound-avatar-template";
export default class FBFF extends Component { export default class FBFF extends Component {
<template> <template>
<div class="rewind-report-page"> <div class="rewind-report-page -fbff">
FBFF <h2 class="rewind-report-title">Your FBFF (Forum Best Friend Forever)</h2>
</div> <div class="rewind-report-container">
<div class="rewind-card">
<div class="rewind-report-page"> {{avatar
page 2 @report.data.fbff.avatar_template
"tiny"
(hash title=@report.data.fbff.username)
}}
{{avatar
@report.data.yourself.avatar_template
"tiny"
(hash title=@report.data.yourself.username)
}}
</div>
</div>
</div> </div>
</template> </template>
} }

View File

@ -30,12 +30,15 @@ export default class Reactions extends Component {
return htmlSafe(`width: ${this.computePercentage(count)}`); return htmlSafe(`width: ${this.computePercentage(count)}`);
} }
get receivedReactions() {
return this.args.report.data.post_received_reactions ?? {};
}
<template> <template>
{{log @report}}
<div class="rewind-report-page -post-received-reactions"> <div class="rewind-report-page -post-received-reactions">
<h2 class="rewind-report-title">Most received reactions in topics</h2> <h2 class="rewind-report-title">Most received reactions in topics</h2>
<div class="rewind-report-container"> <div class="rewind-report-container">
{{#each-in @report.data.post_received_reactions as |emojiName count|}} {{#each-in this.receivedReactions as |emojiName count|}}
<div <div
class="rewind-card scale" class="rewind-card scale"
style="--rand: {{this.randomModifier}}" style="--rand: {{this.randomModifier}}"

View File

@ -3,7 +3,6 @@ import { tracked } from "@glimmer/tracking";
import { on } from "@ember/modifier"; import { on } from "@ember/modifier";
import { action } from "@ember/object"; import { action } from "@ember/object";
import didInsert from "@ember/render-modifiers/modifiers/did-insert"; import didInsert from "@ember/render-modifiers/modifiers/did-insert";
import { schedule } from "@ember/runloop";
import { service } from "@ember/service"; import { service } from "@ember/service";
import { eq } from "truth-helpers"; import { eq } from "truth-helpers";
import DButton from "discourse/components/d-button"; import DButton from "discourse/components/d-button";
@ -85,7 +84,6 @@ export default class Rewind extends Component {
{{didInsert this.registerRewindContainer}} {{didInsert this.registerRewindContainer}}
tabindex="0" tabindex="0"
> >
<div class="rewind"> <div class="rewind">
<div class="background-1 parallax-bg"></div> <div class="background-1 parallax-bg"></div>
{{! <canvas class="background-2 parallax-bg"></canvas> }} {{! <canvas class="background-2 parallax-bg"></canvas> }}
@ -112,7 +110,9 @@ export default class Rewind extends Component {
{{#each this.rewind as |report|}} {{#each this.rewind as |report|}}
<div class={{concatClass "rewind-report" report.identifier}}> <div class={{concatClass "rewind-report" report.identifier}}>
{{#if (eq report.identifier "reactions")}} {{#if (eq report.identifier "fbff")}}
<FBFF @report={{report}} />
{{else if (eq report.identifier "reactions")}}
<Reactions @report={{report}} /> <Reactions @report={{report}} />
{{else if (eq report.identifier "word-cloud")}} {{else if (eq report.identifier "word-cloud")}}
<WordCards @report={{report}} /> <WordCards @report={{report}} />
@ -129,23 +129,6 @@ export default class Rewind extends Component {
{{else if (eq report.identifier "favorite-categories")}} {{else if (eq report.identifier "favorite-categories")}}
<FavoriteCategories @report={{report}} /> <FavoriteCategories @report={{report}} />
{{/if}} {{/if}}
{{!-- {{else if (eq report.identifier "fbff")}}
<FBFF @report={{report}} />
{{else if (eq report.identifier "word-cloud")}}
<WordCloud @report={{report}} />
{{else if (eq report.identifier "activity-calendar")}}
<ActivityCalendar @report={{report}} />
{{else if (eq report.identifier "best-posts")}}
<BestPosts @report={{report}} />
{{else if (eq report.identifier "best-topics")}}
<BestTopics @report={{report}} />
{{else if (eq report.identifier "favorite-tags")}}
<FavoriteTags @report={{report}} />
{{else if (eq report.identifier "favorite-categories")}}
<FavoriteCategories @report={{report}} />
{{else if (eq report.identifier "reading-time")}}
<ReadingTime @report={{report}} />
{{/if}} --}}
</div> </div>
{{/each}} {{/each}}
</div> </div>