Showing posts with label baseball. Show all posts
Showing posts with label baseball. Show all posts

Monday, March 31, 2008

Your 2008 San Francisco Giants

Goodbye Barry Bonds, hello Brian Bocock. This year's team is going to be tough to watch. The heart of our lineup is Randy Winn, Bengie Molina, and Ray Durham. I expect Aaron Rowand to move up from his sixth spot in the lineup within a few games but as of opening day, the 3-4-5 hitters are embarrassing. Thankfully, baseball is not all about offense and the strength of this team is the starting pitching. Pundits predict that we'll win around 60 games this year but I really think we have a good shot at .500 if the pitching performs as expected and if our hitters exceed expectations. Without further adieu, here are my optimistic predictions for the 2008 season.

Pitching

The trio of Matt Cain, Tim Lincecum, and Barry Zito will win 45 games.

The Giants bullpen will be the strength of the team and will be ranked top 5 in the NL in holds, ERA, and WHIP.

Hitting

Aaron Rowand will hit above .300, steal 15 bases, and drive in 100 runs.

Rajai Davis and Eugenio Velez will steal a combined 60 bases.

Benjie Molina will hit .290 with 30 homers.

sorry...I can't do this anymore. Here's my tip for all Giants fans this season: Don't miss Cain and Lincecum pitch and check out the 2008 promotional schedule for some bobbleheads.

Tuesday, October 02, 2007

Fantasy baseball recap

Back in March, Yahoo Sports invited average Joes to go head-to-head against their fantasy experts in baseball. I answered the call and was pitted in a 16 team, head-to-head league with Big Noise himself, Brad Evans. My key draft picks were Chipper, Magglio, Markakis, and Jose Reyes. My waiver wire gems were Ryan Braun and Carlos Pena, who I swapped for Derek Lee just before the trading deadline. My offense carried me the entire season because my only good pitcher was Josh Beckett. Since it was a head-to-head league, I knew that if my offense held up, I could stream pitchers if I reached the playoffs.

Only 6 out of 16 teams qualified for the playoffs and I made it as a 3rd place qualifier. This meant that I didn't have a first round bye which is always a bit dangerous. Luckily, my team held up and I moved on to the semifinals against the 2nd place team. We both had off weeks but my team went on to win. Waiting for me in the championship showdown was Brad Evans' team. He was on a roll and I had to go through him to win the championship. I was up to the challenge and pulled out all the stops like streaming pitchers to win the W and K categories and picking hot September additions such as Jacoby Ellsbury and Norris Hopper.

Just like the regular season, my offense carried me and streaming pitchers yielded wins in the W and K categories. In the end, it was a fun season and I'm thankful that Yahoo opened the league up and that Brad Evans took some time to go up against some of his readers.

Pics or it didn't happen:

Monday, October 01, 2007

Padres out, Rockies in

Thank goodness for TBS. Too bad this game was not televised on the networks because it was an instant classic that saw the Rockies come back against the man with the most saves in the history of baseball. I actually didn't see the comeback because I was peeved that Scott Hairston hit another clutch homer for the Padres and went to do the dishes. This guy has been killing the Giants all year and during the last week of the regular season he tossed the bat about 20 feet after blasting a homer off Matt Cain. Cain let him have it and it'll be interesting to see these guys matched up next year. When I came back from doing the dishes, I saw that the Rockies had won and that Holliday scored the winning run. What a relief that must have been since he was the one that misplayed the Brian Giles flyball that led to the Padres tying the game. If this game was any indication how the playoffs will be played, then we're all in for a treat. My sleeper pick is the Cubs but I think either Boston or Cleveland will win it all.

Friday, September 28, 2007

Giants 2007 Recap

Now that the season is winding down, it's time to revisit my extremely optimistic outlook for the Giants 2007 baseball season. Granted, some of these predictions (see Benitez) were best case, Brady Anderson ala 1996 scenarios, but as the 2005 White Sox proved, it can happen.

Pitching

Prediction: Zito will assume ace responsibilities and that new windup may give him that extra zip and movement.

Reality: The new windup was abandoned in the first week of spring training because the Giants didn't pay for new windup Barry. Barry had one of his worst seasons as a professional.

Running tally: 0-1

Prediction: A seasoned Matt Cain, aka Bobby Hill, will have learned how to pitch

Reality: Cain's W-L record belies how he well he pitched because the record could have been reversed if the Giants gave him more run support or if the relief pitchers didn't blow his leads. He definitely matured from his rookie year and mixed sliders and change ups to go with that nasty fastball.

Running tally: 1-1

Prediction: Noah Lowry might be able to fool hitters once more

Reality: Before Noah got injured he was among the league leaders in wins. He doesn't have overpowering stuff and runs a lot of counts to 3-2 but he still keeps the games close and finds ways to get guys to miss on fastballs never topping 90.

Running tally: 2-1

Prediction: Matt Morris will be able to avoid that one big inning blowup he always has

Reality: nope. same old Morris after a promising start and eventually traded to the Pirates for Rajai Davis.

