I am interested in using this rating class based on an article by Evan Miller to rank the table I have that has upvotes and downvotes. I have a system that is very similar to the up / down polling system for the event site I'm working on, and using this ranking class, I feel the results will be more accurate. My question is, how can I arrange the hotness function?
private function _hotness($upvotes = 0, $downvotes = 0, $posted = 0) { $s = $this->_score($upvotes, $downvotes); $order = log(max(abs($s), 1), 10); if($s > 0) { $sign = 1; } elseif($s < 0) { $sign = -1; } else { $sign = 0; } $seconds = $posted - 1134028003; return round($order + (($sign * $seconds)/45000), 7); }
I believe that every time a user votes, I may have a column in my table that contains the hotness data recounted for the new vote and the order for that column on the main page. But I'm interested in doing this more on the fly by turning on the function above, and I'm not sure if this is possible.
From Evan Miller, he uses:
SELECT widget_id, ((positive + 1.9208) / (positive + negative) - 1.96 * SQRT((positive * negative) / (positive + negative) + 0.9604) / (positive + negative)) / (1 + 3.8416 / (positive + negative)) AS ci_lower_bound FROM widgets WHERE positive + negative > 0 ORDER BY ci_lower_bound DESC;
But I rather do not do this calculation in sql, as I feel it is random and difficult to change line by line if I use this code on multiple .etc pages.
sorting algorithm php ranking
Alex
source share