Skip to content

Instantly share code, notes, and snippets.

@the1mills
Created November 16, 2015 23:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save the1mills/153eded6944e7c414886 to your computer and use it in GitHub Desktop.
Save the1mills/153eded6944e7c414886 to your computer and use it in GitHub Desktop.
Ranking algo for social media feed
// So this is the model I have now (in JavaScript):
var GRACE_PERIOD_MILLIS = 259200000; // 3 days worth of milliseconds
function getRanking(post) {
var millis = post.dateCreated.getTime(); //get milliseconds since post was first posted
var currentMillis = Date.now(); //get current milliseconds since epoch
var diff1 = ((millis + GRACE_PERIOD_MILLIS) / currentMillis) - 1;
var diff2 = currentMillis- millis;
return (diff1) / (post.upvotes.length + 1) + (post.upvotes.length + 1) / (diff2);
}
// but we could do this instead using Math.log:
function getRanking(post) {
var millis = post.dateCreated.getTime(); //get milliseconds since post was first posted
var currentMillis = Date.now(); //get current milliseconds since epoch
var diff1 = ((millis + GRACE_PERIOD_MILLIS) / currentMillis) - 1;
var diff2 = currentMillis- millis;
return (diff1) / (post.upvotes.length + 1) + Math.log(post.upvotes.length + 1) / (diff2); //use the natural log for weight
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment