From ce8a148cbe6fce7a0cf2bbc0b0df88f9af5cf895 Mon Sep 17 00:00:00 2001 From: joshua stein Date: Tue, 15 Dec 2015 12:35:18 -0600 Subject: [PATCH] Story: don't count comments towards hotness when tag hotness mods < 0 --- app/models/story.rb | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/app/models/story.rb b/app/models/story.rb index f584b2e..c32f192 100644 --- a/app/models/story.rb +++ b/app/models/story.rb @@ -172,16 +172,17 @@ class Story < ActiveRecord::Base end def calculated_hotness - base = 0 - self.tags.select{|t| t.hotness_mod != 0 }.each do |t| - base += t.hotness_mod - end + base = self.tags.map{|t| t.hotness_mod }.sum - # give a story's comment votes some weight, but ignore the story - # submitter's own comments - cpoints = self.comments.where("user_id <> ?", self.user_id). - select(:upvotes, :downvotes).map{|c| c.upvotes + 1 - c.downvotes }. - inject(&:+).to_f * 0.5 + # give a story's comment votes some weight (unless the hotness mod is + # negative), but ignore the story submitter's own comments + if base < 0 + cpoints = 0 + else + cpoints = self.comments.where("user_id <> ?", self.user_id). + select(:upvotes, :downvotes).map{|c| c.upvotes + 1 - c.downvotes }. + inject(&:+).to_f * 0.5 + end # don't immediately kill stories at 0 by bumping up score by one order = Math.log([ (score + 1).abs + cpoints, 1 ].max, 10)