Created
February 18, 2014 20:35
-
-
Save twfarland/9079502 to your computer and use it in GitHub Desktop.
Hot score function mysql implementation
This file contains hidden or 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
/* hot score */ | |
/* http://bibwild.wordpress.com/2012/05/08/reddit-story-ranking-algorithm/ */ | |
drop function if exists hot; | |
delimiter $$ | |
create function hot(upvotes int, downvotes int, created_time int unsigned) returns double | |
begin | |
declare s int; | |
declare ord double; | |
declare secs int; | |
declare sign int; | |
set s = upvotes - downvotes; | |
set ord = log10(greatest(abs(s), 1)); | |
set secs = created_time - 1134028003; | |
if s > 0 then set sign = 1; | |
elseif s < 0 then set sign = -1; | |
else set sign = 0; | |
end if; | |
return round((ord * sign) + (secs / 45000), 7); | |
end $$ | |
delimiter ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To fix later: scores even / close to even are all the same:
hot(x, x+1, y) == hot(x+1, x, y) == hot(x, x, y)