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

Commit 5ef594a

Browse files
committed
DEV: Add group_by
1 parent 4325813 commit 5ef594a

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

config/locales/client.en.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ en:
1717
description: "The table lists a count of posts classified with a determined emotion. Classified with the model 'SamLowe/roberta-base-go_emotions'."
1818
reports:
1919
filters:
20-
filter_by:
21-
label: "Filter by"
20+
group_by:
21+
label: "Group by"
22+
sort_by:
23+
label: "Sort by"
2224

2325
js:
2426
discourse_automation:

lib/sentiment/sentiment_analysis_report.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,23 @@ class SentimentAnalysisReport
88
def self.register!(plugin)
99
plugin.add_report("sentiment_analysis") do |report|
1010
report.modes = [:sentiment_analysis]
11-
category_filter = report.filters.dig(:filter_by)
11+
category_filter = report.filters.dig(:group_by) || :category
1212
report.add_filter(
13-
"filter_by",
13+
"group_by",
1414
type: "list",
1515
default: category_filter,
1616
choices: [{ id: "category", name: "Category" }, { id: "tag", name: "Tag" }],
1717
allow_any: false,
1818
auto_insert_none_item: false,
1919
)
2020

21+
report.add_filter(
22+
"sort_by",
23+
type: "list",
24+
default: "size",
25+
choices: [{ id: "size", name: "Size" }, { id: "name", name: "Name" }],
26+
)
27+
2128
sentiment_data = DiscourseAi::Sentiment::SentimentAnalysisReport.fetch_data(report)
2229

2330
report.data = sentiment_data
@@ -33,7 +40,7 @@ def self.register!(plugin)
3340
end
3441

3542
def self.fetch_data(report)
36-
grouping = report.filters.dig(:filter_by).to_sym
43+
grouping = report.filters.dig(:group_by).to_sym
3744
threshold = 0.6
3845

3946
sentiment_count_sql = Proc.new { |sentiment| <<~SQL }

0 commit comments

Comments
 (0)