PDA

View Full Version : PCARS Data API (PCARS2 Suggestion and Possible PCARS1 Project)



SenorPez
04-04-2017, 21:33
I thought about putting this in the PCARS 2 forum, but since it's more developer-focused, I figured it would find more traction here.

One thing I'd like to see in PCARS 2 (it's probably a little late in the cycle for PCARS, but maybe I'll poke around since the Replay Enhancer seems to be fairly stable) is a cars and event REST API. There were a lot of community attempts at creating car databases, with varying degrees of usability and correctness. Ideally, this API information would be published and available from SMS and the PCARS website, but if we have to do it as a community project for the full-stack, I think we can manage that.

The API would deliver JSON data, a fairly common exchange format that, while not easy on the eyes, is easy to process in just about any programming language. From this API, application developers could then build applications using this "source of truth" data, rather than having to reinvent the wheel because there's no way to import data from an Excel spreadsheet into a Python script (not easily, anyway).

A few examples... note that the URL is hideous because I'm not masking the AWS data and it's likely to stop working at some point (just because I bring the instance down)... also the data structures are fairly pedestrian at this point... but it's a proof-of-concept:

Car list (note that this isn't actually the full car list, nor a full set of data, but you get the idea): http://www.projectcars.senorpez.com/v1/cars
Track list: http://www.projectcars.senorpez.com/v1/tracks
Event list: http://www.projectcars.senorpez.com/v1/events

Events also support drilling down.
Cars allowed for a specific event: http://www.projectcars.senorpez.com/v1/events/2/cars
Rounds in a specific event: http://www.projectcars.senorpez.com/v1/events/15/rounds/
Specific round in a specific event: http://www.projectcars.senorpez.com/v1/events/1/rounds/3

Like I said: This would be most effective coming directly from SMS, as they're going to have all the data available, correct, and can put it out there. But as a community, I think we can do it, too. Let's make it happen.

If you have WMD: Maybe pitch this idea? (I regret not getting in on WMD2.)
If you want to help, even just data entry, for PCARS 1 stuff: Let me know. There's a non-trivial chance I expand this moving forward to support PCARS for no reason but my own curiosity.

Ryzza5
05-04-2017, 04:21
I'm sure one of the devs would have noticed this anyway, but I have linked to this thread in the WMD2.0 forums on your behalf.

SenorPez
07-04-2017, 14:24
Updated lead post. Made the API a little more mature, cleaned up some of the URLs, and enabled pretty printing so the output is less harsh on human eyes.

MikeyTT
11-04-2017, 16:55
It's a great idea and much of this is actually encompassed in my suggested API variables, I've posted to the PC2 API section. But not the REST bit :)

Are you aware that some of the car and track data is available directly from the Dedicated Server today, and may well be extended in PC2?

You tag on something like "/api/list/tracks" to the DS address and you get back this:


{
"result" : "ok",
"response" : {
"description" : "All known track ids",
"list" : [
{
"id" : 999,
"name" : "Some Location Circuit",
"gridsize" : 20
},
{
"id" : 998,
"name" : "Some Place GP",
"gridsize" : 38
},
Note: This is from the PC2 DS, so I've changed things to be on the safe side

You can do this for tracks, car classes, cars, plus weather and a few others I can't recall. But, in relation to your OP, it doesn't necessarily do all of the extra "what this session is configured like" you're asking for, or at least yet.

For your ref, I've compiled a spreadsheet of the API changes I'd like to see, which also covers off a lot of what was collected for PC1, that didn't make the cut. It's in the post here in my vrHive thread: http://forum.projectcarsgame.com/showthread.php?33881-PC-XB1-PS4-vrHive-Dashes-Telemetry-Live-Data-Arduino-Client-Server-more&p=1326207&viewfull=1#post1326207

The key for me is being able to get access to the setup data, as the user is in the pits. That way, for my app, you can actually automate things like saving the setup data against each of the laps the player is taking. Then you can compare that with previous runs, setups, weather data, etc.

SenorPez
11-04-2017, 17:34
It's a great idea and much of this is actually encompassed in my suggested API variables, I've posted to the PC2 API section. But not the REST bit :)

Are you aware that some of the car and track data is available directly from the Dedicated Server today, and may well be extended in PC2?


I actually wasn't, and I'll have to check it out. My main platform is PS4, so I've not ever touched the Dedicated Server, but if its outputting some data, that's useful! I'll have to check it out.


For your ref, I've compiled a spreadsheet of the API changes I'd like to see, which also covers off a lot of what was collected for PC1, that didn't make the cut. It's in the post here in my vrHive thread: http://forum.projectcarsgame.com/showthread.php?33881-PC-XB1-PS4-vrHive-Dashes-Telemetry-Live-Data-Arduino-Client-Server-more&p=1326207&viewfull=1#post1326207

And I'm really hoping a lot of that comes in, and glad you're spearheading it. There's definitely room for improvement, and if PCARS2 wants to continue app support, we'll love them for doing it!


The key for me is being able to get access to the setup data, as the user is in the pits. That way, for my app, you can actually automate things like saving the setup data against each of the laps the player is taking. Then you can compare that with previous runs, setups, weather data, etc.

That would be really, really, really cool if something like that could be implemented. "Okay, I changed my springs, what's my 3-lap average delta?" It could really help people get a handle on the black art of tuning... assuming they can turn consistent laps. ;)

I think something like what I proposed would run right alongside that. For example, once your app identifies that I'm driving a Mustang Cobra TransAm, it can pull the static data (weight, wheelbase, etc.) and combine it with the session-specific data (track temperature, tuning settings, etc.). That way, you don't have to worry about data entry or processing for the cars; you can focus on the session information and your front end.

SenorPez
12-04-2017, 21:23
Updated the URLS. They're pretty now. ;)

Also did a bunch of data entry, so it's more robust. Have a look.

If you find errors, or if you want to help fill in the gaps, the project is on Github. You can clone it or edit the data.json file and submit it to the project for inclusion!
https://github.com/SenorPez/project-cars-data-api/tree/0.1-devel

Let me know if you have questions!

SenorPez
25-04-2017, 20:32
I added most of the cars data. Enjoy. :)

