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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@nicolasey/glicko2

v0.0.1

Published

Système de classement Glicko-2 pour TypeScript/Bun

Downloads

15

Readme

Glicko-2 Ranking System

Une librairie TypeScript/Bun complète pour implémenter le système de classement Glicko-2, développé par Mark E. Glickman.

Qu'est-ce que Glicko-2 ?

Le système Glicko-2 est une méthode de classement pour les jeux compétitifs qui améliore le système Elo traditionnel. Contrairement à Elo, Glicko-2 prend en compte :

  • Le rating (μ) : le niveau estimé du joueur
  • La déviation du rating (φ) : l'incertitude sur le rating
  • La volatilité (σ) : la mesure dans laquelle le rating fluctue

Installation

bun install

Utilisation rapide

import { Glicko2 } from "./index.ts";

// Créer le système
const glicko = new Glicko2();

// Créer des joueurs
const alice = glicko.createPlayer("alice");
const bob = glicko.createPlayer("bob");

// Enregistrer des matchs (1 = victoire P1, 0 = victoire P2, 0.5 = nul)
glicko.recordMatch("alice", "bob", 1);
glicko.recordMatch("bob", "alice", 0); // Bob bat Alice

// Calculer les nouveaux ratings
glicko.updateRatings();

// Afficher les résultats
console.log(alice.rating);  // Nouveau rating
console.log(alice.rd);      // Nouvelle déviation
console.log(alice.volatility); // Nouvelle volatilité

API

Classe Glicko2

Création

const glicko = new Glicko2({
  tau: 0.5,              // Contrainte sur la volatilité
  defaultRating: 1500,   // Rating initial
  defaultRd: 350,        // Déviation initiale
  defaultVolatility: 0.06, // Volatilité initiale
  ratingPeriod: 86400,   // Période de rating en secondes
});

Méthodes

  • createPlayer(id, rating?, rd?, volatility?) - Créer un nouveau joueur
  • getPlayer(id) - Récupérer un joueur existant
  • recordMatch(p1, p2, result) - Enregistrer un match
  • recordMatchWithWinner(p1, p2, winnerId) - Enregistrer avec gagnant
  • updateRatings() - Calculer les nouveaux ratings
  • predict(p1, p2) - Prédire la probabilité de victoire
  • getLeaderboard() - Obtenir le classement
  • getLeaderboardWithConfidence() - Classement avec intervalles de confiance à 95%
  • applyDecay(date?) - Appliquer la décroissance aux joueurs inactifs

Classe Player

interface Player {
  id: string;           // Identifiant unique
  rating: number;       // Rating (échelle Glicko-1 : ~1500)
  rd: number;          // Déviation du rating
  volatility: number;  // Volatilité σ
  mu: number;          // Rating μ (échelle Glicko-2)
  phi: number;         // Déviation φ (échelle Glicko-2)
  lastRatingPeriod: Date; // Dernière période de rating
}

Exemple complet

import { Glicko2 } from "./index.ts";

const glicko = new Glicko2();

// Créer 3 joueurs
const p1 = glicko.createPlayer("Alice", 1500, 200, 0.06);
const p2 = glicko.createPlayer("Bob", 1400, 30, 0.06);
const p3 = glicko.createPlayer("Charlie", 1550, 100, 0.06);

// Premier tournoi
glicko.recordMatch("Alice", "Bob", 1);     // Alice bat Bob
glicko.recordMatch("Bob", "Charlie", 0.5); // Match nul
glicko.recordMatch("Alice", "Charlie", 0); // Charlie bat Alice

glicko.updateRatings();

// Afficher le classement
glicko.getLeaderboard().forEach((player, i) => {
  console.log(`${i + 1}. ${player.id}: ${player.rating.toFixed(0)} (±${player.rd.toFixed(0)})`);
});

// Prédire un futur match
const prob = glicko.predict("Alice", "Bob");
console.log(`Probabilité victoire Alice: ${(prob * 100).toFixed(1)}%`);

Extension

Le système expose un hook onRatingUpdate pour brancher des mécaniques tierces (XP, badges, logs) sans modifier le cœur :

const glicko = new Glicko2({
  onRatingUpdate: (playerId, prev, next) => {
    console.log(`${playerId}: ${prev.rating.toFixed(0)} → ${next.rating.toFixed(0)}`);
  },
});

Le callback reçoit l'ID du joueur, son état avant mise à jour, et son état après. Il est appelé une fois par joueur à chaque updateRatings().

Architecture

src/
├── types.ts        # Types et interfaces
├── player.ts       # Classe Player
├── calculator.ts   # Moteur de calcul Glicko-2
└── glicko2.ts      # Classe principale

Formules mathématiques

Le système utilise les formules suivantes :

  • g(φ) = 1 / √(1 + 3φ²/π²)
  • E(μ, μj, φj) = 1 / (1 + exp(-g(φj)(μ - μj)))
  • v = [Σ g(φj)² · E(μ, μj, φj) · (1 - E(μ, μj, φj))]⁻¹
  • Δ = v · Σ g(φj) · (s - E(μ, μj, φj))

Référence

Licence

MIT