mirror of
https://github.com/furyfire/trueskill.git
synced 2025-01-15 17:37:39 +00:00
Quality improvements
This commit is contained in:
134
benchmark/BasicBench.php
Normal file
134
benchmark/BasicBench.php
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace DNW\Skills\Benchmark;
|
||||||
|
|
||||||
|
use DNW\Skills\TrueSkill\TwoPlayerTrueSkillCalculator;
|
||||||
|
use DNW\Skills\TrueSkill\TwoTeamTrueSkillCalculator;
|
||||||
|
use DNW\Skills\TrueSkill\FactorGraphTrueSkillCalculator;
|
||||||
|
use DNW\Skills\GameInfo;
|
||||||
|
use DNW\Skills\Player;
|
||||||
|
use DNW\Skills\Team;
|
||||||
|
use DNW\Skills\Teams;
|
||||||
|
|
||||||
|
class BasicBench
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @Revs(20)
|
||||||
|
* @Iterations(20)
|
||||||
|
*/
|
||||||
|
public function benchBasic2PlayersUsingTwoPlayerTrueSkillCalculator(): void
|
||||||
|
{
|
||||||
|
$gameInfo = new GameInfo();
|
||||||
|
|
||||||
|
$p1 = new Player("Winner");
|
||||||
|
$p2 = new Player("Average");
|
||||||
|
|
||||||
|
$team1 = new Team($p1, $gameInfo->getDefaultRating());
|
||||||
|
$team2 = new Team($p2, $gameInfo->getDefaultRating());
|
||||||
|
|
||||||
|
for ($i = 0; $i < 10; $i++) {
|
||||||
|
$teams = Teams::concat($team1, $team2);
|
||||||
|
|
||||||
|
$calculator = new TwoPlayerTrueSkillCalculator();
|
||||||
|
|
||||||
|
$newRatings = $calculator->calculateNewRatings($gameInfo, $teams, [1, 2]);
|
||||||
|
|
||||||
|
$team1 = new Team($p1, $newRatings->getRating($p1));
|
||||||
|
$team2 = new Team($p2, $newRatings->getRating($p2));
|
||||||
|
|
||||||
|
$newRatings->getRating($p1)->getConservativeRating();
|
||||||
|
$newRatings->getRating($p2)->getConservativeRating();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Revs(20)
|
||||||
|
* @Iterations(20)
|
||||||
|
*/
|
||||||
|
public function benchBasic2PlayersUsingTwoTeamTrueSkillCalculator(): void
|
||||||
|
{
|
||||||
|
$gameInfo = new GameInfo();
|
||||||
|
|
||||||
|
$p1 = new Player("Winner");
|
||||||
|
$p2 = new Player("Average");
|
||||||
|
|
||||||
|
$team1 = new Team($p1, $gameInfo->getDefaultRating());
|
||||||
|
$team2 = new Team($p2, $gameInfo->getDefaultRating());
|
||||||
|
|
||||||
|
for ($i = 0; $i < 10; $i++) {
|
||||||
|
$teams = Teams::concat($team1, $team2);
|
||||||
|
|
||||||
|
$calculator = new TwoTeamTrueSkillCalculator();
|
||||||
|
|
||||||
|
$newRatings = $calculator->calculateNewRatings($gameInfo, $teams, [1, 2]);
|
||||||
|
|
||||||
|
$team1 = new Team($p1, $newRatings->getRating($p1));
|
||||||
|
$team2 = new Team($p2, $newRatings->getRating($p2));
|
||||||
|
|
||||||
|
$newRatings->getRating($p1)->getConservativeRating();
|
||||||
|
$newRatings->getRating($p2)->getConservativeRating();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Revs(20)
|
||||||
|
* @Iterations(20)
|
||||||
|
*/
|
||||||
|
public function benchBasic2PlayersUsingFactorGraphTrueSkillCalculator(): void
|
||||||
|
{
|
||||||
|
$gameInfo = new GameInfo();
|
||||||
|
|
||||||
|
$p1 = new Player("Winner");
|
||||||
|
$p2 = new Player("Average");
|
||||||
|
|
||||||
|
$team1 = new Team($p1, $gameInfo->getDefaultRating());
|
||||||
|
$team2 = new Team($p2, $gameInfo->getDefaultRating());
|
||||||
|
|
||||||
|
for ($i = 0; $i < 10; $i++) {
|
||||||
|
$teams = Teams::concat($team1, $team2);
|
||||||
|
|
||||||
|
$calculator = new FactorGraphTrueSkillCalculator();
|
||||||
|
|
||||||
|
$newRatings = $calculator->calculateNewRatings($gameInfo, $teams, [1, 2]);
|
||||||
|
|
||||||
|
$team1 = new Team($p1, $newRatings->getRating($p1));
|
||||||
|
$team2 = new Team($p2, $newRatings->getRating($p2));
|
||||||
|
|
||||||
|
$newRatings->getRating($p1)->getConservativeRating();
|
||||||
|
$newRatings->getRating($p2)->getConservativeRating();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Revs(20)
|
||||||
|
* @Iterations(20)
|
||||||
|
*/
|
||||||
|
public function bench3Teams(): void
|
||||||
|
{
|
||||||
|
$gameInfo = new GameInfo();
|
||||||
|
|
||||||
|
$p1 = new Player("Winner");
|
||||||
|
$p2 = new Player("Average");
|
||||||
|
$p3 = new Player("Looser");
|
||||||
|
|
||||||
|
$team1 = new Team($p1, $gameInfo->getDefaultRating());
|
||||||
|
$team2 = new Team($p2, $gameInfo->getDefaultRating());
|
||||||
|
$team3 = new Team($p3, $gameInfo->getDefaultRating());
|
||||||
|
|
||||||
|
for ($i = 0; $i < 10; $i++) {
|
||||||
|
$teams = Teams::concat($team1, $team2, $team3);
|
||||||
|
|
||||||
|
$calculator = new FactorGraphTrueSkillCalculator();
|
||||||
|
|
||||||
|
$newRatings = $calculator->calculateNewRatings($gameInfo, $teams, [1, 2, 3]);
|
||||||
|
|
||||||
|
$team1 = new Team($p1, $newRatings->getRating($p1));
|
||||||
|
$team2 = new Team($p2, $newRatings->getRating($p2));
|
||||||
|
$team3 = new Team($p3, $newRatings->getRating($p3));
|
||||||
|
|
||||||
|
$newRatings->getRating($p1)->getConservativeRating();
|
||||||
|
$newRatings->getRating($p2)->getConservativeRating();
|
||||||
|
$newRatings->getRating($p3)->getConservativeRating();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -9,7 +9,8 @@
|
|||||||
"phpunit/phpunit": "^10",
|
"phpunit/phpunit": "^10",
|
||||||
"phpstan/phpstan": "^1",
|
"phpstan/phpstan": "^1",
|
||||||
"squizlabs/php_codesniffer": "*",
|
"squizlabs/php_codesniffer": "*",
|
||||||
"vimeo/psalm": "^5.14"
|
"vimeo/psalm": "^5.14",
|
||||||
|
"phpmetrics/phpmetrics": "^3.0-dev"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
@ -25,6 +26,8 @@
|
|||||||
"test": "vendor/bin/phpunit tests --display-warnings",
|
"test": "vendor/bin/phpunit tests --display-warnings",
|
||||||
"test-coverage": "vendor/bin/phpunit tests --testdox --coverage-filter src --coverage-html output/coverage --coverage-text --testdox-html output/test.html --log-junit output/test.xml",
|
"test-coverage": "vendor/bin/phpunit tests --testdox --coverage-filter src --coverage-html output/coverage --coverage-text --testdox-html output/test.html --log-junit output/test.xml",
|
||||||
"document": "phpDocumentor --setting=graphs.enabled=true",
|
"document": "phpDocumentor --setting=graphs.enabled=true",
|
||||||
|
"benchmark": "phpbench run --report=default --output=build-artifact",
|
||||||
|
"metrics": "vendor/bin/phpmetrics --config=phpmetrics.json",
|
||||||
"analyze": [
|
"analyze": [
|
||||||
"@analyze-phpstan",
|
"@analyze-phpstan",
|
||||||
"@analyze-psalm",
|
"@analyze-psalm",
|
||||||
@ -32,6 +35,6 @@
|
|||||||
],
|
],
|
||||||
"analyze-phpstan":"vendor/bin/phpstan analyze --error-format=raw",
|
"analyze-phpstan":"vendor/bin/phpstan analyze --error-format=raw",
|
||||||
"analyze-psalm": "vendor/bin/psalm --no-cache",
|
"analyze-psalm": "vendor/bin/psalm --no-cache",
|
||||||
"analyze-phpcs": "vendor/bin/phpcs --report=emacs --standard=PSR1,PSR2,PSR12 --exclude=Generic.Files.LineLength src tests"
|
"analyze-phpcs": "vendor/bin/phpcs --report=emacs --standard=PSR1,PSR2,PSR12 --exclude=Generic.Files.LineLength src tests benchmark"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
82
composer.lock
generated
82
composer.lock
generated
@ -4,7 +4,7 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "667bb75c25a72b3d35f64ada9d9d9e0d",
|
"content-hash": "9d079e1055ee327f2d46ed48b8a25cd6",
|
||||||
"packages": [],
|
"packages": [],
|
||||||
"packages-dev": [
|
"packages-dev": [
|
||||||
{
|
{
|
||||||
@ -1082,6 +1082,82 @@
|
|||||||
},
|
},
|
||||||
"time": "2024-01-11T11:49:22+00:00"
|
"time": "2024-01-11T11:49:22+00:00"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "phpmetrics/phpmetrics",
|
||||||
|
"version": "v3.0.0rc5",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/phpmetrics/PhpMetrics.git",
|
||||||
|
"reference": "7a4ee5d6a8233f449fb9125ad586d3880c8a1b2f"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/phpmetrics/PhpMetrics/zipball/7a4ee5d6a8233f449fb9125ad586d3880c8a1b2f",
|
||||||
|
"reference": "7a4ee5d6a8233f449fb9125ad586d3880c8a1b2f",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"ext-tokenizer": "*",
|
||||||
|
"nikic/php-parser": "^4",
|
||||||
|
"php": ">=8.1"
|
||||||
|
},
|
||||||
|
"replace": {
|
||||||
|
"halleck45/php-metrics": "*",
|
||||||
|
"halleck45/phpmetrics": "*"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phake/phake": "^4.4.0",
|
||||||
|
"phpstan/extension-installer": "^1.3",
|
||||||
|
"phpstan/phpstan": "^1.10",
|
||||||
|
"phpstan/phpstan-deprecation-rules": "^1.1",
|
||||||
|
"phpstan/phpstan-phpunit": "^1.3",
|
||||||
|
"phpstan/phpstan-strict-rules": "^1.5",
|
||||||
|
"phpunit/phpunit": "^10.3",
|
||||||
|
"roave/security-advisories": "dev-latest",
|
||||||
|
"sebastian/comparator": ">=5.0.0",
|
||||||
|
"squizlabs/php_codesniffer": "^3.7",
|
||||||
|
"symfony/dom-crawler": "^6.3",
|
||||||
|
"vimeo/psalm": "^5.15"
|
||||||
|
},
|
||||||
|
"suggest": {
|
||||||
|
"ext-dom": "To allow XML parsing and report results.",
|
||||||
|
"ext-yaml": "To allow yaml parsing of configuration files."
|
||||||
|
},
|
||||||
|
"bin": [
|
||||||
|
"bin/phpmetrics"
|
||||||
|
],
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Hal\\": "src/Hal"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Jean-François Lépine",
|
||||||
|
"email": "lepinejeanfrancois@yahoo.fr",
|
||||||
|
"homepage": "http://www.lepine.pro",
|
||||||
|
"role": "Copyright Holder"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Static analyzer tool for PHP : Coupling, Cyclomatic complexity, Maintainability Index, Halstead's metrics... and more !",
|
||||||
|
"homepage": "http://www.phpmetrics.org",
|
||||||
|
"keywords": [
|
||||||
|
"analysis",
|
||||||
|
"qa",
|
||||||
|
"quality",
|
||||||
|
"testing"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/PhpMetrics/PhpMetrics/issues",
|
||||||
|
"source": "https://github.com/phpmetrics/PhpMetrics/tree/v3.0.0rc5"
|
||||||
|
},
|
||||||
|
"time": "2024-01-17T10:59:12+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "phpstan/phpdoc-parser",
|
"name": "phpstan/phpdoc-parser",
|
||||||
"version": "1.25.0",
|
"version": "1.25.0",
|
||||||
@ -3649,7 +3725,9 @@
|
|||||||
],
|
],
|
||||||
"aliases": [],
|
"aliases": [],
|
||||||
"minimum-stability": "stable",
|
"minimum-stability": "stable",
|
||||||
"stability-flags": [],
|
"stability-flags": {
|
||||||
|
"phpmetrics/phpmetrics": 20
|
||||||
|
},
|
||||||
"prefer-stable": false,
|
"prefer-stable": false,
|
||||||
"prefer-lowest": false,
|
"prefer-lowest": false,
|
||||||
"platform": {
|
"platform": {
|
||||||
|
11
phpbench.json
Normal file
11
phpbench.json
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"runner.bootstrap": "vendor/autoload.php",
|
||||||
|
"runner.path": "benchmark/",
|
||||||
|
"report.outputs": {
|
||||||
|
"build-artifact": {
|
||||||
|
"renderer": "html",
|
||||||
|
"path": "output/benchmark.html",
|
||||||
|
"title": "Benchmarking"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
20
phpmetrics.json
Normal file
20
phpmetrics.json
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"composer": true,
|
||||||
|
"includes": [
|
||||||
|
"src"
|
||||||
|
],
|
||||||
|
"excludes": [
|
||||||
|
"tests"
|
||||||
|
],
|
||||||
|
"report": {
|
||||||
|
"html": "output/metrics/"
|
||||||
|
},
|
||||||
|
"plugins": {
|
||||||
|
"git": {
|
||||||
|
"binary": "git"
|
||||||
|
},
|
||||||
|
"junit": {
|
||||||
|
"file": "output/test.xml"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -3,3 +3,4 @@ parameters:
|
|||||||
paths:
|
paths:
|
||||||
- src
|
- src
|
||||||
- tests
|
- tests
|
||||||
|
- benchmark
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
<projectFiles>
|
<projectFiles>
|
||||||
<directory name="src" />
|
<directory name="src" />
|
||||||
<directory name="tests" />
|
<directory name="tests" />
|
||||||
|
<directory name="benchmark" />
|
||||||
<ignoreFiles>
|
<ignoreFiles>
|
||||||
<directory name="vendor" />
|
<directory name="vendor" />
|
||||||
</ignoreFiles>
|
</ignoreFiles>
|
||||||
|
17
tests/PlayerTest.php
Normal file
17
tests/PlayerTest.php
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace DNW\Skills\Tests;
|
||||||
|
|
||||||
|
use DNW\Skills\Player;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class PlayerTest extends TestCase
|
||||||
|
{
|
||||||
|
public function test(): void
|
||||||
|
{
|
||||||
|
$p = new Player('dummy', 0.1, 0.2);
|
||||||
|
$this->assertEquals('dummy', (string)$p);
|
||||||
|
$this->assertEquals(0.1, $p->getPartialPlayPercentage());
|
||||||
|
$this->assertEquals(0.2, $p->getPartialUpdatePercentage());
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user