ranking

0.5.1 • Public • Published

ranking

Build Status Coverage Status npm version

Based on: Fast and reliable ranking in datastore

IMPORTANT The current implementation does not have auto balance. Which makes inserting faster. But in cases when the game does not have a max score is necessary define in the ranking a huge number for maxScore to avoid any user reach the limit. Which works but is an annoying solution. I am working in the implementation with auto balance in a new branch. Probably the changes will affect only the internal code so the public api will still the same with no break changes.

Installation

Install via npm:

$ npm install ranking

Usage

// the example uses es6 but it works with es5 as well
import Ranking from 'ranking';
 
const ranking = new Ranking({
  maxScore: 1000000,
  branchFactor: 1000
});

add player points

ranking.addPlayerPoints({ playerId: 10, points: 28 });
// { position: 1, score: 28, playerId: 20 }

find

// by score
ranking.find({ score: { $gte: 1, $lte: 30 }, $limit: 10 });
ranking.find({ score: 20, $limit: 10 });
ranking.findOne({ score: 20 });
 
// by position
ranking.find({ position: { $gte: 1, $lte: 30 }, $limit: 10 });
ranking.find({ position: 20 });
ranking.findOne({ position: 20 });
 
// by player id
ranking.findOne({ playerId: 29 });

Contributing

It is required to use editorconfig and please write and run specs before pushing any changes:

npm test

License

Copyright (c) 2015 Max Claus Nunes. This software is licensed under the MIT License.

Readme

Keywords

Package Sidebar

Install

npm i ranking

Weekly Downloads

14

Version

0.5.1

License

none

Last publish

Collaborators

  • maxcnunes