Player Stat Gathering
Saturday, June 7th, 2008Today I built-out the mechanism for gathering players’ stats. In the original model, every time anyone loaded a Team page in the Fantasy Stat Tracker, a request was made for each player for an XML file on mlb.com with that player’s stats. It worked, but it seemed like a little overkill. If multiple Users with the same player checked their pages, multiple requests would be made for that player’s stats. If a single User re-loaded their Team page, requests were made for every single player’s stats whether the stats had changed or not.
In the new model, the Fantasy Stat Tracker gathers a player’s stats and saves them to the database with a timestamp for when the stats XML file was last updated. For subsequent stat requests the application first checks if the player’s stats file has been updated on the remote server. If it hasn’t, it simply uses the existing stats in the database. If the stats file has been updated, it will be downloaded, saved to the database with a new timestamp, and the updated stats will be used.
Theoretically this should speed up the Fantasy Stat Tracker a bit. Downloading stats from a remote server takes longer than getting them from a local database. By removing most of the requests for remote stats files, the application should be able to render Team pages quicker.
In addition, by using local stats in most instances instead of downloading them, the Fantasy Stat Tracker should dramatically cut down its bandwidth usage. With the current number of Users and requests in the application, bandwidth isn’t really an issue yet. But if the Stat Tracker becomes more popular, hopefully it’s future-proofed a bit.
One complication with this new stat gathering method is that it is very difficult to test. I can’t fiddle with file dates on mlb.com so I can’t test how the new code will work as the day rolls over to tomorrow and new games begin. If you see any errors in the application, I’d appreciate if you could copy the text of the error message and shoot it to me in an email at fantasy.stat.tracker@gmail.com. Thanks for your help in making the Fantasy Stat Tracker better!