PHP code example of keliodev / glicko2

1. Go to this page and download the library: Download keliodev/glicko2 library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

keliodev / glicko2 example snippets


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;
}

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

php composer.phar