From 700e9de073222977dd42c596096a84b0f4dae4f0 Mon Sep 17 00:00:00 2001 From: Keegan George Date: Wed, 11 Dec 2024 01:15:27 +0900 Subject: [PATCH] Revert "UX: Make sentiment trends more readable in time series data (#1013)" (#1016) This reverts commit 375dd702b29a29773184d8fda57e22d246504d24. --- config/locales/server.en.yml | 4 +++- lib/sentiment/sentiment_dashboard_report.rb | 19 +++++++++++-------- .../lib/modules/sentiment/entry_point_spec.rb | 7 +++++-- 3 files changed, 19 insertions(+), 11 deletions(-) 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