Running tally: 2-2

Prediction: The fifth starter, whether it is a renewed Russ Ortiz or rookie sensations Linceum or Sanchez will surprise the league by storm.

Reality: I sure gave myself some leeway here by counting on at least 1 of 3 players to have a good year. Lincecum really did show the league that he's a special player. Whenever he pitches the opposing team is always at the railing checking him out.

Running tally: 3-2

Prediction: Benitez will be in shape and less of a headcase.

Reality: Nope. same old Benitez. Traded before the break to the Marlins for Randy Messenger.

Running tally: 3-3

Hitting

Prediction: old guys will be injury free

Reality: wishful thinking. Durham, Roberts, Bonds spent significant time on the DL.

Running tally: 3-4

Prediction: Barry Bonds will break Hank's record by early August so the team can concentrate on the playoff push

Reality: Barry broke the record in early August but playoff hopes were pretty much gone at that point. half right = half wrong = a push

Running tally: still 3-4

Prediction: Dave Roberts will be that leadoff hitter we haven't had since Brett Butler

Reality: injured for most of the first half, came on strong for awhile and then leveled off. Splitting time with Rajai Davis so can't say he's that good.

Running tally: 3-5

Prediction: Rich Aurilia pounds 40 homers and shows Seattle fans why they once signed him to big bucks

Reality: yeah right. that was the last prediction so I went for the juggernaut. Rich Aurilia couldn't beat out Ryan Klesko for the starting first base job.

Final tally: 3-6 which pretty much sums up the Giants season. But next year, we'll be back.

Friday, September 21, 2007

It's official. The Barry Bonds era has come to an end

It's official. Barry Bonds will not be a San Francisco Giant next year.

Many people outside of the Bay Area don't understand the relationship Giants fans have with Barry. We know he took steroids. We know he's arrogant. We know he's mean to reporters. So why is it that we don't hate him like the rest of America? Because he's a Giant. Because he grew up in the Bay Area. Because his dad played for the Giants and because his godfather is Willie Mays. Because he's not the only guy that ever took steroids and because he was a hall of famer caliber player before he juiced up. Because 1993 was a magical season.

To be competing for a division title a year removed from a woeful season and rumors of a move to St. Petersbug was invigorating. Suddenly it was fun to be a Giants fan again. Barry put the franchise on his back and carried the organization through the opening of Pac Bell Park, into the World Series in 2002, and even up to when he broke the home run record. That's a lot of great memories. He's been the face of the Giants for 15 years and when you're loyal to your team, you're going to be loyal to the face of the franchise too. Go Giants!

Thursday, April 12, 2007

2007 yahoo fantasy baseball script

update 4/24/2007
Script updated. Fixed issues 3 and 6 reported by Rodric Rabbah and lots of code refactoring. The script no longer automatically loads the window. You have to activate it by pressing on the blue "Show Freebie Stats" button on the top right.

update 4/18/2007
Script updated. Fixed issues 4 and 5 reported by Ethan Herbertson.

update 4/16/2007 To use the script, follow these 3 steps

  1. download firefox
  2. install greasemonkey extension
  3. after installing greasemonkey, install the script

I just updated my fantasy baseball script for 2007. The most obvious change is that I incorporated the UI from my fantasy basketball script but there are also a bunch of under-the-hood fixes too. I go into some detail in those two blog postings on how the scripts are implemented so I won't recap any of that here but I will describe one bug fix. Stolen bases and homers are not part of the boxscore and they require extra parsing.

The stolen base string is of the form: D. Roberts 2 (2nd Inning off J. Bard), B. Bonds (3rd inning off J. Bard)

My old regular expression was a simple check to see if a players name was part of the string. The problem was that if I had J. Bard on my team, then he got a stolen base even though he was the one that allowed the steal. To fix the problem, I deleted everything in parentheses first.

That regular expression looks like: statLine = statLine.replace(/\([^\)].+?\)/gi,''); The key is '?' which makes it a non greedy match and [^\)] which tells the engine when to stop.

Another thing that bothered me was calling mozilla's childNodes method on a table row returned some unexpected results. Instead of returning a list of td elements, it would also return some additional children. To remedy this annoyance, I call row.getElementsByTagName("TD") and then I get a list of td elements that I expect. That said, I'm much happier with Mozilla's handling of the dom api and the development plugins available in FireFox. My day job is as web developer for a high traffic site where we strive for pixel, perfect perfection between IE 6,7 and firefox so developing for just one browser was a nice break.

Install the script.

Friday, February 16, 2007

a fresh start

It's a great time of year to be a baseball fan. The weather is warming up, your team has made some key offseason moves, and everyone is tied for first. I first became a fan in 1987 while rooting for my hometown team, the San Francisco Giants. I read every single baseball book in my elementary school library and became fascinated by larger than life personalities with colorful nicknames like the 'Sultan of Swat', the 'Say Hey Kid', and the 'Yankee Clipper'. I sneaked a walkman to bed and either fell asleep disappointed or happy depending on the outcome of that night's game. It remains the only sport where the radio broadcast is just as enjoyable as the television broadcast.

