Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 32 additions & 16 deletions assets/javascripts/discourse/components/admin-report-emotion.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,62 @@
</div>

<div class="cell value today-count">
<a
href="{{this.filterURL}}activity-after%3A{{this.today}}%20order%3A{{this.model.type}}"
>
{{#if this.filterEnabled}}
<a
href="{{this.filterURL}}activity-after%3A{{this.today}}%20order%3A{{this.model.type}}"
>
{{number this.model.todayCount}}
</a>
{{else}}
{{number this.model.todayCount}}
</a>
{{/if}}
</div>

<div
class="cell value yesterday-count {{this.model.yesterdayTrend}}"
title={{this.model.yesterdayCountTitle}}
>
<a
href="{{this.filterURL}}activity-after%3A{{this.yesterday}}%20order%3A{{this.model.type}}"
>
{{#if this.filterEnabled}}
<a
href="{{this.filterURL}}activity-after%3A{{this.yesterday}}%20order%3A{{this.model.type}}"
>
{{number this.model.yesterdayCount}}
</a>
{{else}}
{{number this.model.yesterdayCount}}
</a>
{{/if}}
{{d-icon this.model.yesterdayTrendIcon}}
</div>

<div
class="cell value sevendays-count {{this.model.sevenDaysTrend}}"
title={{this.model.sevenDaysCountTitle}}
>
<a
href="{{this.filterURL}}activity-after%3A{{this.lastWeek}}%20order%3A{{this.model.type}}"
>
{{#if this.filterEnabled}}
<a
href="{{this.filterURL}}activity-after%3A{{this.lastWeek}}%20order%3A{{this.model.type}}"
>
{{number this.model.lastSevenDaysCount}}
</a>
{{else}}
{{number this.model.lastSevenDaysCount}}
</a>
{{/if}}
{{d-icon this.model.sevenDaysTrendIcon}}
</div>

<div
class="cell value thirty-days-count {{this.model.thirtyDaysTrend}}"
title={{this.model.thirtyDaysCountTitle}}
>
<a
href="{{this.filterURL}}activity-after%3A{{this.lastMonth}}%20order%3A{{this.model.type}}"
>
{{#if this.filterEnabled}}
<a
href="{{this.filterURL}}activity-after%3A{{this.lastMonth}}%20order%3A{{this.model.type}}"
>
{{number this.model.lastThirtyDaysCount}}
</a>
{{else}}
{{number this.model.lastThirtyDaysCount}}
</a>
{{/if}}

{{#if this.model.canDisplayTrendIcon}}
{{d-icon this.model.thirtyDaysTrendIcon}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import Component from "@ember/component";
import { service } from "@ember/service";
import { attributeBindings, classNames } from "@ember-decorators/component";
import getURL from "discourse-common/lib/get-url";

@classNames("admin-report-counters")
@attributeBindings("model.description:title")
export default class AdminReportEmotion extends Component {
@service siteSettings;

get filterURL() {
return getURL(`/filter?q=`);
}
Expand All @@ -24,4 +27,8 @@ export default class AdminReportEmotion extends Component {
get lastMonth() {
return moment().subtract(1, "month").format("YYYY-MM-DD");
}

get filterEnabled() {
return this.siteSettings.experimental_topics_filter;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ export default class AdminDashboardSentiment extends AdminDashboardTabController
return { startDate: this.startDate, endDate: this.endDate };
}

get emotionFilters() {
return {
startDate: moment().format("YYYY-MM-DD"),
endDate: moment().subtract(2, "month").format("YYYY-MM-DD"),
};
}

get emotions() {
const emotions = [
"admiration",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
{{#each this.emotions as |metric|}}
<AdminReport
@showHeader={{false}}
@filters={{this.emotionFilters}}
@forcedModes="emotion"
@dataSourceName="emotion_{{metric}}"
/>
Expand Down
28 changes: 28 additions & 0 deletions config/locales/server.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,60 +117,88 @@ en:
yaxis: "Date"
emotion_admiration:
title: 🤩 Admiration
description: "Posts classified with the emotion admiration via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_amusement:
title: 😄 Amusement
description: "Posts classified with the emotion amusement via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_anger:
title: 😠 Anger
description: "Posts classified with the emotion anger via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_annoyance:
title: 😒 Annoyance
description: "Posts classified with the emotion annoyance via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_approval:
title: 👍 Approval
description: "Posts classified with the emotion approval via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_caring:
title: 🤗 Caring
description: "Posts classified with the emotion caring via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_confusion:
title: 😕 Confusion
description: "Posts classified with the emotion confusion via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_curiosity:
title: 🤔 Curiosity
description: "Posts classified with the emotion curiosity via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_desire:
title: 😍 Desire
description: "Posts classified with the emotion desire via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_disappointment:
title: 😞 Disappointment
description: "Posts classified with the emotion disappointment via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_disapproval:
title: 👎 Disapproval
description: "Posts classified with the emotion disapproval via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_disgust:
title: 🤢 Disgust
description: "Posts classified with the emotion disgust via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_embarrassment:
title: 😳 Embarrassment
description: "Posts classified with the emotion embarrassment via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_excitement:
title: 🤪 Excitement
description: "Posts classified with the emotion excitement via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_fear:
title: 😨 Fear
description: "Posts classified with the emotion fear via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_gratitude:
title: 🙏 Gratitude
description: "Posts classified with the emotion gratitude via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_grief:
title: 😢 Grief
description: "Posts classified with the emotion grief via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_joy:
title: 😊 Joy
description: "Posts classified with the emotion joy via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_love:
title: ❤️ Love
description: "Posts classified with the emotion love via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_nervousness:
title: 😰 Nervousness
description: "Posts classified with the emotion nervousness via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_neutral:
title: 😐 Neutral
description: "Posts classified with the emotion neutral via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_optimism:
title: 🌟 Optimism
description: "Posts classified with the emotion optimism via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_pride:
title: 🦁 Pride
description: "Posts classified with the emotion pride via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_realization:
title: 💡 Realization
description: "Posts classified with the emotion realization via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_relief:
title: 😌 Relief
description: "Posts classified with the emotion relief via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_remorse:
title: 😔 Remorse
description: "Posts classified with the emotion remorse via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_sadness:
title: 😭 Sadness
description: "Posts classified with the emotion sadness via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_surprise:
title: 😲 Surprise
description: "Posts classified with the emotion surprise via AI, using the model 'SamLowe/roberta-base-go_emotions'."

discourse_ai:
ai_artifact:
Expand Down
13 changes: 7 additions & 6 deletions lib/sentiment/emotion_dashboard_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ class EmotionDashboardReport
def self.register!(plugin)
Emotions::LIST.each do |emotion|
plugin.add_report("emotion_#{emotion}") do |report|
query_results = DiscourseAi::Sentiment::EmotionDashboardReport.fetch_data
report.data = query_results.pop(30).map { |row| { x: row.day, y: row.send(emotion) } }
report.prev30Days =
query_results.take(30).reduce(0) { |sum, row| sum + row.send(emotion) }.to_i
query_results = DiscourseAi::Sentiment::EmotionDashboardReport.fetch_data(report)
report.data = query_results.map { |row| { x: row.day, y: row.send(emotion) } }
if report.facets.include?(:prev_period) && query_results.length > 30
report.prev30Days = query_results[31..60].sum { |row| row.send(emotion) }
end
end
end

def self.fetch_data
DB.query(<<~SQL, end: Time.now.tomorrow.midnight, start: 60.days.ago.midnight)
def self.fetch_data(report)
DB.query(<<~SQL, end: report.end_date, start: report.start_date)
SELECT
posts.created_at::DATE AS day,
#{
Expand Down