0

I am using this algorithm based of Reddit and want to change it so it shows rising posts rather than hot. Which number do I change so that the time between posting and now have a greater influence on the returned score? I have tried changing a few numbers but still am not getting anywhere

Thanks heaps

function calculate_rank_sum($score, $created_at) {

     $order = log10(max(abs($score), 1));

     if ( $score > 0 ) {
        $sign = 1;
     } elseif ( $score < 0 ) {
        $sign = -1; 
     } else {
        $sign = 0;
     }

     $seconds = intval(($created_at - mktime(0, 0, 0, 1, 1, 1970))/86400);

     $long_number = ($order + $sign) * ($seconds / 45000);

     return round($long_number, 7);
}
MackieeE
  • 11,751
  • 4
  • 39
  • 56
Matt Ellwood
  • 105
  • 1
  • 13
  • Define rising? Also `$sign = ($score > 0) - ($score < 0);` is better (not branched, see http://stackoverflow.com/questions/315306/is-if-expensive). Is this snippet from some kind of Reddit code-base (I did not knew it was open source)? Do you modified it already or is this the 'real' algorithm? – Jori Feb 03 '14 at 09:34
  • @Jori Yes, Reddit is open source: http://github.com/reddit/reddit However, reddit is not built in PHP. It looks like he took the source from here: https://gist.github.com/zeuxisoo/882820 – Sean Feb 03 '14 at 09:41
  • Hm. But the whole code does not make sense to begin with (who wrote this?). Isn't `mktime(0, 0, 0, 1, 1, 1970)` the same as `time()`? And why call it `$seconds` if you are actually calculating the amount of days after January 1 1970 00:00:00 GMT (Unix Epoch)? And then just divide it by `45000`, so things will become more important after they are long gone? – Jori Feb 03 '14 at 09:52

2 Answers2

0

This is the line which essentially calculates the score.

$long_number = ($order + $sign) * ($seconds / 45000);

If you wanted the time created to have a larger impact, I'd suggest reducing 45000, and/or offsetting ($order + $sign). This is a forumla which will require a lot of fine tuning to get it exactly the way you want it, so the best thing I'd suggest is to perform a lot of unit tests, and perform a lot of tweaks.

Sean
  • 2,278
  • 1
  • 24
  • 45
0

Your formula is wrong:

($order + $sign) * ($seconds / 45000)

You've added parentheses that should not be there. If you look at https://gist.github.com/zeuxisoo/882820, it should be:

$order + $sign * $seconds / 45000

But even that was based on the old reddit algorithm which was later fixed to:

sign * order + seconds / 45000

You can decrease 45000 to give the time component more weight.

wisbucky
  • 33,218
  • 10
  • 150
  • 101