mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-22 12:21:18 +00:00
Fixing ranking algorithm.
This commit is contained in:
parent
811607f81a
commit
93957c781e
4 changed files with 8 additions and 4 deletions
|
@ -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)).
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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}`);
|
||||
|
||||
|
|
Loading…
Reference in a new issue