{"id":86,"date":"2017-09-22T01:00:21","date_gmt":"2017-09-22T08:00:21","guid":{"rendered":"http:\/\/www.ootp.cavebutter.net\/blog\/?p=86"},"modified":"2017-09-22T14:26:42","modified_gmt":"2017-09-22T21:26:42","slug":"run-environment-1-league-stats","status":"publish","type":"post","link":"http:\/\/www.ootp.cavebutter.net\/blog\/archives\/86","title":{"rendered":"<font color='#1e73be'>Run Environment 1: League Stats<\/font>"},"content":{"rendered":"<p>Here&#8217;s where things start to get fun. I&#8217;m going to be setting up a number of views that will allow me to calculate some of the more advanced statistics. The ones that I am most interested in are <a href=\"http:\/\/www.fangraphs.com\/library\/offense\/woba\/\">Weighted On-Base Average<\/a> (wOBA), <a href=\"http:\/\/www.fangraphs.com\/library\/offense\/wrc\/\">Weighted Runs Created<\/a> (wRC), <a href=\"http:\/\/www.fangraphs.com\/library\/offense\/wraa\/\">Weighted Runs Above Average<\/a> (wRAA), and Weighted Runs Created+ (wRC+). If this blog ever becomes a book or major motion picture, I will come back and fill in some detail about what these stats are and why they are meaningful. Until then, I will leave the links to do the explaining.<\/p>\n<p>I am basing all of this Run Environment work on a couple of <a href=\"http:\/\/www.insidethebook.com\/ee\/index.php\/site\/comments\/woba_year_by_year_calculations\/\">posts and formulas<\/a> posted by Tom Tango on his blog.<\/p>\n<p>wOBA is the gatekeeper to all of these other stats, and it can&#8217;t be derived from a player&#8217;s individual stats alone. \u00a0It requires some baseline statistics about the run environment in which a batter plays. \u00a0The first step is to determine, for each league year, the number of Runs, Outs, Plate Appearances, Runs per Out, and Runs per PA. \u00a0I don&#8217;t have a good way, yet, to separate out sub_leagues, and Tango doesn&#8217;t seem to care at this point, so I leave it alone.<\/p>\n<p>The other thing that Tango does and that I have decided to omit is limiting the summed pitching stats to those accumulated by players whose primary position is pitcher. \u00a0My experience is that non-pitchers pitch so rarely in OOTP that it is not worth creating a new view to determine primary position.<\/p>\n<p>I create a view, as such:<\/p>\n<pre class=\"line-numbers\"><code class=\"language-sql\">CREATE OR REPLACE VIEW vLeagueRunsPerOut AS\r\nSELECT p.year\r\n, p.league_id\r\n, SUM(p.r)\/sum(p.outs) AS \"RperOut\"\r\n, sum(p.r) AS \"totR\"\r\n, sum(p.outs) AS \"totOuts\"\r\n, sum(p.outs)+sum(p.ha)+sum(p.bb)+ sum(p.iw)+ sum(p.sh)\r\n   + sum(p.sf) AS \"totPA\"\r\n, round(sum(p.r)\/(sum(p.outs)+sum(p.ha)+sum(p.bb)+ sum(p.iw)+ sum(p.sh)\r\n   + sum(p.sf)),8) AS \"RperPA\"\r\nFROM players_career_pitching_stats AS p\r\nGROUP BY p.year, p.league_id;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Here&#8217;s where things start to get fun. I&#8217;m going to be setting up a number of views that will allow me to calculate some of the more advanced statistics. The ones that I am most interested in are Weighted On-Base Average (wOBA), Weighted Runs Created (wRC), Weighted Runs Above Average (wRAA), and Weighted Runs Created+&hellip; <a class=\"more-link\" href=\"http:\/\/www.ootp.cavebutter.net\/blog\/archives\/86\">Continue reading <span class=\"screen-reader-text\">Run Environment 1: League Stats<\/span> <span class=\"meta-nav\" aria-hidden=\"true\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[23],"tags":[14,17,15,24],"class_list":["post-86","post","type-post","status-publish","format-standard","hentry","category-run-environment","tag-batting","tag-leagues","tag-pitching","tag-view"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9cxb5-1o","jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"http:\/\/www.ootp.cavebutter.net\/blog\/wp-json\/wp\/v2\/posts\/86","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.ootp.cavebutter.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.ootp.cavebutter.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.ootp.cavebutter.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.ootp.cavebutter.net\/blog\/wp-json\/wp\/v2\/comments?post=86"}],"version-history":[{"count":6,"href":"http:\/\/www.ootp.cavebutter.net\/blog\/wp-json\/wp\/v2\/posts\/86\/revisions"}],"predecessor-version":[{"id":93,"href":"http:\/\/www.ootp.cavebutter.net\/blog\/wp-json\/wp\/v2\/posts\/86\/revisions\/93"}],"wp:attachment":[{"href":"http:\/\/www.ootp.cavebutter.net\/blog\/wp-json\/wp\/v2\/media?parent=86"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.ootp.cavebutter.net\/blog\/wp-json\/wp\/v2\/categories?post=86"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.ootp.cavebutter.net\/blog\/wp-json\/wp\/v2\/tags?post=86"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}