fake data

This commit is contained in:
Joffrey JAFFEUX 2025-01-09 16:52:32 +01:00
parent d970dbba68
commit 88d928c315
7 changed files with 62 additions and 94 deletions

View File

@ -3,9 +3,22 @@
# For a most user / received reactions cards
module DiscourseRewind
class Rewind::Action::Reactions < Rewind::Action::BaseReport
def call
data = {}
FakeData = {
data: {
post_received_reactions: {
"open_mouth" => 10,
},
post_used_reactions: {
"open_mouth" => 10,
},
},
identifier: "reactions",
}
def call
return FakeData if Rails.env.development?
data = {}
if defined?(DiscourseReactions::Reaction)
# This is missing heart reactions (default like)
data[:post_used_reactions] = DiscourseReactions::Reaction

View File

@ -3,7 +3,21 @@
# User Word Cloud
module DiscourseRewind
class Rewind::Action::WordCloud < Rewind::Action::BaseReport
FakeData = {
data: [
{ word: "what", score: 100 },
{ word: "have", score: 90 },
{ word: "you", score: 80 },
{ word: "achieved", score: 70 },
{ word: "this", score: 60 },
{ word: "week", score: 50 },
],
identifier: "word-cloud",
}
def call
return FakeData if Rails.env.development?
words = DB.query(<<~SQL, user_id: user.id, date_start: date.first, date_end: date.last)
WITH popular_words AS (
SELECT
@ -27,7 +41,7 @@ module DiscourseRewind
ndoc DESC,
word
LIMIT
5
100
), lex AS (
SELECT
DISTINCT ON (lexeme) to_tsvector('english', word) as lexeme,
@ -65,7 +79,7 @@ module DiscourseRewind
LIMIT 100
SQL
word_score = words.map { [_1.original_word, _1.ndoc + _1.nentry] }.to_h
word_score = words.map { { word: _1.original_word, score: _1.ndoc + _1.nentry } }
{ data: word_score, identifier: "word-cloud" }
end

View File

@ -1,53 +1,35 @@
import Component from "@glimmer/component";
import { fn } from "@ember/helper";
import { concat } from "@ember/helper";
import { concat, fn } from "@ember/helper";
import { on } from "@ember/modifier";
import { action } from "@ember/object";
import didInsert from "@ember/render-modifiers/modifiers/did-insert";
import emoji from "discourse/helpers/emoji";
const MYSTERY_EMOJIS = [
"mag", // 🔍
"question", // ❓
"8ball", // 🎱
"crystal_ball", // 🔮
"crescent_moon", // 🌙
];
const BACKGROUND_COLORS = [
"#FBF5AF",
"#28ABE2",
"#F0794A",
"#E84A51",
"#FBF5AF",
];
export default class WordCard extends Component {
// const mysteryEmojis = [
// "mag", // 🔍
// "question", // ❓
// "8ball", // 🎱
// "crystal_ball", // 🔮
// "crescent_moon", // 🌙
// ];
// const backgroundColors = [
// "#FBF5AF",
// "#28ABE2",
// "#F0794A",
// "#E84A51",
// "#FBF5AF",
// ];
get randomStyle() {
return `--rand: ${Math.random()}`;
}
get mysteryData() {
const mysteryEmojis = [
"mag", // 🔍
"question", // ❓
"8ball", // 🎱
"crystal_ball", // 🔮
"crescent_moon", // 🌙
];
const backgroundColors = [
"#FBF5AF",
"#28ABE2",
"#F0794A",
"#E84A51",
"#FBF5AF",
];
const randomIndex = Math.floor(Math.random() * mysteryEmojis.length);
return {
emoji: mysteryEmojis[randomIndex],
color: `--mystery-color: ${backgroundColors[randomIndex]}`,
emoji: MYSTERY_EMOJIS[this.args.index],
color: `--mystery-color: ${BACKGROUND_COLORS[this.args.index]}`,
};
}

View File

@ -1,16 +1,22 @@
import Component from "@glimmer/component";
import WordCard from "discourse/plugins/discourse-rewind/discourse/components/reports/word-card";
// eslint-disable-next-line ember/no-empty-glimmer-component-classes
export default class WordCards extends Component {
get topWords() {
return this.args.report.data.sort((a, b) => b.score - a.score).slice(0, 5);
}
<template>
<div class="rewind-report-page -word-cloud">
<h2 class="rewind-report-title">Word Usage</h2>
<div class="rewind-report-container">
{{#each-in @report.data as |word count|}}
{{! can we pass in an index here? This way inside instead of random colors & images chosen, we just set them to be static }}
<WordCard @word={{word}} @count={{count}} />
{{/each-in}}
{{#each this.topWords as |entry index|}}
<WordCard
@word={{entry.word}}
@count={{entry.score}}
@index={{index}}
/>
{{/each}}
</div>
</div>
</template>

View File

@ -109,7 +109,7 @@ export default class Rewind extends Component {
<div class="rewind-report">
<Introduction />
</div>
{{log this.rewind}}
{{#each this.rewind as |report|}}
<div class={{concatClass "rewind-report" report.identifier}}>
{{#if (eq report.identifier "reactions")}}

View File

View File

@ -1,47 +0,0 @@
# frozen_string_literal: true
describe "Discourse Rewind - kitchen sink", type: :system do
fab!(:current_user) { Fabricate(:user) }
before do
SiteSetting.discourse_reactions_enabled = true
SiteSetting.chat_enabled = true
SiteSetting.discourse_rewind_enabled = true
sign_in(current_user)
# reactions received
reactions = %w[open_mouth confetti_ball hugs +1 laughing heart]
Fabricate
.times(10, :post, user: current_user)
.each do |post|
DiscourseReactions::Reaction.create!(
created_at: (Date.new(2024, 1, 1) + rand(1..200).days),
post:,
reaction_value: reactions.sample,
)
end
# reading time
100.times do |i|
UserVisit.create!(
user_id: current_user.id,
time_read: rand(1..200),
visited_at: (Date.new(2024, 1, 1) + i.days).strftime("%Y-%m-%d"),
)
end
# calendar
Fabricate.times(10, :post, user: current_user, created_at: Date.new(2024, 1, 25))
Fabricate.times(1, :post, user: current_user, created_at: Date.new(2024, 3, 12))
Fabricate.times(5, :post, user: current_user, created_at: Date.new(2024, 8, 19))
Fabricate.times(1, :post, user: current_user, created_at: Date.new(2024, 10, 29))
Fabricate.times(20, :post, user: current_user, created_at: Date.new(2024, 11, 2))
end
it "can visit the rewind page" do
visit("/my/activity/rewind")
pause_test
end
end