SlotForum banner

Live(ish) race data to any mobile device

9529 Views 104 Replies 11 Participants Last post by  Martyn_
Following on from a discussion on a HO thread (and talking with Dave who produces RC) about people having to crowd round a single screen, I thought it should be trivial to publish the data so that everyone can look at a web page on their iPad, iPhone etc. So it wasn't trivial (and there is someway to go to tidy up the screens) but it only took 3 or 4 hours to get the prototype working with Race Coordinator.

Here's a bad photo of it working, the photo shows a race in progress, while the iPod shows data for all run heats upto that point.
http://www.slingshotx.byethost17.com/zenph...bupdate.JPG.php

So here's what you need.
A network enabled PC running Race Coordinator http://racecoordinator.net/
A Lightweight Web Server that is able to run PHP scripts, there are plenty of free ones available I used something called Resin http://www.caucho.com/download/resin-4.0.30.zip
My prototype php script below.

Edit the couple of lines at the top of the script for the location of your RC files.
Copy the script below called results.php to webapps directory of resin i.e. C:\Program Files\resin-4.0.30\webapps\ROOT
Start a race and browse to http://129.168.?.?:8080/results.php and at the end of every hit if you hit refresh you'll see basic data for all racers.

Couple of things:-
if you can't browse to http://129.168.?.?:8080 then it may be you need to open 8080 on your firewall (especiall Windows 7 users).
Some of the data I've grabbed is wrong.
The data is only updated once a heat has been completed (I don't see this as a problem, you want to checkyour lap times & result after your heat)
It's pretty basic, I'm hoping someone will take on the task of building some nice screens.
If there is no ongoing race it defaults to viewing the most recent race completed.

If people want this functionality then we can tidy it up make it configurable, maybe RC can optionally pubish live data i.e. after every lap for real live race data to your own device (anyone for live callouts into your own headphones of laptime, gap etc?).

It's pretty easy to setup, whilst I'm a software engineer I've never installed a Web Server before or written php, so shouldn't take a genuis to get it working, I'll help where I can.

Let me know what you think.

CODE

Results

<?php

// Things that may need changing at the top
// This is the RC folder to search for json files, it will vary depending on Windows 7 / xp
// Windows 7 it will be something like C:\ProgramData\Race Coordinator\saves on xp it will be
// C:\Documents and Settings\All Users\Application Data\Race Coordinator
$RCDataDir = findLatestFile("C:/Documents and Settings/All Users/Application Data/Race Coordinator");

// Setup an array of lane colours so each driver can tell what lane they were in rather than a number
$lane = array (1=>"Red", 2=>"Blue", 3=>"Green", 4=>"Yellow");

// Searches for the latest file in a directory
function findLatestFile($dirName)
{
$lastTime = 0;
$latestFileName = "";
foreach (glob($dirName) as $f)
{
if (filemtime($f) > $lastTime)
{
$lastTime = filemtime($f);
$latestFileName = $f;
}
}
return $latestFileName;
}

$latestFile = findLatestFile($RCDataDir . "/saves/*/*.json");

// If we didn't find anything in saves then use the stats and look for the last race completed
if ($latestFile == null)
{
$latestFile = findLatestFile($RCDataDir . "/stats/*/*.json");
}

// Load the json file up, and decode it into a PHP object
$Vdata = file_get_contents($latestFile);
$JsonObject = json_decode($Vdata);

// Loop around each driver that has raced
foreach ($JsonObject->config_->driverList_ as &$driver)
{
print("Driver ".$driver->driver_->name_."

");
printf("Best Lap %.2f

", $driver->bestLapTime_);
printf("Worst Lap %.2f

", $driver->worstLapTime_);

// Now get each heat the driver has been entered in
$ctr = 0;
foreach ($driver->heats_ as &$heat)
{
$ctr = $ctr + 1;
$position = $heat->finalPosition_ + 1;
print("

$lane[$ctr] - ");
printf ("Position %s - Laps %d - Avg Lap %.2f - Lap Times ", $position, $heat->finalValue_, $heat->avgLapTime_);

// Now get the time for every lap in this heat
foreach ($heat->lapTimes_ as &$lap)
{
printf("%.2f, ", $lap);
}

}
print ("

-----------------

");
}
?>
See less See more
1 - 15 of 105 Posts
First off I have to say I think where this is going is the future of RMS development. It's a "headless" management system in which any third party can simply write whatever display they want. I wanted to do something like this right out of the gate but decided there weren't going to be enough people interested in this to justify the fairly large development cost. Now that things are VERY stable for RC, this is a good time to start thinking about it again.

So far, Slingshot has done something that in my opinion is very clever. He's accessed RC's auto save file format and realized that although its a bit cumbersome, it's actually a very easy format to parse. There are off the shelf libraries to do so and when he calls "json_decode" that's what he's doing. From there he just needs to know what is what. That's where I can help tremendously since it's my data he's parsing. The other clever thing he's done is to find and use the newest .json file he finds. What this means is that you can actually save the race at anytime to get the data out. I'm not sure if he realizes it or not, but he has access to every single stat the RMS tracks up to the moment the auto save (or manual save occurs).

To take this to the next level, what we need to do is identify the minimum set of data that would be useful and then sort it by static vs. dynamic data. So for example, RC could very easily write out a "heat rotation" file. Now anybody that wants it can display the heats any way they want. We could do something similar, automatically every time a lap occurred, or every time a second of time went by. We can write out the leader board information as it changes as well... Whatever. The hard part is figuring out what to write out and when it's useful to do so. I'd be more than happy to work with somebody on this, but it's not enough for me to write the data out. Somebody has to really go to town with the php scripts and demonstrate this features power.

For those of you who have emailed me in the past, you probably know that I'm happy to help. It just takes a few conditions to be met for me to get involved. First, I have to deem it valuable to my entire RC user base. Second I have to deem it worth the effort. If I got 1000 requests to do a mac version I still wouldn't because of the effort, but if I get simple enough requests that benefit the software, even if just a few people request it, I'm happy to donate my time. This particular feature is cool enough that as long as people work with me to do it right, I'll throw down. But I'd need to see the end results. Otherwise it's just more code I have to maintain which in the end just makes my life harder.

-Dave
See less See more
The json files are literally a serialization of the entire apps state. That's why I can re-load it later. So yes, everything you could ever need is in there (including every lap counted), but there are two main issues. First, this file is currently only written out as an auto save at the end of the heat. I'm not sure if the older computers used to run races could handle writing those files every time something significant happened and besides it would be more ideal to write something a little cleaner and easier to use. I know at least the EACHORC guys want to see laps updated in some way that they can then graph the current heat progress. With dynamic file updates the php script could very easily do something like that.

I also think there are things that are harder to derive from the data than you'd think. Even something like the heat list is "hard" to derive because you have to understand RC's definition of "round robin" (or whatever rotation you're using). Even just deriving the final standings would be a pain in my opinion. Again you have to understand the intricacies of all the race settings, understand tie breakers, etc...

What you really want is a json format that leaves nothing to chance. Everything is spelled out so all the webserver has to do is pick and chose what data it wants to serve up. I think what we've seen so far is fantastic. The next step is to start thinking about how to apply it and have somebody work with me to do just that. Personally I thought this would be most useful for per driver displays. Maybe you have an ipad at every driver station that is showing relevant information for that driver. Maybe you have a page served up that is a "detail" view for each driver in the race. This detail view gives information like when their next heat is, and other lap information... RC already basically stores every stat possible, so the sky is more or less the limit.

QUOTE (diesel @ 4 Sep 2012, 07:02) <{POST_SNAPBACK}>I think the json files provide all the historic data that is currently needed. Are leaderboards required to be generated? Surely this is all just dervied data and better compiled outside of RC? So long as the race data is updated after every heat then that will do nicely.

Heat rotation details would be essential. At the moment we could only remotely see what has happened. Being able to show who's racing now/next in what lane is so useful. This info would need exporting after every change, but that wouldn't be too often.

I still love the idea of logging every lap so that pseudo-realtime race detail/lap graphs could be generated. Of course if you wanted to go to town you could add lap times to this too.
See less See more
Rick, for me the point of this is much more the real time application. In a very "web friendly" way you can setup screens to display pretty much anything you want. Heck, you could probably have it call or text your smart phone. The point is you're breaking away from the confines of what the application can do and you can basically do whatever you want with out updating the RMS. In the long run I see this as a PC-less system that serves up the race data to the internet. Any PC, Mac, tablet, or smartphone can then display the data any way it wants. If nothing else analog racers would finally have an out of the box one stop solution for a track interface. And the best part would be that if their "device" has a webrowser, it can display the race data.

Of course this same technology can be used to post race results after the fact as well.

QUOTE (injectorman @ 4 Sep 2012, 20:29) <{POST_SNAPBACK}>Ok Ive been thinking about this one. What benefit can an iPhone have over a PC and wall mounted monitor?
Am I going to look at my iPhone while I race? No.
Am I going to look at it after the race....yes. And its handy to have your own copy handy.

Wouldnt it be just as easy to SMS (via PC, multiples at once) or email the results after the meeting so they come up on your iPhone anyway?
Im just trying to weigh up any advantages over the effort.
Rick
See less See more
Kevin,

If you're interested I'll work on this with you. I think in the long run the best thing to do is to NOT use the auto save files like you're doing. For one thing they could change every single release. For another there's just too much junk in them.

Really we want to keep the json file(s) really simple and let your php scripts do all the work. I'm thinking I would generate a json object for everything we're trying to accomplish. One for a heat list, one for the on deck list, one for heat laps, one for race laps, one for heat standings, one for overall standings, one for anything else we find we need/want. Once the format of the json object is figured out your script just needs to find the latest files and present the data...

Anyway those are my initial thoughts, I pretty up the data with out losing any needed information and to minimize the amount of data written real time, and the php script manipulates it. If we do something like this we shouldn't do it on the forums... I much more interested in hearing what features people want here, and then working offline with people implementing them on the details.

-Dave

QUOTE (Slingshotx @ 4 Sep 2012, 16:55) <{POST_SNAPBACK}>Just been away for a few days too catch up some good ideas here, but ideas are easy implementation is difficult. I think with Daves help I can get at all data RC holds (as Dave said it's all in the json files) proccessing json is quick and easy, I believe the only thing needed would be to add configurable write periods, anything can then poll the file.

Let's keep it simple I've seen to many projects fail due to trying to fulfill too many requirements. Some peopl maybe need to look at their requirements and if they can change the way they race rather than make the software be what they want.

Kevin
See less See more
I'm going to start putting serious thought into this. What I can tell you is that it won't be XML 100% for sure. Right now I'm leaning towards building a webserver into RC that will respond to HTTP Get/Post messages. Any response will have a JSON payload. This will require web designers to poll me for data, but by doing it this way there's no overhead to the software unless somebody actually does poll it. I suspect in the end we'll have a protocol that gets access to virtually everything. We'll start with simple things that make sense on the phone and go from there.

Oh, and for the non-technical, we're essentially turning the RC display into a web page (keeping the current display unchanged of course). This means a lot of things, but one thing it means is that you can do basically anything you want. If you want to play audio when a lap is detected, or when a drivers fastest times happen you can. In the long run, we'll be able to have "detail" pages specific to a driver. Really as long as the protocol we setup allows for the data retrieval any web designer can do anything they want with the data... You can more or less do this now in XAML, but it's cumbersome especially to do something like play audio. And the XAML is only supports windows, which this will clearly support any device with a web browser.

QUOTE (-Sy- @ 5 Sep 2012, 07:26) <{POST_SNAPBACK}>I would strongly recommend going the XML root as it means the content is unchanged, but the style and format in which the data is presented can be different for each club and each device.
See less See more
I could throw myself into the middle of a JSON vs XML battle, but instead I'll put it this way, 100% for sure, with out a doubt, it's going to be JSON. We'll provide an example php script (hint hint, we've already see the start of it) and we'll support people writing there own. This feature is not intended to be plug and play. It's intended to empower a reasonably technical person to do really powerful things.
Just so people know, what he is doing is available to anybody to do. He's discovered a little bit of techy information about RC's save files and he's taking full advantage of the knowledge. You can literally do anything you want with the data as long as you have somebody technical enough to do it. What he's got is a big of a hack in terms of how he has to access my save files. Now that I've see this in action, I'm working on a protocol that will formalize the support. This is significant only in that it means I'll support it 100%. As it is, I could do a new release and break his scripts. Right now there's nothing I can do about that and the only thing that could be done in that case is to update the scripts. Once I have a build with the protocol in place, people will be able to migrate over to it and know that unless there's a flaw in the protocol, they'll never have to touch their scripts again once its up and running...

For what it's worth, down the road I can see me going away from the XAML file race day screens and using this exact technology to driver screens. This would allow a much scriptable (dynamic) interface than we have now. For example, you'd be able to build your own Sections editor however you like, including editing the lap counts right in the column data. It's really very exciting. I just need the time to get to it.

And well done Slingshot et al... what you have currently is pretty amazing considering how very little I helped. In fact, I don't think I helped at all, so very well done...

-Dave
See less See more
All thanks go to Slingshot for this one. He had the motivation to do it. It just happend that the direction I want to go in enabled him to. But he did it all on his own.

QUOTE (montoya1 @ 17 Sep 2012, 06:15) <{POST_SNAPBACK}>Yeah, well done Dave (and others).
FYI, my hope if/when I find the time for this support is to have RC handle a lot of this work for you. You'll optionally be able to configure RC to host this information and then in theory anybody on your local network will be able to go to the web page(s) to see the information. Keep in mind that you can also use this same technology to host the pages on the internet, but that requires understanding how to setup the webserver properly so that it's accessible to the outside world. For somebody who's done this sort of thing before, it should be really easy.
Data export and this web server stuff are very powerful features, but they don't come free. I'd expect almost every single user of these features to tweak what we provide. How they tweak it is up to them and what support options I have.

For example, some users will modify the xls template and get the exact export they want. Some will modify it, then post export modify the data further. This is all the same thing. When I'm done, you'll have realtime access to the race data. But it will almost certainly be in a format that is unusable with out modification. Slingshot has scripts that modify the data and present it as web pages. You might have scripts to do that AND put the data into your own data base. My plan is to build in a clean reliable system for doing what he's doing now. Which will in turn give you all the access you could ever want/need. But again, even if you have access to his scripts or the ones RC will inevitably come with, more than likely you're going to want to tweak them to present the data how you see fit.

Everybody needs to realize that the features this thread is talking about open up a LOT of doors but you're going to need somebody technical to set it all up at your race location and anywhere else you want to directly host RC data. Once the setup is done, it should be a matter of going to a webpage as if you're browsing the internet...
See less See more
If I'm not mistaken, the other thing holding the graphing up from being truly realtime is the fact that you're using my auto save data to get the heat information??? Assuming that's true, once I get the releases I'm working on out (they're taking forever) and I can get back to doing what I want to support this, you'll be able to get "near realtime" heat data so you can generate your graph as laps occur.

It'll be near realtime because you'll have to poll Race Coordinator for the data at whatever rate you want. In the end, if you can generate the graph quickly you should be able to display a pretty up to date view of the heat in progress...
I had asked slingshot to put in a "poll" check for the save file which I believe he already did. That's a start to what you need. The next thing will be changing over from the current auto save files to the HTTPGet protocol I plan on setting up. Once all that's done, BOOM, realtime web based updates. Go team!
Update: I'm now slowly working on proper support for this. I have a build of RC that is a web server capable of serving up HTML files as well as responding to queries. I need to build the proper API to talk to now and get some sample pages setup. The current plan is for me to provide sample HTML pages that can be used as is or you can use them as an example. The PHP that's being done currently will still be doable, but I'm going to provide something a bit simpler...

I could really use somebody who knows HTML (and ideally java script) to help with these screen. Essentially this person would build the screens and I'd provide/fill in the calls to RC to make them dynamic. If there's any volunteers out there please let me know as it'll greatly speed up this effort.

-Dave
Shoot me an email... "[email protected]" and I'll lay it out.

QUOTE (djlutz @ 5 Oct 2012, 01:50) <{POST_SNAPBACK}>Additional info I forgot to mention:

I had set it to 5.

Yes, "Pause" and "restart Race" (new race).

As said, I will continue testing this weekend
.
See less See more
I made a quick video of our progress. I also started a new topic because this is "live" updates not "live-ish"... check it out:

Live Web Updates -- Preview
1 - 15 of 105 Posts
This is an older thread, you may not receive a response, and could be reviving an old thread. Please consider creating a new thread.
Top