Git Product home page Git Product logo

simresults's Introduction

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:

  • rFactor
  • rFactor 2
  • Project Cars
  • Project Cars 2
  • Assetto Corsa
  • Assetto Corsa Competizione
  • Automobilista
  • Automobilista 2
  • Game Stock Car 2012
  • Game Stock Car 2013
  • Game Stock Car Extreme
  • Formula Truck 2013
  • RACE
  • RACE 07
  • GTR
  • GTR2
  • GT Legends
  • RaceRoom Racing Experience
  • BMW M3 Challenge
  • F1 challenge 99-02

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

  • Race: Caterham expansion
  • GTR Evolution
  • Crowne Plaza
  • STCC - The Game
  • STCC 2 - The Game
  • RACE On
  • Raceroom - The Game
  • Raceroom - The Game 2
  • Formula Raceroom
  • GT Power
  • WTCC 2010
  • Retro
  • Race Injection
  • Volvo - The Game

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

  • Can read out a full session consisting of the following information: Game, Server, Settings, Track, Participants/Drivers including swaps, Vehicle, Compound choice, Chats, Laps/Sectors, Fuel usage, Pit info, Penalties and Incidents
  • Offers extra methods to get specific data, e.g. getBestLap() and getBestLapBySector(<int>)
  • Offers a Helper class to sort laps by time and format times to human readable format (h:i:s.u)
  • Caches heavy methods like getLapsSortedBySector(<int>). This is very useful with endurance results that have 200+ laps
  • The API is unittested

rFactor reader

lib/Data/Reader/Rfactor2.php

  • Supports rFactor and rFactor 2. Also works for other rFactor powered games: Automobilista, Game Stock Car 2012, Game Stock Car 2013 and Formula Truck 2013
  • Detects and fixes position data (sometimes log files report complete wrong positions due to lag/bugs)
  • Detects human and AI players using their aids (sometimes log files report wrong player state)

Project Cars Server reader

lib/Data/Reader/ProjectCarsServer.php

Assetto Corsa reader

lib/Data/Reader/AssettoCorsa.php

  • Limited data. Use server logs if possible.

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

  • Also works for the following games: RACE, GTR, GTR2, GT Legends, BMW M3 Challenge, F1 challenge 99-02 and all expansions of these games
  • Checks and fixes log variations like non-zero based laps and missing lap data

iRacing reader

lib/Data/Reader/Iracing.php

  • Limited data. Only contains the best lap of drivers.

Requirements

  • PHP >= 7.3
  • Composer (for easy installing and autoloading)

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.

simresults's People

Contributors

aleex1848 avatar hieblmedia avatar mauserrifle avatar timdpr avatar wakcs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

simresults's Issues

Qualification times are missing in Raceroom

Hi,

Since a few weeks, the qualifications times are missing in the display of raceroom qualification table, like here : http://simresults.net/171023-vG1

Those times are still in the Json so it should be a bug :

Ex :

