Created
April 24, 2012 23:13
-
-
Save alfg/2484505 to your computer and use it in GitHub Desktop.
Reddit ranking algorithm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Rewritten code from /r2/r2/lib/db/_sorts.pyx | |
from datetime import datetime, timedelta | |
from math import log | |
epoch = datetime(1970, 1, 1) | |
def epoch_seconds(date): | |
"""Returns the number of seconds from the epoch to date.""" | |
td = date - epoch | |
return td.days * 86400 + td.seconds + (float(td.microseconds) / 1000000) | |
def score(ups, downs): | |
return ups - downs | |
def hot(ups, downs, date): | |
"""The hot formula. Should match the equivalent function in postgres.""" | |
s = score(ups, downs) | |
order = log(max(abs(s), 1), 10) | |
sign = 1 if s > 0 else -1 if s < 0 else 0 | |
seconds = epoch_seconds(date) - 1134028003 | |
return round(order + sign * seconds / 45000, 7) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment