PHP code example of lsv / fussball-elo

1. Go to this page and download the library: Download lsv/fussball-elo 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/ */

    

lsv / fussball-elo example snippets



$hometeam_oldRating = 200;
$awayteam_oldRating = 280;

$hometeam_score = 3;
$awayteam_score = 2;

$factor = 20; // Tournament factor
// Normally these are used
// 60 - World Cup
// 50 - Continental Championship and Intercontinental Tournaments
// 40 - World Cup and Continental qualifiers and major tournaments
// 30 - All other tournaments
// 20 - Friendly Matches

use Lsv\FussballElo\Calculator;

$calculator = new Calculator(false);
// Change false to true if you want to give the hometeam a home advance

$ratings = $calculator->getRatings(
    $hometeam_oldRating,
    $awayteam_oldRating,
    $hometeam_score,
    $awayteam_score,
    $factor
);
// $ratings is now a instance of Lsv\FussballElo\Model\Result

$hometeam = $ratings->getHomeTeam();
$awayteam = $ratings->getAwayTeam();

$hometeam->getPointChange(); // Point change in this match for home team
$hometeam->getRating(); // New rating for home team

$awayteam->getPointChange(); // Point change in this match for away team
$awayteam->getRating(); // New rating for away team

$calculator = new Calculator(false);
// Change false to true if you want to give the hometeam a home advance
$resullt = $calculator->getWinExpectancies($hometeam_oldRating, $awayteam_oldRating);
$hometeam = $result->getHomeTeam();
// $hometeam is now a instance of Lsv\FussballElo\Model\TeamWinExpectancies
$awayteam = $result->getAwayTeam();

$hometeam->getWinExpectancies();
// 0.613
$awayteam->getWinExpectancies();
// 0.387

$hometeam->getWinExpectanciesInPercent(1);
// 1 = Number of digits
// 61.3

$awayteam->getWinExpectanciesInPercent(0);
// 39