Skip to content

Instantly share code, notes, and snippets.

@forrestwilkins
Created October 8, 2014 07:38
Show Gist options
  • Save forrestwilkins/273e7291849e623ab5ca to your computer and use it in GitHub Desktop.
Save forrestwilkins/273e7291849e623ab5ca to your computer and use it in GitHub Desktop.
def self.score(obj)
up_votes_weight = 0
for vote in obj.votes.up_votes # recent votes on older posts have more weight
up_votes_weight += ((vote.created_at.to_date - obj.created_at.to_date).to_i / 2) + 1
end # plus one for votes on recent posts to still get valued
_score = (up_votes_weight + (obj.comments.size / 2)) -
((obj.votes.down_votes.size.to_i * 2) + (Date.today - obj.created_at.to_date).to_i)
return _score
# also needs to check for clusters of recent votes, giving more
# weight to recent posts that are closer together in time, "hotness"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment