From 375dd702b29a29773184d8fda57e22d246504d24 Mon Sep 17 00:00:00 2001 From: Keegan George Date: Wed, 11 Dec 2024 00:22:41 +0900 Subject: [PATCH] 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. --- config/locales/server.en.yml | 4 +--- lib/sentiment/sentiment_dashboard_report.rb | 19 ++++++++----------- .../lib/modules/sentiment/entry_point_spec.rb | 7 ++----- 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index dca9e309..ea8aeed7 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -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 😱" diff --git a/lib/sentiment/sentiment_dashboard_report.rb b/lib/sentiment/sentiment_dashboard_report.rb index 1f2297df..a4e91ed0 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 = [:stacked_chart] + report.modes = [:chart] threshold = 0.6 sentiment_count_sql = Proc.new { |sentiment| <<~SQL } @@ -38,20 +38,17 @@ module DiscourseAi 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 diff --git a/spec/lib/modules/sentiment/entry_point_spec.rb b/spec/lib/modules/sentiment/entry_point_spec.rb index 8cfc2e13..0812f358 100644 --- a/spec/lib/modules/sentiment/entry_point_spec.rb +++ b/spec/lib/modules/sentiment/entry_point_spec.rb @@ -77,11 +77,8 @@ RSpec.describe DiscourseAi::Sentiment::EntryPoint do 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