I also like the team and individual aspects of the game. A pitcher relies on the players playing behind him to make plays and to score runs. Yet, at its core is the battle between the hitter making solid contact against a pitcher. There's also the little things about the game that just work. Ninety feet is the perfect distance between first and home since the speediest runner can still be thrown out when defense is played perfectly. That distance is as cool to me as closures. While the infield is of uniform dimension, the outfield can vary widely between stadium to stadium. A ball crushed to right-center will be an out in Pac Bell Park but a homer in practically every other stadium. While park designers may embellish these idiosyncacies, *cough Minute Maid Park hill*, there's no denying the beauty of the Old Tiger Stadium and Fenway Park.

The optimist in me believes the Giants can make a playoff push bolstered by their improved pitching. Zito will assume ace responsibilties and that new windup may give him that extra zip and movement. A seasoned Matt Cain, aka Bobby Hill, will have learned how to pitch, Noah Lowry might be able to fool hitters once more, and Matt Morris will be able to avoid that one big inning blowup he always has. The fifth starter, whether it is a renewed Russ Ortiz or rookie sensations Linceum or Sanchez will surprise the league by storm and Benitez will be in shape and less of a headcase.

On the offensive end, the old guys will be injury free. Barry Bonds will break Hank's record by early August so the team can concentrate on the playoff push and Dave Roberts will be that leadoff hitter we haven't had since Brett Butler. Rich Aurilia pounds 40 homers and shows Seattle fans why they once signed him to big bucks.

Its a great time to be a baseball fan. We're currently in first place.

Sunday, August 13, 2006

greasemonkey fantasy baseball script

update: 4/12/2007 Updated script for 2007 season. update: 8/21/2006 added HR and SB support and also optimized some xpath processing.

I'm a big sports fan and one of my favorite hobbies is playing fantasy sports games on yahoo. For the season's first couple of weeks, yahoo provides real time stats for all your players. But after that, they package this feature into their 'premium services'. The only way to get live scoring is to pay for it or to click on each box score link and then scan for your player. If the game has already ended, it's actually two clicks since the initial link takes you to the game recap.

This is can be quite time consuming if you manage multiple teams but you really have no choice. ...that is, no choice until now: This weekend, I wrote a greasemonkey script that iterates through all the boxscores and parses out your player's stats for the night. Once the script has finished running, you'll have live scoring!

I've written it for default baseball leagues but a football one should follow shortly once I get around to drafting my football team. here's a screenshot of how my players performed tonight:

You can download the script here: http://freebiestats.googlecode.com/svn/trunk/baseball.user.js

Feel free to send feature requests or bug reports here: http://code.google.com/p/freebiestats/issues/list

This is my first greasemonkey script and I'm quite impressed with the whole framework. After the page renders, greasemonkey kicks in and can manipulate any part of the dom. The flow of my script is as follows:

  1. get the box score link for each player
  2. visit that link and get the player's stats
  3. update page with the stats

Firefox has a kick ass xpath implementation so finding all the box score links was pretty easy. It helps that my xpath was pretty sharp from all the xml feed projects I've been doing at work. The xpath for the batters is:
//table[@id='statTable0']/tbody/tr/td[@class='player']/div/a[@href]

The only time consuming part when developing this script was figuring a way to visit and process the box score pages. I definitely wanted to create a dom for the box score page so that I could use the aforementioned kick ass xpath functionality but my first attempt using greasemonkey's GM_xmlhttpRequest function wasn't too promising. I had no luck transforming the raw html returned by GM_xmlhttpRequest to a dom using DomParser. This must be a common problem because a google search yielded this workaround in greaseblog. That solution:

var parser = new XPCNativeWrapper(window, "DOMParser").DOMParser();
alert(parser.parseFromString("", "text/xml"));
seemed a bit hackish and it would only work for xml documents. Since the box score page is not xhtml valid or even html valid for that matter, this was not a viable option.

My second attempt was to use an iframe whose src was the box score link. This seemed to work but then I didn't have permission to access the dom directly. I kept getting permission problems. I'm guessing that firefox disabled this feature to combat cross site scripting issues. If you really want to use an iframe, you'll have to use this solution from youngpup.

My solution was to go back to using GM_xmlhttpRequest to get the raw html of the box score, saving contents within the body tag into a string, and then creating a hidden div on the current page whose innerHTML was set to that string. The box score page was now part of the current page's dom and I was able to write xpath expressions.

after that problem was solved, everything else came together rather quickly. The script is definitely an EA, 0.1 version since it's tightly coupled to how yahoo publishes box scores and fantasy manager pages and HR and SB is not one of the available stats. Ultimately, I plan to resuse a lot of this code in other fantasy games and automatically determing the order of the stats on the management page and the box score page will be a common problem that will need to be solved.

I'm currently hosting this project using google code which has an issue tracker and uses subversion as its version control system. My javascript editor is intellij idea.