Class: VoteFu::Algorithms::RedditHot
- Inherits:
-
Object
- Object
- VoteFu::Algorithms::RedditHot
- Defined in:
- lib/vote_fu/algorithms/reddit_hot.rb
Overview
Reddit's "Hot" ranking algorithm
This algorithm balances popularity (vote score) with recency. Items with high scores rise quickly, but decay over time, allowing fresh content to surface.
The formula uses logarithmic scaling for votes, so the first 10 votes have the same impact as the next 100, then 1000, etc. This prevents runaway popular items from dominating forever.
Constant Summary collapse
- EPOCH =
Reddit's epoch (December 8, 2005)
Time.utc(2005, 12, 8, 7, 46, 43).to_i
Class Method Summary collapse
-
.call(voteable, gravity: 1.8) ⇒ Float
Calculate the hot score.
Instance Method Summary collapse
- #calculate ⇒ Object
-
#initialize(voteable) ⇒ RedditHot
constructor
A new instance of RedditHot.
Constructor Details
#initialize(voteable) ⇒ RedditHot
Returns a new instance of RedditHot.
33 34 35 |
# File 'lib/vote_fu/algorithms/reddit_hot.rb', line 33 def initialize(voteable) @voteable = voteable end |
Class Method Details
.call(voteable, gravity: 1.8) ⇒ Float
Calculate the hot score
29 30 31 |
# File 'lib/vote_fu/algorithms/reddit_hot.rb', line 29 def self.call(voteable, gravity: 1.8) new(voteable).calculate end |
Instance Method Details
#calculate ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/vote_fu/algorithms/reddit_hot.rb', line 37 def calculate score = @voteable.plusminus order = Math.log10([score.abs, 1].max) sign = score <=> 0 seconds = epoch_seconds # The score decays over time (45000 seconds ≈ 12.5 hours) (sign * order + seconds / 45_000.0).round(7) end |