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

haxelo

v1.0.1

Published

simple libary to calculate Elo rating changes

Downloads

14

Readme

HaxElo.js

A simple library to calculate Elo rating changes for teams and individual players. Initially made for Haxball, but can be used in any sort of Elo rating system.

Installation

To install HaxElo.js, you can use npm:

npm install haxelo

Usage

Node.js To use the library in a Node.js project, require it as follows:

const HaxElo = require('haxelo');

// Team Elo Change Example
const red = [1200, 1300, 1400]; // Elo ratings for the red team
const blue = [1100, 1000, 900]; // Elo ratings for the blue team
const score = 1; // Red wins
const factor = 32; // K factor

const result = HaxElo.teamEloChange(red, blue, score, factor);
console.log(result); // Output: { redChange: 13, blueChange: -13 }

// Player Elo Change Example
const red = 1500;
const blue = 1400;
const score = 1; // red wins
const factor = 32; // K factor

const result = HaxElo.playerEloChange(playerA, playerB, score, factor);
console.log(result); // Output: { redChange: 10, blueChange: -10 }

If you want to add it in the web you can just copy the following code:

const HaxElo = (() => {
    function teamEloChange(red, blue, score, factor) {
        if (red.length !== blue.length) throw new Error("Both teams must have the same size.");
        var w = red.reduce((a, x) => x + a, 0) / red.length;
        var l = blue.reduce((a, x) => x + a, 0) / blue.length;
        var E_w = 1 / (1 + Math.pow(10, (l - w) / 400));
        var E_l = 1 / (1 + Math.pow(10, (w - l) / 400));
        var S_w, S_l;
        if (score == 1) {
            S_w = 1;
            S_l = 0;
        }
        else if (score == 2) {
            S_w = 0;
            S_l = 1;
        }
        else if (score == 0) {
            S_w = 0.5;
            S_l = 0.5;
        }
        else {
            throw new Error("Score must be 0, 1 or 2.");
        }
        var result = { redChange: Math.round(factor * (S_w - E_w)), blueChange: Math.round(factor * (S_l - E_l)) };
        return result;
    }

    function playerEloChange(red, blue, score, factor) {
        var E_a = 1 / (1 + Math.pow(10, (blue - red) / 400));
        var E_b = 1 / (1 + Math.pow(10, (red - blue) / 400));
        var S_a, S_b;
        if (score === 1) {
            S_a = 1;
            S_b = 0;
        }
        else if (score === 2) {
            S_a = 0;
            S_b = 1;
        }
        else {
            S_a = 0.5;
            S_b = 0.5;
        }
        var result = { redChange: Math.round(factor * (S_a - E_a)), blueChange: Math.round(factor * (S_b - E_b)) };
        return result;
    }

    return {
        teamEloChange: teamEloChange,
        playerEloChange: playerEloChange
    };
})();

Contributions

Contributions to haxelo are welcome! Feel free to fork this repository, make changes, and submit pull requests to enhance its functionality or improve its documentation.