Prototypes

Workin on some Vis!

‘ve been working all weekend on putting down a solid visualization of baseball games that gives an informative overview of exactly what happened in a game in the least amount of space available. I want to give a variety of ways to view a game in order to get the most out of it, but first and foremost I want to provide a simplified overview of all game events that shows the flow of the game and allows people to see exactly what happened.

I started by trying to classify events and think of how that I can rank them each in a way that will allow me to show them in a linear way that both unifies them per team as well as shows the magnitude of each event. In this idea I thought about the major possible events and ranked them according to the impact they have on the game, form the perspective of the batting team.

Tier 5: Homeruns,
Tier 4: Triples
Tier 3: Doubles
Tier 2: Singles
Tier 1: Walks/Stolen Bases
Tier 0: Outs

I had to revise this several times after experimenting with it, mostly due to issues wtih classifying walks/stolen bases and singles. At first I thought that I could get away with putting them in the same tier, since they all result in the player moving up one base. I then realized that there is a clear difference between the two. While walks and stolen bases both advance the runner towards scoring position on the diamond, singles put the ball in play, which can result in RBIs. Walks can sometimes result in an RBI if the bases are loaded but even this is restricted to one run, while a single can drive in up to three runs.

After coming up with this classification, I began to work on a circular visualization of events that classified them according to a number of criteria. While in concept this made sense to me, in reality it turned out to look somewhat interesting but really show a lot of nothing with a simple look. I also attempted to create an organic shape from this visualization just to see what it looked like, and while this too proved interesting I dont’ think it was very successful in showing anything.

PastedGraphic-1

PastedGraphic-2

I then moved on to the next logical step, visualizing things linearly. I continued with my key of dashes and colors, and while linearly things made a bit more sense it was still not working very well IMO. I experimented with representing outs as negative events at this point as well but I don’t think it read the way I intened.

PastedGraphic-3

PastedGraphic-4

At this point I also created a more organic flow diagram from these charts. I think this actually worked out really well and is a great overall representation of the flow of the game. While it doesn’t really show exactly what I wanted from the first overall view of the game a user is presented with, I think it is a great sub-view and something that I’m going to continue to investigate

PastedGraphic-6

This is where I realized I was sorta getting caught up in doing the same thing over and over, so I decided to give it a rest and move on the next day.

Today I started working again and had some major breakthroughs. I spent a lot of time working on various visualizations, trying to bring down the amount of data ink used (as per reading Edward Tufte) and began to really simplify everything. I did a lot of different experimenting, and came up with a visualization I think finally works pretty well. I did some quick testing with a few casual baseball fans I know (obviously need to do more user testing but something is better than nothing and I just finished it!) and I was pleased that they could easily recreate the narrative of a game themselves after a very brief explanation which wasn’t repeated.

PastedGraphic-8

PastedGraphic-9

PastedGraphic-10

PastedGraphic-11

All of this needs more work I know, but I put in a crapload of time this weekend and I think that I am definitely making progress. I also worked with a real data set vs just making things up, which was a bit of a pain in the ass at first but really helped me a lot in the long run. I hsould have been working like this before and I’m glad I am doing it now.

Thats it for now, I also did a good amount of work on the otehr sections of the application but I don’t feel like they are ready to show yet so that will be another post.

If you read this please check everything out and give me some feedback!

Thanks,

-Steve

Continue reading » No comments

Getting MySQLdb up and running on Snow Leopard with MAMP

OK this is another post that is more for my own future sanity than anything else. This has been a huge pain in the ass for me many times and I want to document the steps I took to get this working.

First, this is a good general overview

http://cd34.com/blog/programming/python/mysql-python-and-snow-leopard/

So I downloaded/installed MySQL, then I had to add it to my PATH var to get the MySQLdb install to work.

//Open With textmate
mate ~/.profile

export PATH=”/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH”

then make sure you update your profile or close and open a new terminal window
source ~/.profile

that will let the MySQLdb install work. Then when you run Python and try to use MySQL db you’ll get errors. What you need to do is the following:

change your PATH to export PATH=/Applications/MAMP/Library/bin:$PATH

which links to MAMP mysql, then run this command

sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock

Then you should be good to go. Might be able to skip the first step but I don’t know if the MySQL that comes with mamp is 64bit and you need 64 bit for snow leopards install of Python..

Why is python such a pain in the ass?

Continue reading » 4 Comments

Some recent work

Here are a couple of CV Prototypes I’ve done in school. This semester has been a really big challenge for me. I feel like I learned a lot but at the same time wasn’t able to put the time and effort I wanted into any of my projects, so most of them exist in prototype form only. Hoping that one day I can expand upon these and create something great if I ever have time…

