npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ihs7/ts-elo

v1.0.0

Published

Elo ranking system implemented in TypeScript

Downloads

39

Readme

@ihs7/ts-elo

ELO calculation library in TypeScript

Supports heads up, team and multiplayer calculations

Installing ts-elo

npm i @ihs7/ts-elo

Two player scenario

Create and calculate match between two players

  • Player 1 has 1200 rating and wins
  • Player 2 has 1320 rating and loses
  • Get results
const match = new Duel();
match.addPlayer(new Player("player-identifier-1", 1200), true);
match.addPlayer(new Player("player-identifier-2", 1320), false);
const results = await match.calculate();

Three player scenario

Create a match between three players

  • Player 1 has 1280 rating and places 1st
  • Player 2 has 1300 rating and places 2nd
  • Player 3 has 1220 rating and places 3rd
  • Get results
const match = new FreeForAll();
match.addPlayer(new Player("player-identifier-1", 1280), 3);
match.addPlayer(new Player("player-identifier-2", 1300), 2);
match.addPlayer(new Player("player-identifier-3", 1220), 1);
const results = await match.calculate();

The calculations is based on:

  • Player 1 won Player 2 and Player 3
  • Player 2 won Player 3 and lost to Player 1
  • Player 3 lost to Player 1 and Player 2

Two versus two scenario

  • Team 1 consists of Player 1 with 1230 ELO and Player 2 with 1260 ELO
  • Team 2 consists of Player 3 with 1120 ELO and Player 4 with 1410 ELO
  • Team 1 wins Team 2
  • Get results
const match = new TeamMatch();
const team1 = match.addTeam("1", 2);
team1.addPlayer(new Player("player-identifier-1", 1230));
team1.addPlayer(new Player("player-identifier-2", 1260));
const team2 = match.addTeam("2", 1);
team2.addPlayer(new Player("player-identifier-3", 1120));
team2.addPlayer(new Player("player-identifier-4", 1410));
const results = await match.calculate();

Each team has a rating which is an average of the team members.

  • Team 1 has a rating of 1245 ((1230+1260)/2)
  • Team 2 has a rating of 1265 ((1120+1410)/2)

Calculation Strategies in Team Matches

By default when creating TeamMatch, the results are calculated using average team rating as if the teams were individuals. However, you can also use WEIGHTED_TEAMS strategy to have the results calculated based on individual player ratings within the team.

  • Team 1 consists of Player 1 with 1000 ELO and Player 2 with 1400 ELO
  • Team 2 consists of Player 3 with 1200 ELO and Player 4 with 1600 ELO
  • Team 1 wins Team 2
  • Get results
const match = new TeamMatch();
const team1 = match.addTeam("1", 2);
team1.addPlayer(new Player("player-identifier-1", 1000));
team1.addPlayer(new Player("player-identifier-2", 1400));
const team2 = match.addTeam("2", 1);
team2.addPlayer(new Player("player-identifier-3", 1200));
team2.addPlayer(new Player("player-identifier-4", 1600));
const results = await match.calculate({
  calculationStrategy: CalculationStrategy.WEIGHTED_TEAMS,
});

Each team has a rating which is an average of the team members. This is used as a basis of calculation:

  • Team 1 has a rating of 1200 ((1000+1400)/2)
  • Team 2 has a rating of 1400 ((1200+1600)/2)

Then after calculating the expected score of each player in the team, the results are calculated based on individual player ratings within the team. For example, Player 1 has a weight of 1000/(1000+1400) ~ 0.4167 and Player 2 has a weight of 0.5833. The same is done for Team 2 and the ELO changes are distributed based on these weights.

With this calculation method, the players are rewarded or penalized based on their rating contribution to the team.

Get expected score between two ratings

Say you have two players, one with 1460 ELO and another with 1130 ELO, and want to know the likelihood of one winning another.

const player1 = new Player("player-identifier-1", 1460);
const player2 = new Player("player-identifier-2", 1130);
const expectedScore = player1.expectedScoreAgainst(player2);

This returns a float number and in this specific scenario the value is 0.8698499 meaning the higher ranked player is estimated to win 87% of encounters.