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

Commit 375dd70

Browse files
authored
UX: Make sentiment trends more readable in time series data (#1013)
Instead of a stacked chart showing a separate series for positive and negative, this PR introduces a simplification to the overall sentiment dashboard. It comprises the sentiment into a single series of the difference between `positive - negative` instead. This should allow for the data to be more easy to scan and look for trends.
1 parent 7ca21cc commit 375dd70

File tree

3 files changed

+11
-19
lines changed

3 files changed

+11
-19
lines changed

config/locales/server.en.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,9 +400,7 @@ en:
400400

401401
sentiment:
402402
reports:
403-
overall_sentiment:
404-
positive: "Positive"
405-
negative: "Negative"
403+
overall_sentiment: "Overall sentiment (Positive - Negative)"
406404
post_emotion:
407405
sadness: "Sadness 😢"
408406
surprise: "Surprise 😱"

lib/sentiment/sentiment_dashboard_report.rb

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Sentiment
55
class SentimentDashboardReport
66
def self.register!(plugin)
77
plugin.add_report("overall_sentiment") do |report|
8-
report.modes = [:stacked_chart]
8+
report.modes = [:chart]
99
threshold = 0.6
1010

1111
sentiment_count_sql = Proc.new { |sentiment| <<~SQL }
@@ -38,20 +38,17 @@ def self.register!(plugin)
3838
threshold: threshold,
3939
)
4040

41-
data_points = %w[positive negative]
42-
4341
return report if grouped_sentiments.empty?
4442

4543
report.data =
46-
data_points.map do |point|
44+
grouped_sentiments.map do |gs|
4745
{
48-
req: "sentiment_#{point}",
49-
color: point == "positive" ? report.colors[:lime] : report.colors[:purple],
50-
label: I18n.t("discourse_ai.sentiment.reports.overall_sentiment.#{point}"),
51-
data:
52-
grouped_sentiments.map do |gs|
53-
{ x: gs.posted_at, y: gs.public_send("#{point}_count") }
54-
end,
46+
color: report.colors[:lime],
47+
label: I18n.t("discourse_ai.sentiment.reports.overall_sentiment"),
48+
data: {
49+
x: gs.posted_at,
50+
y: gs.public_send("positive_count") - gs.public_send("negative_count"),
51+
},
5552
}
5653
end
5754
end

spec/lib/modules/sentiment/entry_point_spec.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,8 @@ def sentiment_classification(post, classification)
7777
sentiment_classification(pm, positive_classification)
7878

7979
report = Report.find("overall_sentiment")
80-
positive_data_point = report.data[0][:data].first[:y].to_i
81-
negative_data_point = report.data[1][:data].first[:y].to_i
82-
83-
expect(positive_data_point).to eq(1)
84-
expect(negative_data_point).to eq(-1)
80+
overall_sentiment = report.data[0][:data][:y].to_i
81+
expect(overall_sentiment).to eq(2)
8582
end
8683
end
8784

0 commit comments

Comments
 (0)