• Stars
    star
    374
  • Rank 114,346 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 13 years ago
  • Updated about 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Famous sorting algorithms based on vote popularity and time implemented for nodejs

decay

npm status build status dependency status coverage status

This library houses 3 popularity estimating algorithms employed by bigger news sites used to sort for best content:

  1. wilsonScore - Reddit's best comment scoring system
  2. redditHot - Reddit's hot post scoring system for news posts
  3. hackerHot - Hackernews' scoring system

Wilson score equation

Algorithms may cause scores to decay based on distance to post time.

1. Decaying algorithms

Algorithms that are designed to decay based on time needs continual recomputation of scores. An example of doing so would be keeping track of, and periodically computing the score(s) required in a node process on a set of suitable candidates:

var decay = require('decay')
  , hotScore = decay.redditHot();

setInterval(function () {
  candidates = []; // perhaps get recent posts saved in db here
  candidates.forEach(function (c) {
    c.score = hotScore(c.upVotes, c.dnVotes, c.date);
    // save so that next GET /entry/ gets an updated ordering
    save(c);
  });
}, 1000 * 60 * 5); // run every 5 minutes, say

2. Non-decaying algorithms

Algorithms that produce a time agnostic popularity score is typically good for comments. For best results, simply recompute the score at every new vote:

var decay = require('decay')
  , wilsonScore = decay.wilsonScore();

// assume req.entry is the item being voted on
app.post('/entry/upvote', middleWare, function (req, res) {
  // call wilsonScore with ups, downs to recompute
  req.entry.score = wilsonScore(req.entry.upVotes + 1, req.entry.dnVotes);

  // save new score in database so that new pageviews sort
  save(req.entry);
});

Usage

Decay exports 3 scoring function factories.

Two of these algorithms decay with time, and the other is based purely on statistical popularity.

// 1. zero decay
var wilsonScore = decay.wilsonScore(zScore);
var score = wilsonScore(upVotes, downVotes);

// 2. decays
var redditHotScore = decay.redditHot(halflife);
var score = redditHotScore(upVotes, downVotes, date);

// 3. decays
var hackerHotScore = decay.hackerHot(gravity);
var score = hackerHotScore(upVotes, date);

Parameter Explanation

1. Wilson Score

AKA Reddit's Best comment sorting system. Source

Statistically, it is the lower bound of the Wilson Score interval at the alpha level based on supplied Z score.

The optional zScore parameter can be passed as to the exported wilsonScore factory. The Z score is a statistical value which roughly means how many standard deviations of safety you want, so it maps directly onto the confidence level of the Wilson Score interval.

It will default to z=1.96 if left out, representing a 95% confidence level in the lower bound. Otherwise, values through 1.0 (69%), to 3.3 (99.9%) good alternatives.

2. Reddit Hot Sort

Based on the difference between ups/downs, and decays with time. Causes hive mind effects in large crowds.

An optional halflife parameter can be passed to the exported redditHot factory. The half-life defaults to 45000 [s]. For info on the effects on this parameter read the original blog post about it. See also the canonical reddit source version.

3. HackerNews Hot Sort

Based on simply the amount of upvotes, and decays with time. Prone to advertising abuse.

An optional gravity parameter (defaulting to 1.8) can be passed to the exported hackerHot factory. For info on the effects of this parameter read the original blog post about it.

Installation

$ npm install decay

License

MIT-Licensed. See LICENSE file for details.

More Repositories

1

muslrust

Docker environment for building musl based static linux rust binaries
Rust
946
star
2

sdp-transform

A simple parser/writer for the Session Description Protocol
JavaScript
324
star
3

webapp-rs

Rust microservice setup with postgres, and diesel + rocket in docker
Rust
58
star
4

logule

A multi-transport, peer-dependent logging library for nodejs - UNMAINTAINED
JavaScript
35
star
5

symlink

npm link helper for npm@^2
JavaScript
33
star
6

modul8

NO LONGER MAINTAINED - browserify is too similar and is better (see issues)
JavaScript
22
star
7

loggerv

A minimalistic stdout/stderr logger for rust
Rust
21
star
8

whyq

jq compatible yq implementation in rust
Rust
17
star
9