Beehive
Working with Lee Meredith and Justin Blinder we created this experiment that allows users to interact with virtual beehives. When a user knocks into the beehive they are swarmed by bees which continue to attack until they leave the video frame. The bees then return to their hives. Created using CV tracking and particle forces.

Puking
We also created this simple app that is a lot of fun. Basically bend over and you puke. Using CV Tracking and detecting which direction the person is bending in using countNonZeroInRegion() function in ofxCvImage.

Continue reading » No comments

Prototype/User Test for Thesis

After a LOT of work/heavy lifting with C++, audio timing and beat spacing, I finally am relieved to have a sizeable prototype for thesis that is a big step towards my intended project. It may not seem like a lot in the form I’m presenting it, but it involved a lot of planning, coding, and adjustments to my XML in order to create something that I can test.

This test consists of two audio files, both generated live from baseball game information read from a database, parsed to XML, imported into openFrameworks, then associated with certain beats in two different patterns. I associated the same beats with events in each pattern so that they can hopefully be compared in a similar fashion. The beats are as follows:

  • Inning Change: Snare Drum
  • Top/Bottom of inning: Bass Drum
  • Out: Kick Drum
  • Hit: Clapping

The first pattern is linear, which means that every plate appearance by a player is mapped to an equally timed beat. This diagram attempts to illustrate what I mean…

linearBeats

This approach is true to the actual rhythm of the game, and spaces the beats as they would occur in actual time. The audio effect that this gives can be quite random at time, and while it represents the game very well

Here is what this sounds like:
[audio:linearSound.mp3]
The second approach I took was to use the constants in the game (9 innings/Top and Bottom to each inning) as steady beats, and then use the variable events within these constants (hits, runs, outs, etc) as sections of variable timing within the the constants. The diagram below attempts to illustrate this:

timedSpacing

This approach doesn’t hold as true to the actual rhythm of the game, however I think that the contrast between constant, steady beat patterns and variable events gives both a feeling of the game as well as a better sounding, more rhythmic sound.

Here is what this sounds like:

[audio:spacedTiming.mp3]

I’d appreciate any feedback you have as well as suggestions, so please review these two tracks and let me know what you think in the comments!

Continue reading » 11 Comments

Digging into the Data

I’ve begun to dig into the Retrosheet database that I recently acquired (see previous post) and have started to plan out a basic format for parsing the immense amount of data into a readable, usable XML format that will let me retrieve game data in a simple, direct way.

In order to do this, I had to first think about how a baseball game is structured. What are the constants and what are the variables? How can I structure my XML around this?

Speaking in terms of a baseball game and not the way that Retrosheet is formatted, the constants in a game are as follows:

  • 9 Innings
  • 2 halves of an inning
  • 1 set of at bats and 1 set of fielding (defense) for each team
  • Away team always bats first in an inning
  • Each half of an inning consists of 3 outs
  • An out always ends an inning

After writing this down, I was starting to see a structure.

I then started to investigate how the game data was stored in the retrosheet database. The database is structured in a somwhat simplistic way, with only two levels of heirarchy: Games and at bats. Within the at bats lies all the other information about where the at bat took place in the game…which inning, which team, how many outs, etc.

This format didn’t quite mix with the way that I was thinking a game should be represented, but for a database structure it made perfect sense. I then began to think how I could merge these two formats, and what information I could gain from a game.

After several attempts, this is the XML format that I have come up with which I think will work quite well in organizing the information that I need.


This format organizes the game around the structure I mentioned previously, then adds in the game events from retrosheet as Plate Appearances within outs. This approach creates an XML document that is very easy to read, which I can use to reconstruct a game very quickly and pull connected data out based on related fields. At this point I am not pulling all the data but a smaller set that will be easy for me to get started with.

Here is a diagram of the overall structure.
gameDiagram

Continue reading » No comments

Getting the baseball data.

The first major challenge of my thesis project has been acquiring historical data, parsing it into a usable format (database), and then going through it and trying to make some sense of it. I’ll try to go over some of the steps I took to get where I’m at (as usual both for anyone trying to do the same thing and for my own sanity the next time I need to do this).

First of all, thanks to the extremely hard work of a few super dedicated individuals, historical data for every baseball game  is available online at the site http://www.retrosheet.com

These files have an insane amount of data for almost every game played for at least the last 50 years (there is more but before then the complete info is a bit hit or miss). Unfortunately, due to the way that they are recording the data (I’m not really sure how, but I assume it involves some sort of spreadsheet), the files are not really in an easily interpreted format. Luckily, again due to the work of a few dedicated individuals, the open source community has a solution for this as well. The tool “Chadwick” (named after the man who is historically credited with inventing the first widely accepted form of baseball scorekeeping) is a command-line unix tool which can take these files and parse them to Comma Separated Value (CSV) files. This does entail learning a proprietary command language for the compiling (it looks sorta like regular expressions but I don’t think its related), but the end result is worth it.

