mauserrifle / simresults

Sim racing result reader for PHP
http://simresults.net
ISC License
60 stars 21 forks source link
assetto-corsa automobilista php project-cars raceroom reader rfactor simracing

Simresults

Minimum PHP Version CI Status Total Downloads License

Simresults is an open-source, object-oriented library built using PHP. It allows you to read out log files of a race game and transforms them to a simple data model to easily read out this data.

This project is the core of the website simresults.net , which allows you to upload your race log files and transform them to a readable format. The uploaded results become saved and public, so visitors can share them with their fellow racers. An example result can be found at http://simresults.net/130529-X2g.

The website is a service but also a demonstration of what is possible using this library. This library does not supply any HTML templates or whatsoever. Any 'implementation' is up to you within your own project and is not limited to any framework.

This project is created (2013) and maintained by Maurice van der Star

Please consider donating to cover future development.

It's also possible to use the Simresults website remote results API. This requires much less work and programming knowledge.

Supported games

Simresults supports a wide range of games:

The following expansions of RACE (07) should work too:

Please note that Formula Truck will be reported as as a rFactor game.

Results from F1 challenge and GTR might miss laps.

Results from Assetto Corsa (race_out.json) and Raceroom might only contain 1 lap.

Features

rFactor reader

lib/Data/Reader/Rfactor2.php

Project Cars Server reader

lib/Data/Reader/ProjectCarsServer.php

Assetto Corsa reader

lib/Data/Reader/AssettoCorsa.php

Assetto Corsa Server reader

lib/Data/Reader/AssettoCorsaServer.php

Assetto Corsa Server reader JSON

lib/Data/Reader/AssettoCorsaServerJson.php

Assetto Corsa Competizione

lib/Data/Reader/AssettoCorsaCompetizione.php

RaceRoom Server reader

lib/Data/Reader/RaceRoomServer.php

RACE 07 reader

lib/Data/Reader/Race07.php

iRacing reader

lib/Data/Reader/Iracing.php

Requirements

Installation and example

Simresults can be installed and autoloaded using composer. But ofcourse it will work with any PSR-0 autoloader.

Example for Linux/OSX

Install composer.

Add the Simresults package to the composer.json file:

composer require mauserrifle/simresults:dev-develop

Create index.php:

<?php

// Load code
require(realpath('vendor/autoload.php'));

// Path to the result source file
$file = realpath(dirname(__FILE__)
        .'/vendor/mauserrifle/simresults/tests/logs/rfactor2'
        .DIRECTORY_SEPARATOR.'race.xml');

// Get a reader using the source file
$reader = \Simresults\Data_Reader::factory($file);

// Get the first session. Note: Use `getSessions()` to get all sessions
$session = $reader->getSession();

// Get participants sorted by their position
$participants = $session->getParticipants();

// Get the driver name of the second participant
$driver_name = $participants[1]->getDriver()->getName();

// Get the best lap of the second participant
$best_lap = $participants[1]->getBestLap();

// Get the best lap of the session
$session_best_lap = $session->getBestLap();

// Format the gap between the two laps
$helper = new \Simresults\Helper;
$best_lap_gap = $helper->formatTime($session_best_lap->getGap($best_lap));
echo $best_lap_gap;

Run server

 php -S localhost:8000

Open http://localhost:8000 and all should work!

For further usage please read the classes code within the lib folder. They are carefully documented.

Sponsors

Big thanks to the following sponsors for supporting Simresults! Please pay them a visit :)

Bugs

Have a bug or a feature request? Please open a new issue.

Known issues

Caching

Some classes like Participant do heavy caching. So changing any value after calling sorting methods will be pointless. There are no cache invalidate methods (yet). Most likely they will never be needed as there's no use case you actually would want to change values after reading out all data.

When writing a reader. NEVER call methods like getVehicle() on Participant (which uses cached methods). Re-use your own created objects (like $vehicle) within the reading to prevent any early invalid cache. Do this for all type of objects.

Laps missing

Logs tend to miss lap data on all games. Check the logs.

Marked as RACE session while it's not

The Race 07 reader detects qualify if all drivers are DNF. There's no session type in these log files. This detection might be false in some cases.

Date is not right of session

GTR, GTL, F1 challenge don't have a timestamp or timezone information. So dates are created using the default timezone.

Contributing

The project is designed to be extended with new features and game support. Feel free to fork Simresults on GitHub and submit a pull request!

The project is tested using PHPUnit and phpspec. If you offer any changes, make sure all your new additions are tested.

Running simresults tests

To run the tests, use the following command:

./vendor/bin/phpunit
./vendor/bin/phpspec run

License

The Simresults library is open-sourced software licensed under the ISC license.