Revert "UX: Make sentiment trends more readable in time series data (#1013)" (#1016)

This reverts commit 375dd702b2.
This commit is contained in:
Keegan George 2024-12-11 01:15:27 +09:00 committed by GitHub
parent 375dd702b2
commit 700e9de073
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 11 deletions

View File

@ -400,7 +400,9 @@ en:
sentiment: sentiment:
reports: reports:
overall_sentiment: "Overall sentiment (Positive - Negative)" overall_sentiment:
positive: "Positive"
negative: "Negative"
post_emotion: post_emotion:
sadness: "Sadness 😢" sadness: "Sadness 😢"
surprise: "Surprise 😱" surprise: "Surprise 😱"

View File

@ -5,7 +5,7 @@ module DiscourseAi
class SentimentDashboardReport class SentimentDashboardReport
def self.register!(plugin) def self.register!(plugin)
plugin.add_report("overall_sentiment") do |report| plugin.add_report("overall_sentiment") do |report|
report.modes = [:chart] report.modes = [:stacked_chart]
threshold = 0.6 threshold = 0.6
sentiment_count_sql = Proc.new { |sentiment| <<~SQL } sentiment_count_sql = Proc.new { |sentiment| <<~SQL }
@ -38,17 +38,20 @@ module DiscourseAi
threshold: threshold, threshold: threshold,
) )
data_points = %w[positive negative]
return report if grouped_sentiments.empty? return report if grouped_sentiments.empty?
report.data = report.data =
grouped_sentiments.map do |gs| data_points.map do |point|
{ {
color: report.colors[:lime], req: "sentiment_#{point}",
label: I18n.t("discourse_ai.sentiment.reports.overall_sentiment"), color: point == "positive" ? report.colors[:lime] : report.colors[:purple],
data: { label: I18n.t("discourse_ai.sentiment.reports.overall_sentiment.#{point}"),
x: gs.posted_at, data:
y: gs.public_send("positive_count") - gs.public_send("negative_count"), grouped_sentiments.map do |gs|
}, { x: gs.posted_at, y: gs.public_send("#{point}_count") }
end,
} }
end end
end end

View File

@ -77,8 +77,11 @@ RSpec.describe DiscourseAi::Sentiment::EntryPoint do
sentiment_classification(pm, positive_classification) sentiment_classification(pm, positive_classification)
report = Report.find("overall_sentiment") report = Report.find("overall_sentiment")
overall_sentiment = report.data[0][:data][:y].to_i positive_data_point = report.data[0][:data].first[:y].to_i
expect(overall_sentiment).to eq(2) 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)
end end
end end