From this point (once you have your CSV files) you can create a database in the SQL of your choice (MySQL, sqLite, etc) and import the database.

Fortunately there are a few people out there who have already done a great bulk of this work, and have written some scripts to take care of a lot of this process for you. Unfortunately, they are using Python with the MySQLDB extension, which under snow leopard is near impossible to compile at this time.

The main site I have been working from to get this data to work can be found here:

http://blog.wellsoliver.com/2009/06/retrosheet/

This guy is the perfect combination for my thesis: a data geek and a huge baseball fan. He has made several amazing tools (a few of which I look forward to getting into in the future) that allow people to get baseball data in a bit more friendly manner, and shares his experiences obtaining the data.

I spent the better half of a weekend attempting to get his code to work on my computer, due in no way to any error on his fault but solely based on the fact that snow leopard refuses to compile and install a workable version of MySQLDB to python.

I finally gave up, and decided that I would go to plan B and run the script on my server (Dreamhost). This too proved to hit a few roadblocks (the version of Python installed on my server wasn’t new enough, had to install new Python then compile and install new MySQLDB a couple times :( )

Then I had to figure out how to compile the Chadwick source code under Unix, which seemed very unclear until I actually opened the readme file and realized all I had to do was type ./configure in the Chadwick directory and it would compile no sweat.

I finally got the code to run and (seemingly) work! Then I realized I had another error…my server was killing my requests and I was only getting part of the data. After emailing back and forth with Dreamhost for an hour or two, I finally realized what the issue was. The python code that I was working with ran in 20 seperate threads (which would have been fine had I been able to run it on my own computer) however my Dreamhost account had a limit on concurrent threads that were allowed to run and i was greatly exceeding this. After changing the amount to 5, I finally was able to execute the script and build my database. It took about 15 minutes (!) to run the script through, and I was left with a complete, 4+GB database of baseball information.

This has been a huge headache (to say the damn least!) but now that I have gone through this process once it should be a lot easier from her on out if I need to grab new data (hopefully…).

I’m now working on understanding and parsing this enormous amount of data (the one table of events alone has over 8 million rows…) and make some sense of it. I’m close to having a workable XML format and I’ll post more about this in the future.

One more thing….

I found this link: http://www.wantlinux.net/2009/04/retrosheet-baseball-mysql-database-download/

which is basically the entire code already compiled into a database and downloadable :( On one hand this totally bums me out, but on the other hand it was a great experience having terminal/unix try to beat me down and coming out victorious! I am considering doing what this person has done and hosting the 2009 database on my site once it has become available, I’ll make a post if I decide to do so.

Continue reading » No comments

And the spending begins…..

So I started buying the things I’m gonna need for my multitouch table after doing a shitload of research…

I have decided upon a Diffused Illumination setup vs a FTIR setup so that I have the option of doing fiducial tracking, which I really want to do. Its also a lot less work as far as soldering/powering/etc although I think its tough to get real good/even lighting.

Its actually pretty cheap to build a table, with the exception of the projector, which even at a heavy discount through an ebay purchase is still a pretty swift kick to my financial groin….

I settled on a BenQ MP522 Short Throw projector for both the ridiculously short throw distance (1.2 feet?!?!?) as well as the 1024×768 native resolution so I don’t get a super pixellated image. Its capable of 1280×1024 but I don’t know how that will looks since its not native. It also has 2500 lumen brightness, so it should be plenty bright for most indoor lighting. The projector goes for $870.00 new on Ebay but I got a unopened refurbished version with 0 hours on the bulb from ebay for $650.00 (plus shipping). Hopefully this will be by far the most expensive thing I purchase for thesis and I can build this table and concentrate on making software!

24-014-192-02

Here’s the projector’s New Egg page

I also ordered some IR flood lights for the table here. $18 a piece for arrays of 30 powered infrared super brights, not a terrible deal. I found another site with $16 arrays of 48 but the site has bad reviews and the lights didn’t look as nice.

ir30

I bought these here

Next things to do/buy:

  • I need to get wood and plexi once I decide on dimensions and screen size. I’m thinking something around 50 inches diagonal would be pretty nice, not too big but not too small either.
  • Take apart a PS3 eye and install an infrared filter on it. Also probably should get a wide angle lens for it
  • Lee 225 lighting film for the projection surface and also diffusing film for the box
  • power strips

I think thats it, getting there slowly but surely!

Continue reading » 2 Comments