Innovation Session: The History of NFL Win Percentages – Part 4
Continuing what I’ve been working on lately – tonight I’m going to try and get all of the data loaded for my NFL chart and hopefully get the javascript to automatically loop through and chart each team’s record.
Refactoring
As I dove in tonight I realized that the way I was doing things wasn’t going to work. D3.csv() loops over every row in the csv that is loaded and performs the described operations on it. I was looping over the season data which meant that I was doing things hundreds of times rather than 32.
I decided to refactor my code so that I now loop over the team data csv and then for each team go pull the season data as part of the process.
The first roadblock I hit was that javascript data types are a bit strange. It took me a lot of trial & error to figure out what type of thing I was dealing with and get it to work properly.
The second roadblock was with the way I am accessing the second csv, the one with the season data. Because it is asynchronous, I wasn’t able to return the formula for the line to the place that calls it – I then tried plotting from within the call and ended up with hundreds of the same line.
I think I need to load the second csv using a different process.
Nothing is working right now, so I haven’t updated the live code, but I updated the code on github if anyone feels like taking a look and helping me out of this jam.