From: Dessalines Date: Sun, 21 Apr 2019 17:15:40 +0000 (-0700) Subject: Fixing ranking algorithm. X-Git-Url: http://these/git/readmes/static/%7B%60/css/themes/%7BimageUploadUrl%7D?a=commitdiff_plain;h=93957c781e3d0e1a97f6cdca2a3505da9374892e;p=lemmy.git Fixing ranking algorithm. --- diff --git a/README.md b/README.md index 64dd9146..7b44f743 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,9 @@ This is a **very early beta version**, and a lot of features are currently broke - Server is written in rust. - Front end is `~80kB` gzipped. +## About +Lemmy is similar to sites like Reddit, lobste.rs, Raddle, or Hacker News. Behind the scenes, it is very different; It allows anyone to run a server (instance), and all instances are federated, and similar to Mastodon, connected to the same universe. For a link aggregator, this means a user registered on one server can subscribe to forums on any other Lemmy instance, and can have discussions with users registered on any number of instances. + ## Why's it called Lemmy? - Lead singer from [motorhead](https://invidio.us/watch?v=pWB5JZRGl0U). - The old school [video game](https://en.wikipedia.org/wiki/Lemmings_(video_game)). diff --git a/docs/ranking.md b/docs/ranking.md index 34348c30..608b5484 100644 --- a/docs/ranking.md +++ b/docs/ranking.md @@ -12,14 +12,15 @@ The [Hacker New's ranking algorithm](https://medium.com/hacking-and-gonzo/how-ha ## My Algorithm ``` -Rank = ScaleFactor * sign(3 + Score) * log(abs(3 + Score)) / (Time + 2)^Gravity +Rank = ScaleFactor * log(Max(1, 3 + Score)) / (Time + 2)^Gravity Score = Upvotes - Downvotes Time = time since submission (in hours) Gravity = Decay gravity, 1.8 is default ``` -- Add 3 to the score, so that even minimally downvoted comments will be affected by time decay. Otherwise all new comments would stay at zero, near the bottom. +- Use Max(1, score) to make sure all comments are affected by time decay. +- Add 3 to the score, so that everything that has less than 3 downvotes will seem new. Otherwise all new comments would stay at zero, near the bottom. - The sign and abs of the score are necessary for dealing with the log of negative scores. - A scale factor of 10k gets the rank in integer form. diff --git a/server/migrations/2019-03-30-212058_create_post_view/up.sql b/server/migrations/2019-03-30-212058_create_post_view/up.sql index 3a509e29..17dc8604 100644 --- a/server/migrations/2019-03-30-212058_create_post_view/up.sql +++ b/server/migrations/2019-03-30-212058_create_post_view/up.sql @@ -5,7 +5,7 @@ create or replace function hot_rank( returns integer as $$ begin -- hours_diff:=EXTRACT(EPOCH FROM (timezone('utc',now()) - published))/3600 - return floor(10000*sign(3+score)*log(abs(3+score)) / power(((EXTRACT(EPOCH FROM (timezone('utc',now()) - published))/3600) + 2), 1.8))::integer; + return floor(10000*log(greatest(1,score+3)) / power(((EXTRACT(EPOCH FROM (timezone('utc',now()) - published))/3600) + 2), 1.8))::integer; end; $$ LANGUAGE plpgsql; diff --git a/ui/src/utils.ts b/ui/src/utils.ts index 70b6e846..3a8e2576 100644 --- a/ui/src/utils.ts +++ b/ui/src/utils.ts @@ -21,7 +21,7 @@ export function hotRank(comment: Comment): number { let now: Date = new Date(); let hoursElapsed: number = (now.getTime() - date.getTime()) / 36e5; - let rank = (10000 * Math.sign(3+comment.score) * Math.log10(Math.abs(3+comment.score))) / Math.pow(hoursElapsed + 2, 1.8); + let rank = (10000 * Math.log10(Math.max(1, 3 + comment.score))) / Math.pow(hoursElapsed + 2, 1.8); // console.log(`Comment: ${comment.content}\nRank: ${rank}\nScore: ${comment.score}\nHours: ${hoursElapsed}`);