Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit 6ae5a6d

Browse files
committed
updates
1 parent a4e4868 commit 6ae5a6d

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

lib/sentiment/sentiment_dashboard_report.rb

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,21 @@ module Sentiment
55
class SentimentDashboardReport
66
def self.register!(plugin)
77
plugin.add_report("overall_sentiment") do |report|
8-
report.modes = [:chart]
8+
report.modes = [:stacked_chart]
99
threshold = 0.6
1010

1111
sentiment_count_sql = Proc.new { |sentiment| <<~SQL }
1212
COUNT(
1313
CASE WHEN (cr.classification::jsonb->'#{sentiment}')::float > :threshold THEN 1 ELSE NULL END
14-
) AS #{sentiment}_count
14+
)
1515
SQL
1616

1717
grouped_sentiments =
1818
DB.query(
1919
<<~SQL,
2020
SELECT
2121
DATE_TRUNC('day', p.created_at)::DATE AS posted_at,
22-
#{sentiment_count_sql.call("positive")},
23-
-#{sentiment_count_sql.call("negative")}
22+
#{sentiment_count_sql.call("positive")} - #{sentiment_count_sql.call("negative")} AS sentiment_count
2423
FROM
2524
classification_results AS cr
2625
INNER JOIN posts p ON p.id = cr.target_id AND cr.target_type = 'Post'
@@ -32,6 +31,7 @@ def self.register!(plugin)
3231
cr.model_used = 'cardiffnlp/twitter-roberta-base-sentiment-latest' AND
3332
(p.created_at > :report_start AND p.created_at < :report_end)
3433
GROUP BY DATE_TRUNC('day', p.created_at)
34+
ORDER BY 1 ASC
3535
SQL
3636
report_start: report.start_date,
3737
report_end: report.end_date,
@@ -40,17 +40,15 @@ def self.register!(plugin)
4040

4141
return report if grouped_sentiments.empty?
4242

43-
report.data =
44-
grouped_sentiments.map do |gs|
45-
{
46-
color: report.colors[:lime],
47-
label: I18n.t("discourse_ai.sentiment.reports.overall_sentiment"),
48-
data: {
49-
x: gs.posted_at,
50-
y: gs.public_send("positive_count") - gs.public_send("negative_count"),
51-
},
52-
}
53-
end
43+
report.data = {
44+
req: "overall_sentiment",
45+
color: report.colors[:lime],
46+
label: I18n.t("discourse_ai.sentiment.reports.overall_sentiment"),
47+
data:
48+
grouped_sentiments.map do |gs|
49+
{ x: gs.posted_at, y: gs.public_send("sentiment_count") }
50+
end,
51+
}
5452
end
5553
end
5654
end

spec/lib/modules/sentiment/entry_point_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ def sentiment_classification(post, classification)
7777
sentiment_classification(pm, positive_classification)
7878

7979
report = Report.find("overall_sentiment")
80-
overall_sentiment = report.data[0][:data][:y].to_i
81-
expect(overall_sentiment).to eq(2)
80+
overall_sentiment = report.data[:data][0][:y].to_i
81+
expect(overall_sentiment).to eq(0)
8282
end
8383
end
8484

0 commit comments

Comments
 (0)