Skip to content

Instantly share code, notes, and snippets.

@zeuxisoo
Created March 23, 2011 09:06
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zeuxisoo/882820 to your computer and use it in GitHub Desktop.
Save zeuxisoo/882820 to your computer and use it in GitHub Desktop.
Reddit Ranking Algorithms in PHP
<?php
// Zeuxis Lo
// Created at 2011-03-23 05:05 PM
date_default_timezone_set("Asia/Hong_Kong");
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);
}
function confidence($ups, $downs) {
if ($ups + $downs == 0) {
return 0;
}else{
$n = $ups + $downs;
if ($n == 0) return 0;
$z = 1.0;
$phat = (float)$ups / $n;
return sqrt($phat+$z*$z/(2*$n)-$z*(($phat*(1-$phat)+$z*$z/(4*$n))/$n))/(1+$z*$z/$n);
}
}
echo calculate_rank_sum(10, time()), "\n";
echo confidence(10, 0), "\n";
?>
@rockyraccoon
Copy link

Also, is there an easy way to make the time decay faster?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment