title: Social Network Ranking Algorithm
body: <p>I am trying to develop a simple ranking algorithm for a social network based on the number of likes, comments, and reposts receiving and time. I have been reading about the edge rank algorithm that facebook uses and tried to do something similar but I cannot get it right.</p>
  
  <p>The algorithm should show the popular posts now.</p>
  
  <p>Here is what i tried:</p>
  
  <pre><code>let nComments = (from c in db.Comments where c.postid == r.pageOwner.PostId select c).Count()
  
  let nReposts = (from s in db.Posts where s.RepostedFrom_postid == r.pageOwner.PostId select s).Count()
  
  let nLikes = (from u in db.UserPageRelations where u.Post_id == r.pageOwner.PostId select u).Sum(s =&gt; s.Rate)
  
  let TimeDecayFactor = ignoretime ? 1 : Math.Exp(-(DateTime.Now - Post.Date).TotalHours)
  
  let TotalEdge = (1 * nComments + 3 * nLikes + 2 * nReposts + 1) * TimeDecayFactor
  
   orderby (TotalEdge) descending
  </code></pre>
  
  <p>does anyone have a better solution?</p>