Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,16 @@
<ul class="breadcrumb">
<li class="item report">
<LinkTo @route="adminReports" class="report-url">
{{i18n "admin.dashboard.emotion"}}
{{i18n "admin.dashboard.emotion.title"}}
</LinkTo>
<DTooltip @interactive="true">
<:trigger>
{{d-icon "circle-question"}}
</:trigger>
<:content>
<span>{{i18n "admin.dashboard.emotion.description"}}</span>
</:content>
</DTooltip>
</li>
</ul>
</div>
Expand Down
4 changes: 3 additions & 1 deletion config/locales/client.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ en:
categories:
discourse_ai: "Discourse AI"
dashboard:
emotion: "Emotion"
emotion:
title: "Emotion"
description: "The table lists a count of posts classified with a determined emotion. Classified with the model 'SamLowe/roberta-base-go_emotions'."
js:
discourse_automation:
scriptables:
Expand Down
2 changes: 1 addition & 1 deletion config/locales/server.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ en:
reports:
overall_sentiment:
title: "Overall sentiment"
description: 'The chart compares the number of posts classified as either positive or negative. These are calculated when positive or negative scores > the set threshold score. This means neutral posts are not shown. Private messages (PMs) are also excluded. Classified with "cardiffnlp/twitter-roberta-base-sentiment-latest"'
description: 'The chart compares the number of posts classified as either positive or negative. These are calculated when positive or negative scores > the set threshold score. This means neutral posts are not shown. Personal messages (PMs) are also excluded. Classified with "cardiffnlp/twitter-roberta-base-sentiment-latest"'
xaxis: "Positive(%)"
yaxis: "Date"
emotion_admiration:
Expand Down
28 changes: 20 additions & 8 deletions lib/sentiment/emotion_filter_order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,25 @@ class EmotionFilterOrder
def self.register!(plugin)
Emotions::LIST.each do |emotion|
filter_order_emotion = ->(scope, order_direction) do
scope_period =
scope
.arel
&.constraints
&.flat_map(&:children)
&.find do |node|
node.is_a?(Arel::Nodes::Grouping) &&
node.expr.to_s.match?(/topics\.bumped_at\s*>=/)
end
&.expr
&.split(">=")
&.last if scope.arel.constraints.present? &&
scope.arel.constraints.any? { |c| c.is_a?(Arel::Nodes::Grouping) }

# Fallback in case we can't find the scope period
scope_period ||= "CURRENT_DATE - INTERVAL '1 year'"

emotion_clause = <<~SQL
SUM(
CASE
WHEN (classification_results.classification::jsonb->'#{emotion}')::float > 0.1
THEN 1
ELSE 0
END
)::float / COUNT(posts.id)
COUNT(*) FILTER (WHERE (classification_results.classification::jsonb->'#{emotion}')::float > 0.1)
SQL

# TODO: This is slow, we will need to materialize this in the future
Expand All @@ -35,10 +46,11 @@ def self.register!(plugin)
AND topics.deleted_at IS NULL
AND posts.deleted_at IS NULL
AND posts.post_type = 1
AND posts.created_at >= #{scope_period}
GROUP BY
1
HAVING
#{emotion_clause} > 0.05
#{emotion_clause} > 0
SQL

scope
Expand Down