keliodev/glicko2

A PHP implementation of glicko2 rating system

1.0.2 2019-12-05 02:44 UTC

This package is not auto-updated.

Last update: 2025-06-14 01:09:16 UTC


README

--------------------------------------------------------------------------------------------------------------

It's a fork to rename the class Match into MatchGame because the work "match" is a reserved keyword in PHP 8.0

--------------------------------------------------------------------------------------------------------------

License Latest Stable Version Total Downloads

A PHP implementation of Glicko2 rating system

Installation

Composer

The preferred way to install this extension is through Composer.

Either run

php composer.phar require KelioDev/glicko2 "~1.0.0"

or add

"KelioDev/glicko2": "~1.0.0"

to the require section of your composer.json

Usage

For ease of understanding take ActiveRecord pattern.

Somewhere create object. Attribute names can be any

use keliodev\glicko2\Player;
// ...
public function createUserRating(int $userId)
{
    $userRating = new UserRating();
    $userRating->user_id = $userId;
    $player = new Player();
    $userRating->rating = $player->getRating();
    $userRating->rating_deviation = $player->getRatingDeviation();
    $userRating->rating_volatility = $player->getRatingVolatility();

    $userRating->insert();
    
    return $userRating;
}

Ok, let's play

use keliodev\glicko2\MatchGame;
use keliodev\glicko2\MatchCollection;
use keliodev\glicko2\Player;

$player1 = new Player($userRating1->rating, $userRating1->rating_deviation, $userRating1->rating_volatility);
$player2 = new Player($userRating2->rating, $userRating2->rating_deviation, $userRating2->rating_volatility);

// match chain
$match1 = new MatchGame($player1, $player2, 1, 0);
$match1->calculate();

$match2 = new MatchGame($player1, $player2, 3, 2);
$match2->calculate();

// or match collection
$matchCollection = new MatchCollection();
$matchCollection->addMatch(new MatchGame($player1, $player2, 1, 0));
$matchCollection->addMatch(new MatchGame($player1, $player2, 3, 2));
$matchCollection->calculate();

$newPlayer1Rating = $player1->getRating();
$newPlayer2Rating = $player2->getRating();

// for example, save in DB

$userRating1->rating = $player1->getRating();
$userRating1->rating_deviation = $player1->getRatingDeviation();
$userRating1->rating_volatility = $player1->getRatingVolatility();
$userRating1->update();

// similarly save the second player

Author

Aleksandr Zelenin, e-mail: aleksandr@zelenin.me

Vlad Varlamov, e-mail: work@laxity.ru