There's also some rudimentary documentation located at: http://www.projectcars.senorpez.com/swagger-ui.html

SenorPez
02-06-2017, 21:18
Good news: I'm not dead. (There was some job-drama, but that's typical American dream these days, right?)

Better news: While there's still some data gaps, the PCARS API is far more mature and stable now.

If you're interested, check it out at:
http://www.projectcars.senorpez.com/

From there, it's self-documenting. Okay, not entirely. I've not actually written the documentation that should be at the documentation links yet (which is funny, since that's my real-life job). But the link names should give you an idea of what's there, and where you can go next.

There's some probably-out-of-date Swagger documentation at: http://www.projectcars.senorpez.com/swagger-ui.html

Notes
This will all work out of a web browser for now, but if you really want to use this in an application, you should set your request Accept header to "application/vnd.senorpez.pcars.v1+json". Why? Because when I roll out data for PCARS2, you'll use the same URLs, but the Accept header will change to "application/vnd.senorpez.pcars2.v1+json" in order to get PCARS2 data. And the "application/json" that's currently being served into a web browser will fallback to PCARS2 since that'll be the latest game version + API version.

There's data missing! If you see a track with a length of 0, that means it hasn't been verified with in-game telemetry capture (for length and what the game calls it in telemetry). If you see an event with "verified: false," that means it hasn't been verified, so the round names and car eligibility could be wrong. If you want to help, you can do so. Please use verified telemetry or screenshot data, though... there are some quirks between what you might think is right and what the game internally uses. The object of this is to align with that captured telemetry, so that there's nothing lost in translation! I wanted to get to this last month, but the job-drama has kept me from playing PCARS for a month.

v1 is currently unstable. If you build an app against this, expect it to be broken. (That being said, v1's probably pretty close to being finished.)

Help is always appreciated. I'm far from a professional programmer, but I'm getting better... and I'd love to learn from you, and in turn, make something awesome for PCARS2.

The API is designed to be HAL compliant. http://stateless.co/hal_specification.html

Questions
I can't seem to get a complete list of, say, cars.
That's correct. HAL and REST are somewhat expected to be "chatty." For example, you can get a list of all tracks at http://www.projectcars.senorpez.com/tracks, but to see individual track data, aside from the name and ID, you need to open each link. That's intended behavior. Keep in mind:

The chunks of data opening each track is a tiny web transaction, and it's running on a Java+Spring backend, which will optimize the calls even further. Transferring huge files is bad.
The API isn't really intended for human consumption, so "clicking" 100 links to get data for all 100 tracks in the game isn't actually all that onerous if you're a machine. And since, as above, the chunk for each track is small, you can also do this in parallel, making it fast and efficient, at the expense of you hitting my webserver 101 times instead of 1.

SenorPez
12-06-2017, 19:54
I've added in data from the list of (sort-of) confirmed cars and tracks for Project CARS 2. You can access them by setting the GET request Accept header to "application/vnd.senorpez.pcars2.v0+json; charset=UTF-8".

SenorPez
26-06-2017, 20:33
As of right now, I'm calling the data model for PCARS done. Once the data integrity test is complete (it takes about 24 hours), I'll release this as V1.0.

Note that this does not mean the data won't change. I'm still working on verifying what I can. But unless there's a serious issue, the structure in which that data is presented through the API will not change, at least not without a version update.

Now, to see if I can get this up and running in time for PCARS2? Unfortunately, I've already got plans for a few days after the 22nd, so I'll miss the initial rush... and I should find a job that actually pays me before then. *sigh*