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 all 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
4 changes: 1 addition & 3 deletions config/locales/server.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,7 @@ en:

sentiment:
reports:
overall_sentiment:
positive: "Positive"
negative: "Negative"
overall_sentiment: "Overall sentiment (Positive - Negative)"
post_emotion:
sadness: "Sadness 😢"
surprise: "Surprise 😱"
Expand Down
19 changes: 8 additions & 11 deletions lib/sentiment/sentiment_dashboard_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Sentiment
class SentimentDashboardReport
def self.register!(plugin)
plugin.add_report("overall_sentiment") do |report|
report.modes = [:stacked_chart]
report.modes = [:chart]
threshold = 0.6

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

data_points = %w[positive negative]

return report if grouped_sentiments.empty?

report.data =
data_points.map do |point|
grouped_sentiments.map do |gs|
{
req: "sentiment_#{point}",
color: point == "positive" ? report.colors[:lime] : report.colors[:purple],
label: I18n.t("discourse_ai.sentiment.reports.overall_sentiment.#{point}"),
data:
grouped_sentiments.map do |gs|
{ x: gs.posted_at, y: gs.public_send("#{point}_count") }
end,
color: report.colors[:lime],
label: I18n.t("discourse_ai.sentiment.reports.overall_sentiment"),
data: {
x: gs.posted_at,
y: gs.public_send("positive_count") - gs.public_send("negative_count"),
},
}
end
end
Expand Down
7 changes: 2 additions & 5 deletions spec/lib/modules/sentiment/entry_point_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,8 @@ def sentiment_classification(post, classification)
sentiment_classification(pm, positive_classification)

report = Report.find("overall_sentiment")
positive_data_point = report.data[0][:data].first[:y].to_i
negative_data_point = report.data[1][:data].first[:y].to_i

expect(positive_data_point).to eq(1)
expect(negative_data_point).to eq(-1)
overall_sentiment = report.data[0][:data][:y].to_i
expect(overall_sentiment).to eq(2)
end
end

Expand Down
Loading