UNPKG

elo-rating

Version:

elo-rating.js is a simple utility to calculate elo ratings for Node.js

79 lines (52 loc) 2.38 kB
# elo-rating.js elo-rating.js is a simple utility to calculate elo ratings for Node.js. See [https://en.wikipedia.org/wiki/Elo_rating_system](https://en.wikipedia.org/wiki/Elo_rating_system) for more information about elo rating. # Installation ``` npm install elo-rating ``` # Usage ```javascript var EloRating = require('elo-rating'); var playerWin = false; var result = EloRating.calculate(1750, 1535, playerWin); console.log(result.playerRating) // Output: 1735 console.log(result.opponentRating) // Output: 1550 result = EloRating.calculate(1750, 1535); console.log(result.playerRating) // Output: 1754 console.log(result.opponentRating) // Output: 1531 ``` # Functions ## EloRating.ratingDifference(playerRating, opponentRating) Calculates the rating difference, capped at -400 and +400. ```javascript var EloRating = require('elo-rating'); console.log(EloRating.ratingDifference(1500, 1350)); // Output: 150 console.log(EloRating.ratingDifference(1200, 2000)); // Output: -400 ``` ## EloRating.expected(playerRating, opponentRating) Calculates the expected value for the player with the given rating if he plays against an opponent with the given rating. (0 = Loss, 0.5 = Draw, 1 = Win). ```javascript var EloRating = require('elo-rating'); console.log(EloRating.expected(1800, 1800)); // Output: 0.5 console.log(EloRating.expected(1500, 1350)); // Output: 0.70... console.log(EloRating.expected(1200, 2000)); // Output: 0.09... ``` ## EloRating.calculate(playerRating, opponentRating, playerWin = true, k = 20) Calculates the new rating for the player and his opponent. ```javascript var EloRating = require('elo-rating'); console.log(EloRating.calculate(1800, 1800)); // Output: { playerRating: 1810, opponentRating: 1790 } console.log(EloRating.calculate(1200, 1500, false)); // Output: { playerRating: 1197, opponentRating: 1503 } console.log(EloRating.calculate(1200, 1500, false, 40)); // Output: { playerRating: 1194, opponentRating: 1506 } ``` # License The MIT License (MIT) # Similar modules There are several other modules for Node.js, which provide similar functionality. Check them out as well: * https://github.com/dmamills/elo-rank * https://github.com/moroshko/elo.js * https://github.com/PhobosRising/node-arpad * https://github.com/jbrooksuk/node-elo