Created
November 16, 2015 23:25
-
-
Save the1mills/153eded6944e7c414886 to your computer and use it in GitHub Desktop.
Ranking algo for social media feed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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