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

Commit 448ac67

Browse files
committed
DEV: make include subcategories checkbox operational
1 parent 09f4895 commit 448ac67

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

lib/sentiment/sentiment_analysis_report.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ def self.register!(plugin)
3131
auto_insert_none_item: false,
3232
)
3333

34-
report.add_category_filter(disabled: group_by_filter.to_sym == :tag)
34+
category_id, include_subcategories =
35+
report.add_category_filter(disabled: group_by_filter.to_sym == :tag)
3536

3637
tag_filter = report.filters.dig(:tag) || "any"
3738
tag_choices =
@@ -49,7 +50,8 @@ def self.register!(plugin)
4950
disabled: group_by_filter.to_sym == :category,
5051
)
5152

52-
sentiment_data = DiscourseAi::Sentiment::SentimentAnalysisReport.fetch_data(report)
53+
opts = { category_id: category_id, include_subcategories: include_subcategories }
54+
sentiment_data = DiscourseAi::Sentiment::SentimentAnalysisReport.fetch_data(report, opts)
5355

5456
report.data = sentiment_data
5557
report.labels = [
@@ -60,12 +62,13 @@ def self.register!(plugin)
6062
end
6163
end
6264

63-
def self.fetch_data(report)
65+
def self.fetch_data(report, opts)
6466
threshold = SENTIMENT_THRESHOLD
6567

6668
grouping = (report.filters.dig(:group_by) || GROUP_BY_FILTER_DEFAULT).to_sym
6769
sorting = (report.filters.dig(:sort_by) || SORT_BY_FILTER_DEFAULT).to_sym
6870
category_filter = report.filters.dig(:category)
71+
pp "========================== category_filter ===================================== #{category_filter} include subcategories?: #{opts[:include_subcategories]}"
6972
tag_filter = report.filters.dig(:tag)
7073

7174
sentiment_count_sql = Proc.new { |sentiment| <<~SQL }
@@ -118,6 +121,10 @@ def self.fetch_data(report)
118121
when :category
119122
if category_filter.nil?
120123
""
124+
elsif opts[:include_subcategories]
125+
<<~SQL
126+
AND (c.id = :category_filter OR c.parent_category_id = :category_filter)
127+
SQL
121128
else
122129
"AND c.id = :category_filter"
123130
end

0 commit comments

Comments
 (0)