From f151e93615b88e49be46991c508500ba44bf15d5 Mon Sep 17 00:00:00 2001 From: evazion Date: Sun, 21 Nov 2021 18:06:41 -0600 Subject: [PATCH] votes: fix upvote ratio calculation. Old posts don't have vote records, so we can't use vote records to calculate the ratio. --- app/components/post_votes_tooltip_component.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/components/post_votes_tooltip_component.rb b/app/components/post_votes_tooltip_component.rb index b8b1f11a4..c2d971d09 100644 --- a/app/components/post_votes_tooltip_component.rb +++ b/app/components/post_votes_tooltip_component.rb @@ -21,7 +21,7 @@ class PostVotesTooltipComponent < ApplicationComponent def upvote_ratio return nil if votes.length == 0 - sprintf("(%.1f%%)", 100.0 * votes.select(&:is_positive?).length / votes.length) + sprintf("(%.1f%%)", 100.0 * post.up_score / (post.up_score + post.down_score.abs)) end def voter_name(vote)