mirror of
https://github.com/discourse/discourse-rewind.git
synced 2025-07-07 14:22:12 +00:00
more reports and fake data
This commit is contained in:
parent
88d928c315
commit
2f7cd88bf2
@ -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
|
||||
|
@ -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)
|
@ -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
|
||||
|
@ -24,7 +24,6 @@ export default class BestTopics extends Component {
|
||||
<div class="rewind-report-page -best-topics">
|
||||
<h2 class="rewind-report-title">Your 3 best topics</h2>
|
||||
<div class="rewind-report-container">
|
||||
{{log @report.data}}
|
||||
<div class="rewind-card">
|
||||
{{#each @report.data as |topic idx|}}
|
||||
<a
|
||||
|
@ -24,7 +24,6 @@ export default class BestTopics extends Component {
|
||||
<div class="rewind-report-page -best-topics">
|
||||
<h2 class="rewind-report-title">Your 3 best topics</h2>
|
||||
<div class="rewind-report-container">
|
||||
{{log @report.data}}
|
||||
<div class="rewind-card">
|
||||
{{#each @report.data as |topic idx|}}
|
||||
<a
|
||||
|
@ -1,13 +1,25 @@
|
||||
import Component from "@glimmer/component";
|
||||
import { hash } from "@ember/helper";
|
||||
import avatar from "discourse/helpers/bound-avatar-template";
|
||||
|
||||
export default class FBFF extends Component {
|
||||
<template>
|
||||
<div class="rewind-report-page">
|
||||
FBFF
|
||||
</div>
|
||||
|
||||
<div class="rewind-report-page">
|
||||
page 2
|
||||
<div class="rewind-report-page -fbff">
|
||||
<h2 class="rewind-report-title">Your FBFF (Forum Best Friend Forever)</h2>
|
||||
<div class="rewind-report-container">
|
||||
<div class="rewind-card">
|
||||
{{avatar
|
||||
@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>
|
||||
</template>
|
||||
}
|
||||
|
@ -30,12 +30,15 @@ export default class Reactions extends Component {
|
||||
return htmlSafe(`width: ${this.computePercentage(count)}`);
|
||||
}
|
||||
|
||||
get receivedReactions() {
|
||||
return this.args.report.data.post_received_reactions ?? {};
|
||||
}
|
||||
|
||||
<template>
|
||||
{{log @report}}
|
||||
<div class="rewind-report-page -post-received-reactions">
|
||||
<h2 class="rewind-report-title">Most received reactions in topics</h2>
|
||||
<div class="rewind-report-container">
|
||||
{{#each-in @report.data.post_received_reactions as |emojiName count|}}
|
||||
{{#each-in this.receivedReactions as |emojiName count|}}
|
||||
<div
|
||||
class="rewind-card scale"
|
||||
style="--rand: {{this.randomModifier}}"
|
||||
|
@ -3,7 +3,6 @@ import { tracked } from "@glimmer/tracking";
|
||||
import { on } from "@ember/modifier";
|
||||
import { action } from "@ember/object";
|
||||
import didInsert from "@ember/render-modifiers/modifiers/did-insert";
|
||||
import { schedule } from "@ember/runloop";
|
||||
import { service } from "@ember/service";
|
||||
import { eq } from "truth-helpers";
|
||||
import DButton from "discourse/components/d-button";
|
||||
@ -85,7 +84,6 @@ export default class Rewind extends Component {
|
||||
{{didInsert this.registerRewindContainer}}
|
||||
tabindex="0"
|
||||
>
|
||||
|
||||
<div class="rewind">
|
||||
<div class="background-1 parallax-bg"></div>
|
||||
{{! <canvas class="background-2 parallax-bg"></canvas> }}
|
||||
@ -112,7 +110,9 @@ export default class Rewind extends Component {
|
||||
|
||||
{{#each this.rewind as |report|}}
|
||||
<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}} />
|
||||
{{else if (eq report.identifier "word-cloud")}}
|
||||
<WordCards @report={{report}} />
|
||||
@ -129,23 +129,6 @@ export default class Rewind extends Component {
|
||||
{{else if (eq report.identifier "favorite-categories")}}
|
||||
<FavoriteCategories @report={{report}} />
|
||||
{{/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>
|
||||
{{/each}}
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user