FIX: Change how we filter date for emotion on /filter (#1006)
This commit is contained in:
parent
4ba74511c2
commit
5ba274f7a5
|
@ -12,15 +12,18 @@ module DiscourseAi
|
||||||
&.constraints
|
&.constraints
|
||||||
&.flat_map(&:children)
|
&.flat_map(&:children)
|
||||||
&.find do |node|
|
&.find do |node|
|
||||||
node.is_a?(Arel::Nodes::Grouping) &&
|
node.is_a?(Arel::Nodes::BoundSqlLiteral) &&
|
||||||
node.expr.to_s.match?(/topics\.bumped_at\s*>=/)
|
node.to_sql.match?(/topics\.bumped_at\s*>=/)
|
||||||
end
|
end
|
||||||
&.expr
|
&.positional_binds
|
||||||
&.split(">=")
|
&.first if scope.to_sql.include?("topics.bumped_at >=")
|
||||||
&.last if scope.to_sql.include?("topics.bumped_at >=")
|
|
||||||
|
|
||||||
|
if scope_period.is_a?(ActiveSupport::TimeWithZone)
|
||||||
|
scope_period = "'#{scope_period.to_date}'"
|
||||||
|
else
|
||||||
# Fallback in case we can't find the scope period
|
# Fallback in case we can't find the scope period
|
||||||
scope_period ||= "CURRENT_DATE - INTERVAL '1 year'"
|
scope_period = "CURRENT_DATE - INTERVAL '1 year'"
|
||||||
|
end
|
||||||
|
|
||||||
emotion_clause = <<~SQL
|
emotion_clause = <<~SQL
|
||||||
COUNT(*) FILTER (WHERE (classification_results.classification::jsonb->'#{emotion}')::float > 0.1)
|
COUNT(*) FILTER (WHERE (classification_results.classification::jsonb->'#{emotion}')::float > 0.1)
|
||||||
|
|
Loading…
Reference in New Issue