title: Ranking algorithm using likes / dislikes and average views per day
body: <p>I'm currently ranking videos on a website using a bayesian ranking algorithm, each video has:</p>
  
  <ul>
  <li><code>likes</code></li>
  <li><code>dislikes</code></li>
  <li><code>views</code></li>
  <li><code>upload_date</code></li>
  </ul>
  
  <p>Anyone can <code>like</code> or <code>dislike</code> a video, a video is always <code>views + 1</code> when viewed and all videos have a unique <code>upload_date</code>.</p>
  
  <p><br>
  <strong>Data Structure</strong></p>
  
  <p>The data is in the following format:</p>
  
  <pre><code>|  id  |  title    |  likes  |  dislikes  |  views  |  upload_date  |
  |------|-----------|---------|------------|---------|---------------|
  |  1   | Funny Cat |    9    |     2      |   18    |  2014-04-01   |
  |  2   | Silly Dog |    9    |     2      |   500   |  2014-04-06   |
  |  3   | Epic Fail |    100  |     0      |   200   |  2014-04-07   |
  |  4   | Duck Song |    0    |     10000  |   10000 |  2014-04-08   |
  |  5   | Trololool |    25   |     30     |   5000  |  2014-04-09   |
  </code></pre>
  
  <p><br>
  <strong>Current Weighted Ranking</strong></p>
  
  <p>The following weighted ratio algorithm is used to rank and sort the videos so that the best rated are shown first.</p>
  
  <p><em>This algorithm takes into account the <a href="http://en.wikipedia.org/wiki/Bayesian_average">bayesian average</a> to give a better overall ranking.</em></p>
  
  <pre><code>Weighted Rating (WR) = ((AV * AR) + (V * R))) / (AV + V)
  
  AV = Average number of total votes
  AR = Average rating
  V  = This items number of combined (likes + dislikes)
  R  = This items current rating (likes - dislikes)
  </code></pre>
  
  <p><br>
  <strong>Example current MySQL Query</strong></p>
  
  <pre><code>SELECT id, title, (((avg_vote * avg_rating) + ((likes + dislikes) * (likes / dislikes)) ) / (avg_vote + (likes + dislikes))) AS score 
  FROM video
  INNER JOIN (SELECT ((SUM(likes) + SUM(dislikes)) / COUNT(id)) AS avg_vote FROM video) AS t1
  INNER JOIN (SELECT ((SUM(likes) - SUM(dislikes)) / COUNT(id)) AS avg_rating FROM video) AS t2
  ORDER BY score DESC
  LIMIT 10
  </code></pre>
  
  <p><em>Note: <code>views</code> and <code>upload_date</code> are not factored in.</em></p>
  
  <p><br>
  <strong>The Issue</strong></p>
  
  <p>The ranking currently works well but it seems we are not making full use of all the data at our disposal.</p>
  
  <p>Having <code>likes</code>, <code>dislikes</code>, <code>views</code> and an <code>upload_date</code> but only using two seems a waste because the <code>views</code> and <code>upload_date</code> are not factored in to account how much weight each <code>like</code> / <code>dislike</code> should have.</p>
  
  <p>For example in the <strong>Data Structure</strong> table above, items <code>1</code> and <code>2</code> both have the same amount of <code>likes</code> / <code>dislikes</code> however item <code>2</code> was uploaded more recently so it's average daily views are higher.</p>
  
  <p>Since item <code>2</code> has more likes and dislikes in a shorter time than those <code>likes</code> / <code>dislikes</code> should surely be weighted stronger?</p>
  
  <p><br>
  <strong>New Algorithm Result</strong></p>
  
  <p>Ideally the new algorithm with <code>views</code> and <code>upload_date</code> factored in would sort the data into the following result:</p>
  
  <p><em>Note: <code>avg_views</code> would equal <code>(views / days_since_upload)</code></em></p>
  
  <pre><code>|  id  |  title    |  likes  |  dislikes  |  views  |  upload_date  |  avg_views  |
  |------|-----------|---------|------------|---------|---------------|-------------|
  |  3   | Epic Fail |    100  |     0      |   200   |  2014-04-07   |     67      |
  |  2   | Silly Dog |    9    |     2      |   500   |  2014-04-06   |     125     |
  |  1   | Funny Cat |    9    |     2      |   18    |  2014-04-01   |     2       |
  |  5   | Trololool |    25   |     30     |   5000  |  2014-04-09   |     5000    |
  |  4   | Duck Song |    0    |     10000  |   10000 |  2014-04-08   |     5000    |
  </code></pre>
  
  <p><em>The above is a simple representation, with more data it gets a lot more complex.</em></p>
  
  <p><br>
  <strong>The question</strong></p>
  
  <p>So to summarise, my question is how can I factor <code>views</code> and <code>upload_date</code> into my current ranking algorithm in a style to improve the way that videos are ranked?</p>
  
  <p>I think the above example by calculating the <code>avg_views</code> is a good way to go but where should I then add that into the ranking algorithm that I have?</p>
  
  <p>It's possible that <strong>better ranking algorithms may exist</strong>, if this is the case then please provide an example of a different algorithm that I could use and state the benefits of using it.</p>