tap-pessimist

A tap consumer that filters on failed tests
JavaScript
15
star
10

diesel-cli

Minimal docker image with disel cli for migrations
Makefile
14
star
11

npm-graph

Prints a dependency graph of modules that is actually required
JavaScript
14
star
12

badgify

Rebuild readme markdown badges from package.json
JavaScript
13
star
13

cleverbot-irc

An IRC bot that defers to Cleverbot.
JavaScript
11
star
14

dotfiles

Symlinked dotfiles
Shell
11
star
15

blog-docker

Git and Markdown powered, containerised blog experiment
Rust
10
star
16

shipcat

fork mirror of shipcat up until july'21 since babylonhealth closed it soon after
Rust
10
star
17

jenq

Query jenkins job history or console output from a terminal
Rust
8
star
18

irc-stream

A duplex streaming IRC bot library built on top of `irc`
JavaScript
7
star
19

zalgolize

Uniform-clustered zalgolizer
JavaScript
6
star
20

tub

Lax streaming tap parser
JavaScript
6
star
21

provision

Arch Linux + Mac provisioning scripts
Shell
6
star
22

topiary

Produce pretty representations of tree-structured objects
JavaScript
6
star
23

magic-forest

CPU bound benchmarking of languages using the magic forest problem
Fortran
6
star
24

tournament.hs

Tournament related algorithms in Haskell
Haskell
6
star
25

wolfram-irc

An IRC bot that defers to Wolfram Alpha
JavaScript
6
star
26

dye

Minimalistic terminal coloring library
JavaScript
5
star
27

bandage

Simple generator based test library
JavaScript
4
star
28

trials

Statistical trial generator
JavaScript
4
star
29

yr-cli

Fetch specific weather forecasts from your terminal
JavaScript
4
star
30

confortable

Makes nodejs config location a little more.. pleasant.
JavaScript
3
star
31

splitter

Stream split library using new streams (node >= 0.10)
JavaScript
3
star
32

vitae

Personal HTML5 CV
HTML
3
star
33

quadratic

Quadratic reciprocity and the Jacobi Symbol for rust
Rust
3
star
34

facemaulers

face maulers 2018-2021
Just
3
star
35

gu

Streaming bot makers library with regex handlers
JavaScript
3
star
36

fsx

Simple recursive file and directory reader using synchronous node fs calls
JavaScript
2
star
37

.textadept

JavaScript and CoffeeScript settings for the textadept editor (updated at v4.2)
Lua
2
star
38

kubecon2022

kube-rs office hour slides
2
star
39

food

Food framework for future fulfilment
JavaScript
2
star
40

sulfur

Absorb log smells in your application
JavaScript
2
star
41

mumble-bot

Experiment with using the mumble client
JavaScript
2
star
42

curvefever-bot

A curvefever signup and match making bot for your chat channel
JavaScript
2
star
43

icebreaker

Deus Ex style ICE breaker web component
HTML
1
star
44

combustion

A primitive, but efficient micro-templating javascript engine
JavaScript
1
star
45

m8-templation

NOT MAINTAINED. See combustion instead.
JavaScript
1
star
46

m8-mongoose

NOT MAINTAINED. Bad/hard idea to get right. Not worth it.
CoffeeScript
1
star
47

linkr-components

Polymer component experiments for a personal link sharing site
HTML
1
star
48

deus-login

Deus Ex styled login component
HTML
1
star
49

unitednationsoftheworld

An updated and complete Nations of the World song ala Animaniacs
JavaScript
1
star
50

kubecon2020

Talk for KubeCon 2020
JavaScript
1
star
51

smell

Smelly log emitter
JavaScript
1
star
52

curvefever-stats

A statistics library and match maker for the curvefever game
JavaScript
1
star
53

tl-datademo

TrueLayer Data API test app.
Rust
1
star
54

posts

blog posts for new blog
1
star
55

jquery-timeslider

The easier, keyboard friendly way to pick the time of day.
JavaScript
1
star
56

flight-stream

A readable stream that tracks nearby aircrafts.
JavaScript
1
star
57

mddocs

A simple doc generator for gh-pages when writing documentation in markdown
JavaScript
1
star