{
"FullName":"David Torned",
"Username":"Torned",
"Car":"McLaren MP4-12C GT3",
"CarPerformanceIndex":60,
"Position":2,
"PositionInClass":2,
"BestLapTime":97958,
"TotalTime":-1,
"FinishStatus":"Finished",
"RaceSessionLaps":[
{
"Time":-1000,
"Position":2,
"PitStopOccured":false
}
]

I've looked in the code and I think I know why it does not worked. Qualification has a section "RaceSessionLaps" (which is wierd) and has a consequence, you parser does not take into account "BestLapTime" which is where we can find the time for the qualification. See line 183 and 212 of Data/Reader/RaceRoomServer.php.

Thanks

Implement json export

Easy converting to JSON would be of big value for users who do not know PHP and just want to get a fast universal JSON output.

Assetto Corsa: Read skin and ballast

Read skin and ballast information.

"Cars": [
        {
            "CarId": 0,
            "Driver": {
                "Name": "Driver",
                "Team": "",
                "Guid": "7111111111111459"
            },
            "Model": "ag_porsche997rsr_11",
            "Skin": "porsche_1",
            "BallastKG": 0
        },

50% laps completion rule

In the AC Server JSON reader, drivers that have not completed 50% of the laps are marked as FINISH_NONE. Implement this on other (AC) readers too?

Create an array helper class

Almost every reader has the code below. Fix it.

/**
 * Retrieve a single key from an array. If the key does not exist in the
 * array, the default value will be returned instead.
 *
 *     // Get the value "username" from $_POST, if it exists
 *     $username = Arr::get($_POST, 'username');
 *
 *     // Get the value "sorting" from $_GET, if it exists
 *     $sorting = Arr::get($_GET, 'sorting');
 *
 * This function is from the Kohana project (http://kohanaframework.org/).
 *
 * @param   array   $array      array to extract from
 * @param   string  $key        key name
 * @param   mixed   $default    default value
 * @return  mixed
 */
protected function get($array, $key, $default = NULL)
{
    return isset($array[$key]) ? $array[$key] : $default;
}

Bug on API?

Hello,

I try to use the API for grouping the result of my league (on R3E). For that purpose, I created a JSON as described in your docs:
http://ec2-35-180-32-180.eu-west-3.compute.amazonaws.com/results/json/simresult.json

Seems to work well : http://simresults.net/remote?results=http%3A%2F%2Fec2-35-180-32-180.eu-west-3.compute.amazonaws.com%2Fresults%2Fjson%2Fsimresult.json

Unfortunately, it does not work well at the moment because, if I update my json input file, for example by adding a new event, this event does not appear in the dropdown list when I refresh the page in simresults (while I can see the change in my webserver). Finally, I'll see this event a few hours later (which is problematic as our drivers want to see the results just after the race).

Seems that there is some caching or something?

I also notice that when I select one event and then an other in the dropdown, there is a duplicated parameter in the URL : "&result=4&result=11". This bug is also visible when using the demo in your API description page : http://simresults.net/remote?results=http%3A%2F%2Fsimresults.net%2Fexample.json&result=1&result=0

Maybe is those two issue related with each other?

Thanks in advance for your support,

BR

PS : there is also another bug in raceroom, all names are now "broken" : John D instead of John Doe (only when using manual upload, not through the API)

Ac-server: Improve tyre performance

When doing regex above Lap data. Somehow detect that there are no lap changes after that lap? So this means 2 regexes, but maybe safe like 10-60 after that.

Remove cache code from Session

Make an interface of Session. Make the current Session class an implementation of it. Remove all cache code from that implementation and make use of a cached decorator implementing the interface.

CachedSession --> Session --> SessionInterface

Add toString to Lap

Consider adding toString to the Lap class. This makes code simpler by excluding getTime() from the following code

\Simresults\Helper::formatTime($participants[$i]->getBestLap()->getTime());

Project Cars: distance traveled

From the PC forum:

I have a small request,
in the log file, there is a value "trackdistance" by drivers.
It would be nice to integrated with the total number of laps made during the different sessions.

Clean unittests with custom logs

Change code like this:

    $file_path = realpath(__DIR__.'/logs/assettocorsa-server/discarded.laps.txt');
    $session = Data_Reader::factory($file_path)->getSession(3);

To something like:

    $session = Data_Reader::factory(realpath(__DIR__.'/logs/assettocorsa-server/discarded.laps.txt'))->getSession();

AC-server-json: Detailed incidents

Source: http://www.assettocorsa.net/forum/index.php?threads/simresults-net-a-webbased-result-reader-php-library.2658/page-16#post-937593

(example log is known at Alex or Mauserrifle).

I use $session->getIncidents() for retrieving collisions. That's kind of ugly because i have to parse these message strings someway, try to match it against my drivers to get in touch with the involved driver guids.
I saw an "Events" section in the json which provides detailed information about collisions including type (car collision / environment collision) and the involved driver's guid.
My it be possible to include these information in you library?

Add `isValid` to Lap?

Project Cars now excludes invalid laps. But it could be nice to still have these laps for stats but exclude from all other logic such as best lap.

Set original session date string

Set the session date as original string too. This is useful for readers of logs that don't include dates that can be converted to a proper PHP timezones. I think this is better for the ac-server reader.

ProjectCars 2 no result data for admin/first player on ded

Hi , I'm one of the admins at simracingonline.co.uk & we have an issue with my info (as admin & first on the server) never appearing in the results for pc2 , I have done the edits to the sms_stats_json ,here are my edits >

-- Session game state changes.
function handle_session_game_state_change( old_state, new_state )
if not old_state or old_state == "" then
old_state = "None"
end
session_game_state = new_state
if ( old_state == "None" ) and ( new_state == "Lobby" ) then
handle_new_session_lobby()
elseif ( old_state == "Returning" ) and ( new_state == "Lobby" ) then
handle_returning_session_lobby()
elseif ( old_state == "Lobby" ) and ( new_state == "Loading" ) then
handle_session_loading()
elseif ( old_state == "Loading" ) and ( new_state == "PostRace" or new_state == "Race" ) then
handle_session_loaded()
elseif ( old_state == "PostRace" or old_state == "Race" ) and ( new_state ~= "PostRace" and new_state ~= "Race" ) then
if new_state == "None" then
handle_session_finished_prematurely()
else
handle_session_finished()
end
end
end

These seem to work as we now have results ! however my info is never parsed and Im left out of every result ?
here is a pic of race 1 (of 2 that day & should be the last 2 races in the results) Im admin on the server and finished 6th 'Rob Milliken'

send to mouser

& this
This is what we get from simresults without any of my info ..

yyyyxxxx

We don't know what to do ?? its been like this from the start meaning my data is never shown ..

I tried to upload my sms_stats_data but i dont have winzip and wrar wont work ..it's posted in this thread at SMS forums http://forum.projectcarsgame.com/showthread.php?56405-No-Race-Results-in-sms_stats_data-json&p=1461236&viewfull=1#post1461236

Im reading in the forum that other players have it working with no issues & so it must be something on my end ?
Thanks in advance if you find any time to help !
Rob .. ;-)

Refactor readers with a common interface

Alot of readers share common functionality (for example fix positions based on participant order). Also all readers started to have their own implementation and order how to get things (big clutter in getSessions() method too).

We need to fix this and make all readers act within with the same behavior using a common interface. Template methods? Is this possible due to different data formats?

Refused laps with different log format are included

Example:

LAP ShijouR26B 2:42:396 
SPLIT COUNT: 3
Dynamic track ok
LAP REFUSED BECAUSE THE SESSION HAS NOT STARTED YET

Filter them out too. See how we can change the regex. Currently works only when it's on the next line (\n|\r)(?!WARNING: LAPTIME DISCARDED|LAP REFUSED) which won't work in this case :(

Assetto Corsa missing lap 1 position data

I have an instance where lap 1 is missing for all participants. All other laps are processed ok. This is an Assetto Corsa json file. I can see lap 1 in the file for all participants. Any workaround for this problem? Thanks.

Project Cars 2: Player not being recognized as the same user across two races.

I'm using your website to calculate the points for our league and it is showing one of our players as being a separate user across two races. Here is a link to the result:

https://simresults.net/181018-4Jj

If it would be useful I can attach the logfiles I used to create this result. You can see that the player 'V8_Fiero' is listed twice on the points breakdown and is in both race 2 and 3. We are using the MotoGP points schedule.

One thing to note is that I entered each race as a separate json file. We run two races a week and I removed all the other history results from each file so it only contained one practice/qual/race session.

rFactor: Calculate pitstop time

Request by CordellCahill:

Another thing is calculating pit stop bogey times. Looking at the stream part it seems it can be calculated using that. Say take the last sector 3 starting time stamp before a pit then get the timestamp of the start of the proceeding sector 2. Take that time and subtract an avg of what that time is without the pit....boom, bogey time.

Throw exception when file is not found

Is now throwing Simresults\Exception\NoData: Cannot find a reader for the given data which is incorrect. The "given data" is not read.

Throw a File Not Found exception instead.

Set grid position for Assetto Corsa reader

Set race grid position based on the previous qualify session for the Assetto Corsa reader (race_out.json). Same functionality as used within Assetto Corsa Server reader.

Prevent duplicate code?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.