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 @@ -46,10 +46,6 @@ def posts
u.name,
u.uploaded_avatar_id,
c.id AS category_id,
c.name AS category_name,
c.color AS category_color,
c.slug AS category_slug,
c.description AS category_description,
(CASE
WHEN (cr.classification::jsonb->'positive')::float > :threshold THEN 'positive'
WHEN (cr.classification::jsonb->'negative')::float > :threshold THEN 'negative'
Expand Down
12 changes: 1 addition & 11 deletions app/serializers/ai_sentiment_post_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class AiSentimentPostSerializer < ApplicationSerializer
:excerpt,
:sentiment,
:truncated,
:category,
:category_id,
:created_at

def avatar_template
Expand All @@ -25,14 +25,4 @@ def excerpt
def truncated
object.post_cooked.length > SiteSetting.post_excerpt_maxlength
end

def category
{
id: object.category_id,
name: object.category_name,
color: object.category_color,
slug: object.category_slug,
description: object.category_description,
}
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import DButton from "discourse/components/d-button";
import HorizontalOverflowNav from "discourse/components/horizontal-overflow-nav";
import PostList from "discourse/components/post-list";
import bodyClass from "discourse/helpers/body-class";
import categoryBadge from "discourse/helpers/category-badge";
import dIcon from "discourse/helpers/d-icon";
import replaceEmoji from "discourse/helpers/replace-emoji";
import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error";
import { getAbsoluteURL } from "discourse/lib/get-url";
import discourseLater from "discourse/lib/later";
import { clipboardCopy } from "discourse/lib/utilities";
import Category from "discourse/models/category";
import Post from "discourse/models/post";
import closeOnClickOutside from "discourse/modifiers/close-on-click-outside";
import { i18n } from "discourse-i18n";
Expand Down Expand Up @@ -111,6 +113,7 @@ export default class AdminReportSentimentAnalysis extends Component {
get transformedData() {
return this.args.model.data.map((data) => {
return {
category: Category.findById(data.category_id),
title: data.category_name || data.tag_name,
scores: [
data.positive_count,
Expand Down Expand Up @@ -139,6 +142,7 @@ export default class AdminReportSentimentAnalysis extends Component {

return this.posts.filter((post) => {
post.topic_title = replaceEmoji(post.topic_title);
post.category = Category.findById(post.category_id);

if (this.activeFilter === "all") {
return true;
Expand Down Expand Up @@ -347,7 +351,13 @@ export default class AdminReportSentimentAnalysis extends Component {
)
}}
>
<td class="sentiment-analysis-table__title">{{data.title}}</td>
<td class="sentiment-analysis-table__title">
{{#if data.category}}
{{categoryBadge data.category}}
{{else}}
{{data.title}}
{{/if}}
</td>
<td
class="sentiment-analysis-table__total-score"
>{{data.total_score}}</td>
Expand Down
13 changes: 12 additions & 1 deletion lib/sentiment/sentiment_analysis_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def self.fetch_data(report, opts)
case grouping
when :category
<<~SQL
c.id AS category_id,
c.name AS category_name,
SQL
when :tag
Expand All @@ -90,6 +91,16 @@ def self.fetch_data(report, opts)
raise Discourse::InvalidParameters
end

group_by_clause =
case grouping
when :category
"GROUP BY c.id, c.name"
when :tag
"GROUP BY tags.name"
else
raise Discourse::InvalidParameters
end

grouping_join =
case grouping
when :category
Expand Down Expand Up @@ -154,7 +165,7 @@ def self.fetch_data(report, opts)
cr.model_used = 'cardiffnlp/twitter-roberta-base-sentiment-latest' AND
(p.created_at > :report_start AND p.created_at < :report_end)
#{where_clause}
GROUP BY 1
#{group_by_clause}
#{order_by_clause}
SQL
report_start: report.start_date,
Expand Down