Labs: NASCAR Update

by Marty Alchin on September 11, 2009 about numbers

It’s been almost two weeks since I launched my labs, and I thought it was high time for an update. Even though the travel experiment is my most exciting one, I wanted to spend some time giving some love to NASCAR this week.

When I launched, I just had the top ten drivers from one race, entirely hand-coded into HTML, so I could test out the CSS and make sure it was a viable option. NASCAR provides a data feed throughout each race, which I’ve been capturing for a while now, but I hadn’t wired up the pieces to use that feed to produce the display. Until now.

The new leaderboard is driven (pun intended) entirely by NASCAR’s data feed. The current display is still static, because there’s no race going on, but it was generated completely by pushing NASCAR’s data files through a relatively simple Python function. This produces a data structure that can then be fed straight into a Django template to produce the display you see here. I plan to wire up a cron job that will regenerate the page every minute throughout both of the races this weekend, which should be easy now that all the feed parsing is finished.

There are a few minor changes this time around, now that I have a full field to work with. First, the “behind” column now shows drivers who aren’t on the lead lap. For drivers on the leap lap, a bar displays, showing how much of the lead lap is between them and the leader. This is computed based on the time they’re behind the leader and the leader’s lap time, so I can get a proportion of the lead lap they need to make up. For cars not on the lead lap, a percentage doesn’t make sense, so it simply shows how many laps behind they are. At the bottom of the field, a few cars were marked as inactive, due to either bad accidents or other vehicle failure, so those names have been faded to indicate this. It helps explain why they’re so many laps behind.

The Movement column stayed the same (though I really need a better name for it; I’m accepting suggestions), but the Laps Led column got a minor update as well. Now that the backend support is capable of calculating the threshold for winning the most laps, the gray line will move to the left in the second half of the race, depending on how the leaders have been distributed throughout the race. In addition, any drivers who are mathematically incapable of getting the most laps (there just aren’t enough laps left to lead) are marked in gray, so you can focus on those drivers who still have a chance. Naturally, at the end of a race, there will typically be only one still in black, but there can be a tie for the most laps, at which point they’ll both be in black still, since they both get the points.

Goals for the future

The Points column hasn’t changed at all, though I think I need to do something with it. With values in the thousands and added points being just a couple hundred at most, the limitations of pixels become fairly apparent. Not all the bars are exactly the right width, due to this limitation, and rounding in the browser can cause things to look weird if you’re examining the raw values. In order to really work well, I think this column needs to be much wider, but I don’t think it should dominate the display, either. I’ll see if I can come up with something.

Also, I didn’t expect to add new features beyond making it live-updating during a race, but I’ve thought of a couple new things I’d like to try out. This weekend is the last race before the chase for the cup, where just 12 drivers have a chance to win the championship. Those 12 are determined by their point totals after this weekend’s race, so it’s always the same 12 for the rest of the year, but they race alongside 31 other cars, just like they’ve done all year. This presents on opportunity for the visualization to shine by showing the whole field while highlighting the chase drivers, since that’s where most of the attention will be focused. I’m not sure how I’ll highlight them yet, but I’m thinking a slight color change (blue instead of black, for instance) would suffice.

Lastly, I notice that my wife (and most other fans, I’d wager) has favorites that she keeps track of during a race. I’m thinking about adding a star next to drivers that will allow users to mark a driver as a favorite, so that driver will be highlighted throughout the race. I’m thinking just bolding the name of the driver would be enough to make them easier to pick out in the list (the marked star would also help). Of course, as long as I’m regenerating the page statically throughout the race, this isn’t an option, so it may have to wait until I can flesh out a proper database-driven backend for it, which may have to wait until next season.