FIX: Don't divide by zero if there is no emotion data for TL group (#285)

This commit is contained in:
Roman Rizzi 2023-11-08 13:05:36 -03:00 committed by GitHub
parent b172ef11c4
commit 231cf91cc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -103,7 +103,7 @@ module DiscourseAi
y: y:
tl_emotion_avgs.sum do |tl_emotion_avg| tl_emotion_avgs.sum do |tl_emotion_avg|
tl_emotion_avg.public_send("avg_#{e}").to_i tl_emotion_avg.public_send("avg_#{e}").to_i
end / tl_emotion_avgs.size, end / [tl_emotion_avgs.size, 1].max,
} }
end, end,
} }

View File

@ -121,6 +121,19 @@ RSpec.describe DiscourseAi::Sentiment::EntryPoint do
expect(tl_01_point[:y]).to eq(emotion_1[tl_01_point[:x].downcase.to_sym]) expect(tl_01_point[:y]).to eq(emotion_1[tl_01_point[:x].downcase.to_sym])
expect(tl_234_point[:y]).to eq(emotion_2[tl_234_point[:x].downcase.to_sym]) expect(tl_234_point[:y]).to eq(emotion_2[tl_234_point[:x].downcase.to_sym])
end end
it "doesn't try to divide by zero if there are no data in a TL group" do
post_1.user.update!(trust_level: TrustLevel[3])
post_2.user.update!(trust_level: TrustLevel[3])
emotion_classification(post_1, emotion_1)
emotion_classification(post_2, emotion_2)
report = Report.find("post_emotion")
tl_01_point = report.data[0][:data].first
expect(tl_01_point[:y]).to be_zero
end
end end
end end
end end