kruser / atbat-mongodb

A Perl project that pulls data from MLB's AtBat servers and shoves them into a local MongoDB
Other
33 stars 11 forks source link

How Is MongoDB Doing? #2

Closed rdetert closed 10 years ago

rdetert commented 10 years ago

I'm trying to model statistics for all sports right now and MongoDB seems like a painless way to rapidly prototype. Baseball is, of course, on my todo list.

I was wondering if you've stuck with mongodb?

kruser commented 10 years ago

Yes, it's been great. It definitely is beneficial during the prototype phase, especially when you are sourcing your data from documents like this project is doing.

I'm using the MongoDB database that this project can maintain as a base for a new web app too. I haven't published the app anywhere yet but the source is here https://github.com/kruser/pitchfx-site/

rdetert commented 10 years ago

Send me your email. I'll let you know what kind of schema I come up with. The thing I'm trying to wrap my head around is how to update stats, like Batting Averages atomically.

On Dec 12, 2013, at 6:14 AM, Ryan Kruse wrote:

Yes, it's been great. It definitely is beneficial during the prototype phase, especially when you are sourcing your data from documents like this project is doing.

I'm using the MongoDB database that this project can maintain as a base for a new web app too. I haven't published the app anywhere yet but the source is here https://github.com/kruser/pitchfx-site/

— Reply to this email directly or view it on GitHub.

kruser commented 10 years ago

email - ryan@kruseonline.net

Here are some examples of the documents I store.

In the atbats table...

{
    "_id" : ObjectId("522cf46e6b3dd66603000001"),
    "hip" : {
        "trajectory" : "grounder",
        "angle" : 77.96,
        "x" : 114.46,
        "y" : 154.62,
        "inning" : NumberLong(1),
        "batter" : NumberLong(116539),
        "type" : "O",
        "pitcher" : NumberLong(277417),
        "des" : "Groundout",
        "team" : "A"
    },
    "num" : NumberLong(1),
    "runnersPotentialBases" : NumberLong(0),
    "b_height" : "6-3",
    "inning" : {
        "number" : NumberLong(1),
        "type" : "top"
    },
    "batter_team" : "nya",
    "pitch" : [
        {
            "ax" : -14.894,
            "y0" : 50,
            "y" : 129.52,
            "cc" : "",
            "az" : -11.652,
            "id" : NumberLong(3),
            "vy0" : -137.019,
            "type_confidence" : 0.898,
            "pfx_x" : -7.82,
            "tfs_zulu" : "2010-04-05T00:10:13Z",
            "spin_dir" : 215.969,
            "tfs" : NumberLong(201013),
            "px" : -0.111,
            "type" : "X",
            "pfx_z" : 10.73,
            "des" : "In play, out(s)",
            "sz_top" : 3.61,
            "zone" : NumberLong(2),
            "z0" : 5.451,
            "x" : 104.72,
            "x0" : -2.008,
            "mt" : "",
            "break_y" : 23.8,
            "sz_bot" : 1.8199999999999998,
            "sv_id" : "100404_201019",
            "pz" : 3.206,
            "vz0" : -3.927,
            "break_length" : 3.9,
            "end_speed" : 86.2,
            "start_speed" : 93.6,
            "ay" : 29.614,
            "spin_rate" : 2684.859,
            "pitch_type" : "FT",
            "vx0" : 7.8870000000000005,
            "break_angle" : 46.6,
            "nasty" : NumberLong(41)
        }
    ],
    "pitcher" : NumberLong(277417),
    "runnersMovedBases" : NumberLong(0),
    "stand" : "R",
    "pitcher_team" : "bos",
    "p_throws" : "R",
    "s" : NumberLong(0),
    "event" : "Groundout",
    "batter" : NumberLong(116539),
    "start_tfs_zulu" : ISODate("2010-04-05T00:09:31Z"),
    "game" : {
        "home_team" : "bos",
        "away_team" : "nya",
        "venue_id" : NumberLong(3),
        "time" : "8:05",
        "id" : "2010_04_04_nyamlb_bosmlb_1"
    },
    "b" : NumberLong(0),
    "start_tfs" : NumberLong(200931),
    "des" : "Derek Jeter grounds out, shortstop Marco Scutaro to first baseman Kevin Youkilis.  ",
    "o" : NumberLong(1)
}

In the pitches collection....

{
    "_id" : ObjectId("522cf46f6b3dd66603000053"),
    "hip" : {
        "angle" : 77.96,
        "x" : 114.46,
        "y" : 154.62,
        "inning" : NumberLong(1),
        "batter" : NumberLong(116539),
        "type" : "O",
        "pitcher" : NumberLong(277417),
        "des" : "Groundout",
        "team" : "A"
    },
    "ax" : -14.894,
    "y0" : 50,
    "inning" : {
        "number" : NumberLong(1),
        "type" : "top"
    },
    "y" : 129.52,
    "cc" : "",
    "az" : -11.652,
    "id" : NumberLong(3),
    "vy0" : -137.019,
    "type_confidence" : 0.898,
    "atbat" : {
        "pitcher_team" : "bos",
        "stand" : "R",
        "num" : NumberLong(1),
        "p_throws" : "R",
        "event" : "Groundout",
        "s" : NumberLong(0),
        "b_height" : "6-3",
        "batter_team" : "nya",
        "start_tfs_zulu" : ISODate("2010-04-05T00:09:31Z"),
        "batter" : NumberLong(116539),
        "start_tfs" : NumberLong(200931),
        "b" : NumberLong(0),
        "pitch" : null,
        "pitcher" : NumberLong(277417),
        "des" : "Derek Jeter grounds out, shortstop Marco Scutaro to first baseman Kevin Youkilis.  ",
        "o" : NumberLong(1)
    },
    "pfx_x" : -7.82,
    "tfs_zulu" : ISODate("2010-04-05T00:10:13Z"),
    "spin_dir" : 215.969,
    "tfs" : NumberLong(201013),
    "px" : -0.111,
    "type" : "X",
    "pfx_z" : 10.73,
    "des" : "In play, out(s)",
    "sz_top" : 3.61,
    "zone" : NumberLong(2),
    "z0" : 5.451,
    "x" : 104.72,
    "x0" : -2.008,
    "mt" : "",
    "break_y" : 23.8,
    "sz_bot" : 1.8199999999999998,
    "sv_id" : "100404_201019",
    "pz" : 3.206,
    "vz0" : -3.927,
    "break_length" : 3.9,
    "end_speed" : 86.2,
    "start_speed" : 93.6,
    "ay" : 29.614,
    "spin_rate" : 2684.859,
    "game" : {
        "home_team" : "bos",
        "away_team" : "nya",
        "venue_id" : NumberLong(3),
        "time" : "8:05",
        "id" : "2010_04_04_nyamlb_bosmlb_1"
    },
    "pitch_type" : "FT",
    "vx0" : 7.8870000000000005,
    "break_angle" : 46.6,
    "nasty" : NumberLong(41)
}