Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit 8d37984

Browse files
committed
FEATURE: Refinements to Emotion in dashboard
- Made links conditional on /filter being enabled - Added descriptions to individual reports - Made reports work with data older than 60 days
1 parent e54f2da commit 8d37984

File tree

6 files changed

+84
-24
lines changed

6 files changed

+84
-24
lines changed

assets/javascripts/discourse/components/admin-report-emotion.hbs

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,46 +6,62 @@
66
</div>
77

88
<div class="cell value today-count">
9-
<a
10-
href="{{this.filterURL}}activity-after%3A{{this.today}}%20order%3A{{this.model.type}}"
11-
>
9+
{{#if this.filterEnabled}}
10+
<a
11+
href="{{this.filterURL}}activity-after%3A{{this.today}}%20order%3A{{this.model.type}}"
12+
>
13+
{{number this.model.todayCount}}
14+
</a>
15+
{{else}}
1216
{{number this.model.todayCount}}
13-
</a>
17+
{{/if}}
1418
</div>
1519

1620
<div
1721
class="cell value yesterday-count {{this.model.yesterdayTrend}}"
1822
title={{this.model.yesterdayCountTitle}}
1923
>
20-
<a
21-
href="{{this.filterURL}}activity-after%3A{{this.yesterday}}%20order%3A{{this.model.type}}"
22-
>
24+
{{#if this.filterEnabled}}
25+
<a
26+
href="{{this.filterURL}}activity-after%3A{{this.yesterday}}%20order%3A{{this.model.type}}"
27+
>
28+
{{number this.model.yesterdayCount}}
29+
</a>
30+
{{else}}
2331
{{number this.model.yesterdayCount}}
24-
</a>
32+
{{/if}}
2533
{{d-icon this.model.yesterdayTrendIcon}}
2634
</div>
2735

2836
<div
2937
class="cell value sevendays-count {{this.model.sevenDaysTrend}}"
3038
title={{this.model.sevenDaysCountTitle}}
3139
>
32-
<a
33-
href="{{this.filterURL}}activity-after%3A{{this.lastWeek}}%20order%3A{{this.model.type}}"
34-
>
40+
{{#if this.filterEnabled}}
41+
<a
42+
href="{{this.filterURL}}activity-after%3A{{this.lastWeek}}%20order%3A{{this.model.type}}"
43+
>
44+
{{number this.model.lastSevenDaysCount}}
45+
</a>
46+
{{else}}
3547
{{number this.model.lastSevenDaysCount}}
36-
</a>
48+
{{/if}}
3749
{{d-icon this.model.sevenDaysTrendIcon}}
3850
</div>
3951

4052
<div
4153
class="cell value thirty-days-count {{this.model.thirtyDaysTrend}}"
4254
title={{this.model.thirtyDaysCountTitle}}
4355
>
44-
<a
45-
href="{{this.filterURL}}activity-after%3A{{this.lastMonth}}%20order%3A{{this.model.type}}"
46-
>
56+
{{#if this.filterEnabled}}
57+
<a
58+
href="{{this.filterURL}}activity-after%3A{{this.lastMonth}}%20order%3A{{this.model.type}}"
59+
>
60+
{{number this.model.lastThirtyDaysCount}}
61+
</a>
62+
{{else}}
4763
{{number this.model.lastThirtyDaysCount}}
48-
</a>
64+
{{/if}}
4965

5066
{{#if this.model.canDisplayTrendIcon}}
5167
{{d-icon this.model.thirtyDaysTrendIcon}}

assets/javascripts/discourse/components/admin-report-emotion.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
import Component from "@ember/component";
21
import { attributeBindings, classNames } from "@ember-decorators/component";
2+
import Component from "@ember/component";
3+
import { service } from "@ember/service";
34
import getURL from "discourse-common/lib/get-url";
45

56
@classNames("admin-report-counters")
67
@attributeBindings("model.description:title")
78
export default class AdminReportEmotion extends Component {
9+
@service siteSettings;
10+
811
get filterURL() {
912
return getURL(`/filter?q=`);
1013
}
@@ -24,4 +27,8 @@ export default class AdminReportEmotion extends Component {
2427
get lastMonth() {
2528
return moment().subtract(1, "month").format("YYYY-MM-DD");
2629
}
30+
31+
get filterEnabled() {
32+
return this.siteSettings.experimental_topics_filter;
33+
}
2734
}

assets/javascripts/discourse/controllers/admin-dashboard-sentiment.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ export default class AdminDashboardSentiment extends AdminDashboardTabController
77
return { startDate: this.startDate, endDate: this.endDate };
88
}
99

10+
get emotionFilters() {
11+
return {
12+
startDate: moment().format("YYYY-MM-DD"),
13+
endDate: moment().subtract(2, "month").format("YYYY-MM-DD"),
14+
};
15+
}
16+
1017
get emotions() {
1118
const emotions = [
1219
"admiration",

assets/javascripts/discourse/templates/admin-dashboard-sentiment.hbs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
{{#each this.emotions as |metric|}}
6161
<AdminReport
6262
@showHeader={{false}}
63+
@filters={{this.emotionFilters}}
6364
@forcedModes="emotion"
6465
@dataSourceName="emotion_{{metric}}"
6566
/>
@@ -69,4 +70,4 @@
6970
</div>
7071
</div>
7172
</div>
72-
</div>
73+
</div>

config/locales/server.en.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,60 +117,88 @@ en:
117117
yaxis: "Date"
118118
emotion_admiration:
119119
title: 🤩 Admiration
120+
description: "Posts classified with the emotion admiration via AI, using the model 'SamLowe/roberta-base-go_emotions'."
120121
emotion_amusement:
121122
title: 😄 Amusement
123+
description: "Posts classified with the emotion amusement via AI, using the model 'SamLowe/roberta-base-go_emotions'."
122124
emotion_anger:
123125
title: 😠 Anger
126+
description: "Posts classified with the emotion anger via AI, using the model 'SamLowe/roberta-base-go_emotions'."
124127
emotion_annoyance:
125128
title: 😒 Annoyance
129+
description: "Posts classified with the emotion annoyance via AI, using the model 'SamLowe/roberta-base-go_emotions'."
126130
emotion_approval:
127131
title: 👍 Approval
132+
description: "Posts classified with the emotion approval via AI, using the model 'SamLowe/roberta-base-go_emotions'."
128133
emotion_caring:
129134
title: 🤗 Caring
135+
description: "Posts classified with the emotion caring via AI, using the model 'SamLowe/roberta-base-go_emotions'."
130136
emotion_confusion:
131137
title: 😕 Confusion
138+
description: "Posts classified with the emotion confusion via AI, using the model 'SamLowe/roberta-base-go_emotions'."
132139
emotion_curiosity:
133140
title: 🤔 Curiosity
141+
description: "Posts classified with the emotion curiosity via AI, using the model 'SamLowe/roberta-base-go_emotions'."
134142
emotion_desire:
135143
title: 😍 Desire
144+
description: "Posts classified with the emotion desire via AI, using the model 'SamLowe/roberta-base-go_emotions'."
136145
emotion_disappointment:
137146
title: 😞 Disappointment
147+
description: "Posts classified with the emotion disappointment via AI, using the model 'SamLowe/roberta-base-go_emotions'."
138148
emotion_disapproval:
139149
title: 👎 Disapproval
150+
description: "Posts classified with the emotion disapproval via AI, using the model 'SamLowe/roberta-base-go_emotions'."
140151
emotion_disgust:
141152
title: 🤢 Disgust
153+
description: "Posts classified with the emotion disgust via AI, using the model 'SamLowe/roberta-base-go_emotions'."
142154
emotion_embarrassment:
143155
title: 😳 Embarrassment
156+
description: "Posts classified with the emotion embarrassment via AI, using the model 'SamLowe/roberta-base-go_emotions'."
144157
emotion_excitement:
145158
title: 🤪 Excitement
159+
description: "Posts classified with the emotion excitement via AI, using the model 'SamLowe/roberta-base-go_emotions'."
146160
emotion_fear:
147161
title: 😨 Fear
162+
description: "Posts classified with the emotion fear via AI, using the model 'SamLowe/roberta-base-go_emotions'."
148163
emotion_gratitude:
149164
title: 🙏 Gratitude
165+
description: "Posts classified with the emotion gratitude via AI, using the model 'SamLowe/roberta-base-go_emotions'."
150166
emotion_grief:
151167
title: 😢 Grief
168+
description: "Posts classified with the emotion grief via AI, using the model 'SamLowe/roberta-base-go_emotions'."
152169
emotion_joy:
153170
title: 😊 Joy
171+
description: "Posts classified with the emotion joy via AI, using the model 'SamLowe/roberta-base-go_emotions'."
154172
emotion_love:
155173
title: ❤️ Love
174+
description: "Posts classified with the emotion love via AI, using the model 'SamLowe/roberta-base-go_emotions'."
156175
emotion_nervousness:
157176
title: 😰 Nervousness
177+
description: "Posts classified with the emotion nervousness via AI, using the model 'SamLowe/roberta-base-go_emotions'."
158178
emotion_neutral:
159179
title: 😐 Neutral
180+
description: "Posts classified with the emotion neutral via AI, using the model 'SamLowe/roberta-base-go_emotions'."
160181
emotion_optimism:
161182
title: 🌟 Optimism
183+
description: "Posts classified with the emotion optimism via AI, using the model 'SamLowe/roberta-base-go_emotions'."
162184
emotion_pride:
163185
title: 🦁 Pride
186+
description: "Posts classified with the emotion pride via AI, using the model 'SamLowe/roberta-base-go_emotions'."
164187
emotion_realization:
165188
title: 💡 Realization
189+
description: "Posts classified with the emotion realization via AI, using the model 'SamLowe/roberta-base-go_emotions'."
166190
emotion_relief:
167191
title: 😌 Relief
192+
description: "Posts classified with the emotion relief via AI, using the model 'SamLowe/roberta-base-go_emotions'."
168193
emotion_remorse:
169194
title: 😔 Remorse
195+
description: "Posts classified with the emotion remorse via AI, using the model 'SamLowe/roberta-base-go_emotions'."
170196
emotion_sadness:
171197
title: 😭 Sadness
198+
description: "Posts classified with the emotion sadness via AI, using the model 'SamLowe/roberta-base-go_emotions'."
172199
emotion_surprise:
173200
title: 😲 Surprise
201+
description: "Posts classified with the emotion surprise via AI, using the model 'SamLowe/roberta-base-go_emotions'."
174202

175203
discourse_ai:
176204
ai_artifact:

lib/sentiment/emotion_dashboard_report.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@ class EmotionDashboardReport
66
def self.register!(plugin)
77
Emotions::LIST.each do |emotion|
88
plugin.add_report("emotion_#{emotion}") do |report|
9-
query_results = DiscourseAi::Sentiment::EmotionDashboardReport.fetch_data
10-
report.data = query_results.pop(30).map { |row| { x: row.day, y: row.send(emotion) } }
11-
report.prev30Days =
12-
query_results.take(30).reduce(0) { |sum, row| sum + row.send(emotion) }.to_i
9+
query_results = DiscourseAi::Sentiment::EmotionDashboardReport.fetch_data(report)
10+
report.data = query_results.map { |row| { x: row.day, y: row.send(emotion) } }
11+
if report.facets.include?(:prev_period) && query_results.length > 30
12+
report.prev30Days = query_results[31..60].sum { |row| row.send(emotion) }
13+
end
1314
end
1415
end
1516

16-
def self.fetch_data
17-
DB.query(<<~SQL, end: Time.now.tomorrow.midnight, start: 60.days.ago.midnight)
17+
def self.fetch_data(report)
18+
DB.query(<<~SQL, end: report.end_date, start: report.start_date)
1819
SELECT
1920
posts.created_at::DATE AS day,
2021
#{

0 commit comments

Comments
 (0)