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

Commit 5fb1177

Browse files
authored
FEATURE: Refinements to Emotion in dashboard (#947)
* FEATURE: Refinements to Emotion in dashboard - Added descriptions to individual reports - Made reports work with data older than 60 days
1 parent ea24328 commit 5fb1177

File tree

5 files changed

+47
-27
lines changed

5 files changed

+47
-27
lines changed

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

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,47 +6,30 @@
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-
>
12-
{{number this.model.todayCount}}
13-
</a>
9+
{{number this.model.todayCount}}
1410
</div>
1511

1612
<div
1713
class="cell value yesterday-count {{this.model.yesterdayTrend}}"
1814
title={{this.model.yesterdayCountTitle}}
1915
>
20-
<a
21-
href="{{this.filterURL}}activity-after%3A{{this.yesterday}}%20order%3A{{this.model.type}}"
22-
>
23-
{{number this.model.yesterdayCount}}
24-
</a>
16+
{{number this.model.yesterdayCount}}
2517
{{d-icon this.model.yesterdayTrendIcon}}
2618
</div>
2719

2820
<div
2921
class="cell value sevendays-count {{this.model.sevenDaysTrend}}"
3022
title={{this.model.sevenDaysCountTitle}}
3123
>
32-
<a
33-
href="{{this.filterURL}}activity-after%3A{{this.lastWeek}}%20order%3A{{this.model.type}}"
34-
>
35-
{{number this.model.lastSevenDaysCount}}
36-
</a>
24+
{{number this.model.lastSevenDaysCount}}
3725
{{d-icon this.model.sevenDaysTrendIcon}}
3826
</div>
3927

4028
<div
4129
class="cell value thirty-days-count {{this.model.thirtyDaysTrend}}"
4230
title={{this.model.thirtyDaysCountTitle}}
4331
>
44-
<a
45-
href="{{this.filterURL}}activity-after%3A{{this.lastMonth}}%20order%3A{{this.model.type}}"
46-
>
47-
{{number this.model.lastThirtyDaysCount}}
48-
</a>
49-
32+
{{number this.model.lastThirtyDaysCount}}
5033
{{#if this.model.canDisplayTrendIcon}}
5134
{{d-icon this.model.thirtyDaysTrendIcon}}
5235
{{/if}}

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: 1 addition & 0 deletions
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
/>

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)