sr

smart-ranking

NodeJS Library for smart ranking

Showing:

Popularity

Downloads/wk

2

GitHub Stars

14

Maintenance

Last Commit

8yrs ago

Contributors

3

Package

Dependencies

0

Size (min+gzip)

0.4KB

License

Type Definitions

Tree-Shakeable

No?

Categories

Readme

NodeJS library for smart ranking

Installation

npm install smart-ranking

Usage

var ratings = [
    { votes: [3,2,1], id:'Batman' },
    { votes: [1,2,3,4,5], id:'Robin' }
];

var Ranking = require('smart-ranking');

var bayesianScore = Ranking.bayesian(ratings);
var imdbScore = Ranking.imdb(ratings);

Input

Three different inputs are accepted:

// Input 1: raw votes
var ratings = [
    { votes: [3,2,1],     id:'Batman' },
    { votes: [1,2,3,4,5], id:'Robin'  }
];
// Input 2: vote sum & total (with id object)
var ratings = [
    { sumVotes: 10, numVotes:3, _id:{ id:'Batman' } },
    { sumVotes: 10, numVotes:3, _id:{ id:'Robin'  } }
];
// Input 3: vote sum & total (with id string)
var ratings = [
    { sumVotes: 10, numVotes:3, id:'Batman' },
    { sumVotes: 10, numVotes:3, id:'Robin'  }
];

Output

Two different outputs are available:

    // Output 1: returns an object
    var imdbScore = Ranking.imdb(ratings);
    imdbScore = {
        "Item 1":{"id":"Item 1","sumVotes":6,"numVotes":3,"avgRating":2,"score":2.3125},
        "Item 2":{"id":"Item 2","sumVotes":15,"numVotes":5,"avgRating":3,"score":2.859375},
        "avgRatings":2.625,
        "avgVotes":4
    }
    // Output 2: returns an array
    var imdbScore = Ranking.imdb(ratings, true);
    imdbScore = [
        {"id":"Item 1","sumVotes":6,"numVotes":3,"avgRating":2,"score":2.3125},
        {"id":"Item 2","sumVotes":15,"numVotes":5,"avgRating":3,"score":2.859375}
    ]

API

Ranking.imdb(ratings, returnArray, min);

Parameters:

  • ratings (Array)
    • Array with data ** See Input (above)
  • returnArray (boolean)
    • If true, the method returns an Array
    • If false, the method returns an object ** See Output (above)
  • min (integer)
    • Number of reviews required to be listed

Ranking.bayesian(ratings, returnArray);

Parameters:

  • ratings (Array)
    • Array with data
    • See Input (above)
  • returnArray (boolean)
    • If true, the method returns an Array
    • If false, the method returns an object ** See Output (above)

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100