{"id":122,"date":"2017-09-27T14:45:34","date_gmt":"2017-09-27T21:45:34","guid":{"rendered":"http:\/\/www.ootp.cavebutter.net\/blog\/?p=122"},"modified":"2017-09-27T14:45:34","modified_gmt":"2017-09-27T21:45:34","slug":"run-environment-5-an-intermediate-table","status":"publish","type":"post","link":"http:\/\/www.ootp.cavebutter.net\/blog\/archives\/122","title":{"rendered":"Run Environment 5: An Intermediate Table"},"content":{"rendered":"<p>In addition to using variables, Wyers also does the other thing I had thought about using: an intermediate table to store the runMinus, runPlus, and wOBAScale values. \u00a0On the one hand, this makes sense as we will only have to write out the calculations once and then refer to them in this table when we need them. \u00a0On the other hand, if we managed to use variables for defining the run values in the previous table, we should be able to do so with these values as well.<\/p>\n<p>Also, in this table, we define league wOBA. \u00a0It makes sense that the weighted On Base Average for the entire league is just the entire league&#8217;s On Base Percentage. \u00a0If we&#8217;re looking at an average for the entire league, there is nothing to weigh it against. \u00a0We&#8217;ll see this idea again when we look at wRC+.<\/p>\n<p>A few minor adjustments to the code to allow for OOTP&#8217;s naming conventions and one final difference: \u00a0I&#8217;m taking the batting stats from the league_history_batting table rather than the players_ file. \u00a0It&#8217;s already there and there are far fewer rows to sort through. \u00a0And given that we&#8217;re not filtering out any stats, it&#8217;s silly not to use it. \u00a0And, because we&#8217;re using it, we can use the column for singles (s) rather than deriving singles from H-2b-3b-HR.<\/p>\n<pre class=\"line-numbers\"><code class=\"language-sql\">#Creating an intermediate table so as not to have to write out formulae for rumMinus etc.\r\nDROP TABLE IF EXISTS tblRunValues1A;\r\nCREATE TABLE IF NOT EXISTS tblRunValues1A AS\r\nSELECT r.year\r\n, r.league_id\r\n, r.RperOut \r\n, r.runBB \r\n, r.runHB \r\n, r.run1B \r\n, r.run2B \r\n, r.run3B \r\n, r.runHR \r\n, r.runSB \r\n, r.runCS \r\n, SUM(runBB*(BB-IBB) + runHB * HP + run1B * s + run2B * d \r\n   + run3B * t + 1.4 * HR + runSB * SB - runCS * CS) \r\n   \/ SUM(AB - H + SF) AS runMinus \r\n\r\n, SUM(runBB * (BB-IBB) + runHB * HP + run1B * s + run2B * d \r\n   + run3B * t + 1.4 * HR + runSB * SB - runCS * CS) \r\n   \/ SUM(BB-IBB + HP + H) AS runPlus\r\n\r\n, SUM(H+BB-IBB+HP) \/ SUM(AB+BB-IBB+HP+SF) AS wOBA \r\n \r\nFROM tblRunValues r\r\nINNER JOIN league_history_batting_stats \r\n   ON r.year=league_history_batting_stats.year \r\n   AND r.league_id=league_history_batting_stats.league_id\r\n\r\n \r\nGROUP BY \r\nr.year\r\n, r.league_id\r\n, r.RperOut \r\n, r.runBB \r\n, r.runHB \r\n, r.run1B \r\n, r.run2B \r\n, r.run3B \r\n, r.runHR \r\n, r.runSB \r\n, r.runCS \r\n \r\nORDER BY \r\nr.year DESC;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In addition to using variables, Wyers also does the other thing I had thought about using: an intermediate table to store the runMinus, runPlus, and wOBAScale values. \u00a0On the one hand, this makes sense as we will only have to write out the calculations once and then refer to them in this table when we&hellip; <a class=\"more-link\" href=\"http:\/\/www.ootp.cavebutter.net\/blog\/archives\/122\">Continue reading <span class=\"screen-reader-text\">Run Environment 5: An Intermediate Table<\/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,7,4,6],"class_list":["post-122","post","type-post","status-publish","format-standard","hentry","category-run-environment","tag-batting","tag-leagues","tag-mysql","tag-ootp","tag-tables"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9cxb5-1Y","jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"http:\/\/www.ootp.cavebutter.net\/blog\/wp-json\/wp\/v2\/posts\/122","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=122"}],"version-history":[{"count":2,"href":"http:\/\/www.ootp.cavebutter.net\/blog\/wp-json\/wp\/v2\/posts\/122\/revisions"}],"predecessor-version":[{"id":124,"href":"http:\/\/www.ootp.cavebutter.net\/blog\/wp-json\/wp\/v2\/posts\/122\/revisions\/124"}],"wp:attachment":[{"href":"http:\/\/www.ootp.cavebutter.net\/blog\/wp-json\/wp\/v2\/media?parent=122"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.ootp.cavebutter.net\/blog\/wp-json\/wp\/v2\/categories?post=122"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.ootp.cavebutter.net\/blog\/wp-json\/wp\/v2\/tags?post=122"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}