title: Item rankings, order by confidence using Reddit Ranking Algorithms
body: <p>I am interested to use this <a href="https://gist.github.com/91media/1478806">ranking class</a>, based off of an article by <a href="http://www.evanmiller.org/how-not-to-sort-by-average-rating.html">Evan Miller</a> to rank a table I have that has upvotes and downvotes. I have a system very similar to Stack Overflow's up/down voting system for an events site I am working on, and by using this ranking class I feel as though results will be more accurate. My question is how do I order by the function 'hotness'?</p>
  
  <pre><code>private function _hotness($upvotes = 0, $downvotes = 0, $posted = 0) {
      $s = $this-&gt;_score($upvotes, $downvotes);
      $order = log(max(abs($s), 1), 10);
  
      if($s &gt; 0) {
          $sign = 1;
      } elseif($s &lt; 0) {
          $sign = -1;
      } else {
          $sign = 0;
      }
  
      $seconds = $posted - 1134028003;
  
      return round($order + (($sign * $seconds)/45000), 7);
  }
  </code></pre>
  
  <p>I suppose each time a user votes I could have a column in my table that has the hotness data recalculated for the new vote, and order by that column on the main page. But I am interested to do this more on-the-fly incorporating the function above, and I am not sure if that is possible.</p>
  
  <p>From Evan Miller, he uses:</p>
  
  <pre><code>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 &gt; 0 
         ORDER BY ci_lower_bound DESC;
  </code></pre>
  
  <p>But I rather not do this calculation in the sql as I feel this is messy and difficult to change down the line if I utilize this code on multiple pages .etc.</p>