diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index ea8aeed7..dca9e309 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -400,7 +400,9 @@ en: sentiment: reports: - overall_sentiment: "Overall sentiment (Positive - Negative)" + overall_sentiment: + positive: "Positive" + negative: "Negative" post_emotion: sadness: "Sadness 😢" surprise: "Surprise 😱" diff --git a/lib/sentiment/sentiment_dashboard_report.rb b/lib/sentiment/sentiment_dashboard_report.rb index a4e91ed0..1f2297df 100644 --- a/lib/sentiment/sentiment_dashboard_report.rb +++ b/lib/sentiment/sentiment_dashboard_report.rb @@ -5,7 +5,7 @@ module DiscourseAi class SentimentDashboardReport def self.register!(plugin) plugin.add_report("overall_sentiment") do |report| - report.modes = [:chart] + report.modes = [:stacked_chart] threshold = 0.6 sentiment_count_sql = Proc.new { |sentiment| <<~SQL } @@ -38,17 +38,20 @@ module DiscourseAi threshold: threshold, ) + data_points = %w[positive negative] + return report if grouped_sentiments.empty? report.data = - grouped_sentiments.map do |gs| + data_points.map do |point| { - 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"), - }, + 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, } end end diff --git a/spec/lib/modules/sentiment/entry_point_spec.rb b/spec/lib/modules/sentiment/entry_point_spec.rb index 0812f358..8cfc2e13 100644 --- a/spec/lib/modules/sentiment/entry_point_spec.rb +++ b/spec/lib/modules/sentiment/entry_point_spec.rb @@ -77,8 +77,11 @@ RSpec.describe DiscourseAi::Sentiment::EntryPoint do sentiment_classification(pm, positive_classification) report = Report.find("overall_sentiment") - overall_sentiment = report.data[0][:data][:y].to_i - expect(overall_sentiment).to eq(2) + 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) end end