Story: don't count comments towards hotness when tag hotness mods < 0

This commit is contained in:
joshua stein 2015-12-15 12:35:18 -06:00
parent de176d80dd
commit ce8a148cbe

View file

@ -172,16 +172,17 @@ class Story < ActiveRecord::Base
end end
def calculated_hotness def calculated_hotness
base = 0 base = self.tags.map{|t| t.hotness_mod }.sum
self.tags.select{|t| t.hotness_mod != 0 }.each do |t|
base += t.hotness_mod
end
# give a story's comment votes some weight, but ignore the story # give a story's comment votes some weight (unless the hotness mod is
# submitter's own comments # negative), but ignore the story submitter's own comments
cpoints = self.comments.where("user_id <> ?", self.user_id). if base < 0
select(:upvotes, :downvotes).map{|c| c.upvotes + 1 - c.downvotes }. cpoints = 0
inject(&:+).to_f * 0.5 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 # don't immediately kill stories at 0 by bumping up score by one
order = Math.log([ (score + 1).abs + cpoints, 1 ].max, 10) order = Math.log([ (score + 1).abs + cpoints, 1 ].max, 10)