ruanyf Mar 6th, 2012 3,558 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- #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)
RAW Paste Data