Showing posts with label basketball. Show all posts
Showing posts with label basketball. Show all posts

Sunday, November 04, 2007

2007 Fantasy basketball script released

*update - 2/22/2008 - updated the script to handle new yahoo boxscores for in progress games

I couldn't sleep last night (Friday night...actually Sat at 2am to be exact) so I stayed up and implemented the two missing features for the live stats basketball script: maintaining the order of players in the modal window and displaying a summary of all active players' stats.

The first feature was easy to implement since I had already solved that problem for baseball. The old technique of adding a row after retrieving a player's stats leads to indeterminate ordering because we do not wait for a boxscore request to finish before moving on to the next. Therefore, it was possible that a UTIL player who is towards the bottom of the management page would actually be processed faster than a PG depending on how snappy the server handled the request. The solution is to create placeholder rows that have the correct order and then update those rows later.

The second feature is summarizing all your players' stats for the night. Unlike a baseball boxscore where a player's stats appear on multiple parts of the page and some stats need to be derived, all basketball stats appear on one row. That's why I didn't create full blown function objects that had getter/setters for stats like assists, turnovers, pts, boards, etc. Instead, I went the lightweight route and defined two rules that are used to summarize stats. If the stat has a dash, like 7-11, then we keep track of total made and total attempts, else we just sum up the current stat with the running total.

Wednesday, October 31, 2007

halloween treat

No candy to pass out but I did make a few tweaks to my fantasy basketball live scoring script. Like the modified baseball version, the script no longer automatically loads. The user has to trigger it by clicking on the 'show freebie stats' link. I also ripped out the autocenter on scroll code since that was causing display issues for users on low resolution monitors.

The two biggest missing features that I will tackle next are maintaining the order on the display and totaling all your active players' stats. But I probably won't get to that until the weekend. don't fret, yahoo provides free stats for the first couple of weeks of the season so you're covered.

Thursday, September 20, 2007

Would you leave 63 million on the table?

Andrei Kirilenko would. He's so unhappy playing for Jerry Sloan that he's willing to forego the rest of his max contract which equates to 63 million dollars. Is this guy for real? Most guys want to void or renegotiate their contract to make more money. Kirilenko's already got a max deal and the way he's played the last two years he's never going to get that sweet a deal again.

He played for the Russian team this summer and was the main man so maybe he missed being the go to guy. Maybe he just really misses home. Maybe he was misquoted and the interview was taken out of context. Maybe a Russian oil tycoon has promised him even more cash to play in Russia.

Whatever the reason I'm sure more of the story will come out in the coming weeks. I've always been a big Kirilenko fan. He won me over many years ago when he went ballistic in a Rookie vs Sophomore game during All star weekend. The other players were playing lackadaisically and AK was subbed in and was a beast of defense. He guarded guys tight, swatted shots, and went to the basket hard. It was refreshing to see since those games are more and1 than nba. He's also been a favorite because he resembled Ivan Drago from Rocky IV so my old roommates and I would shout out the "I must break you" voice every time he blocked a shot.

Good luck Kirilenko! I hope you get whatever makes you happy. I'd definitely like to see you in a Warriors uniform.

Tuesday, February 20, 2007

2007 nba dunk contest

Two thoughts entered my mind when I was watching the slam dunk competition:

  1. Must be a direct correlation between the winner and the win pct of their team because the last couple of years players from the Celtics, Knicks, and Hawks have won.
  2. Dwight Howard was robbed. That sticker dunk was original and difficult. He also had to do it in one attempt or else the shock factor would have been lost.

Tuesday, October 31, 2006

yahoo fantasy basketball live scoring greasemonkey script

Updated 2007-Nov-04: Updated the script to calculate team totals and also maintain roster order as it appears on management page.

Updated 2006-Nov-05: I cleaned up the boxscore processing code to implement a feature my friend Simon requested: Viewing the live stats of other managers' teams. Be sure to update the script to use the new features.

I didn't write a baseball script until after the all-star break and I passed on writing a football script since it wouldn't save me much time. But tonight I finished a greasemonkey script that provides live scoring for yahoo's fantasy basketball leagues.

To use it, download the newest version of greasemonkey and then install the script. Yahoo provides live scoring until nov 11 so you've got plenty of time to dissect the code to make sure it's safe :) Don't worry, unless someone has hacked into my code repo (very unlikely since it's hosted by google), the script does not contain nefarious code. That's always my biggest concern when installing scripts written by others since it's so easy to place code then sends data to other remote servers. That said, the script is provided as is so if it drops Kobe or Lebron from your team then oops :) I'm only kidding...I've tested it on windows xp prof running firefox 2 and the latest version of greasemonkey and have had no problems.

Here's a screenshot of the script in action. Note that the bench players have a darker background color:

The logic of the script was similar to the baseball one. First, I parsed out the boxscore links and then I made an ajax request to retrieve the contents of each boxscore. Finally, I used xpath to find the stats for my player. The techniques I used for xpath and ajax are explained in detail here. Although the business logic for the script is similar, I employed a vastly different view for presentation. Instead of embedding the stats directly into the existing table cells like in the baseball script, I placed the basketball stats inside a modal window.

Using a modal window greatly simplified my code because I didn't have to keep track of each stat and its corresponding display cell. Instead, I could copy the row node from the boxscore and place it directly into my modal window without any extra processing. I also noticed that my fantasy football team's page on sunday night no longer had placeholders for stats. The modal will bypass this problem should yahoo implement something similar for fantasy basketball.

There are a couple of different methods to implement modals. The contents of a modal can be from an iframe or a hidden div. My script uses the hidden div technique since the stats are added to the DOM on the fly. If you're interested in implementing something similar, a must read is this blog posting on modal windows. I used that technique along with some others that I picked up while implementing modals at work. In fact, the autocentering code is from an enhanced, iframe-based modal library called submodal that my boss Todd has greatly enhanced.

One bug that took me a while to track down was that some players made multiple ajax requests. I added logging using greasemonkey's GM_log api and discovered it was related to my xpath expression:
//table[@id='statTable0']/tbody/tr/td[@class='player']/div/a[@href]

this expression finds all player profile links but it also found links to the 'breaking news' about the player. I fixed the problem by adding an extra check for the a tag: a[@class='name' and @href] ... problem solved :)

Enjoy the script!

Thursday, March 30, 2006

back in business

Ucla is going back to the final four. Our storied basketball program is back in business and returns to its familiar place among the hoops elite. Like enjoying a good wine, I needed to savor the memories of defense and clutch plays before penning my ode to this tournament run.

When the brackets were annouced and Ucla claimed a number 2 seed I knew we would make it to the final four. Getting past Gonzaga was a real test of my faith but these kids came through. We unleashed a suffocating defense and Coach Howland managed the game to perfection.

Thanks to streaming video from march madness on demand, I replayed the clutch Hollins free throws and the ensuing steal to find some great coaching nuggets. After the free throws, Hollins was quickly subbed out for a quicker Collison. Collison's responsibility was to cover deep which freed Mbah a Moute to cover the player inbounding the ball and allowed Bozeman to switch over to Batista. The ball was inbounded to Morrison who made a great pass to Batista. Batista was quickly swarmed by Farmar and Bozeman was able to knock the ball loose. Howland was in the game the entire time..perhaps it was coincidence that the play turned out the way it did, or maybe it's just because the guy can flat out coach.

It's so great to see the maturation of the players and the team's level of playthis past season. Ryan Hollins just became a millionaire by his play in this tournament alone. It's great to watch and I'm looking forward to this weekend's game.