{"id":160,"date":"2017-10-02T12:31:09","date_gmt":"2017-10-02T19:31:09","guid":{"rendered":"http:\/\/www.ootp.cavebutter.net\/blog\/?p=160"},"modified":"2017-10-02T12:31:09","modified_gmt":"2017-10-02T19:31:09","slug":"batting-stats-3-slg-ops-and-iso","status":"publish","type":"post","link":"http:\/\/www.ootp.cavebutter.net\/blog\/archives\/160","title":{"rendered":"Batting Stats 3: SLG, OPS, and ISO"},"content":{"rendered":"<p>A short post for three pretty straightforward rate stats: Slugging Percentage, On Base Plus Slugging, and Isolated Power.<\/p>\n<p>All three are measures of a batter&#8217;s hitting for power. \u00a0Keeping with my tradition here of not explaining things that I understand, I will get straight to the point. \u00a0Seeking to keep things simple and readable, and wanting to show off my mad variable skills, I set them all as variables, including batting average. \u00a0The result is:<\/p>\n<pre class=\"line-numbers\"><code class=\"language-sql\">DROP TABLE IF EXISTS CalcBatting;\r\nCREATE TABLE IF NOT EXISTS CalcBatting AS\r\n\r\n   SELECT b.year\r\n    , b.league_id\r\n    , b.player_id\r\n    , b.stint #We can eventually move this down the list\r\n    , b.split_id #We can eventually remove\r\n    , b.team_id #We can eventually move this down the list\r\n    , l.abbr as Lg\r\n    , t.abbr as Team\r\n    , b.g\r\n    , b.ab\r\n    , @PA := b.ab+b.bb+b.sh+b.sf+b.hp AS PA\r\n    , @BA := round(b.h\/b.ab,3) AS ba\r\n    , round(b.k\/@PA,3) as krate\r\n    , round((b.bb)\/@PA,3) as bbrate\r\n    , @OBP := round((b.h + b.bb + b.hp)\/(@PA-b.sh-b.ci),3) AS obp\r\n    , round(100*(@OBP\/r.woba),0) as OBPplus\r\n    , @SLG := round((b.h+b.d+2*b.t+3*b.hr)\/b.ab,3) as slg\r\n    , round(@OBP+@SLG,3) as ops\r\n    , round(@SLG-@BA,3) as iso\r\nFROM \r\n      players_career_batting_stats b \r\n      INNER JOIN leagues l ON b.league_id=l.league_id \r\n      INNER JOIN teams t ON b.team_id=t.team_id\r\n      INNER JOIN tblRunValues2 r ON b.year=r.year AND b.league_id=r.league_id\r\n    WHERE b.ab&lt;&gt;0 AND b.split_id=1\r\n    ORDER BY b.player_id, b.year<\/code><\/pre>\n<p><!--more--><br \/>\nThe full script as it stands now:<\/p>\n<pre class=\"line-numbers\"><code class=\"language-sql\">#Calculated batting stats for OOTP\r\n    DROP TABLE IF EXISTS CalcBatting;\r\n    CREATE TABLE IF NOT EXISTS CalcBatting AS\r\n\r\n    SELECT b.year\r\n    , b.league_id\r\n    , b.player_id\r\n    , b.stint #We can eventually move this down the list\r\n    , b.split_id #We can eventually remove\r\n    , b.team_id #We can eventually move this down the list\r\n    , l.abbr as Lg\r\n    , t.abbr as Team\r\n    , b.g\r\n    , b.ab\r\n    , @PA := b.ab+b.bb+b.sh+b.sf+b.hp AS PA\r\n    , b.r \r\n    , b.h\r\n    , b.d\r\n    , b.t\r\n    , b.hr\r\n    , b.rbi\r\n    , b.sb\r\n    , b.cs\r\n    , b.bb\r\n    , b.k\r\n    , b.ibb\r\n    , b.hp\r\n    , b.sh\r\n    , b.sf\r\n    , b.gdp\r\n    , b.ci\r\n    , @BA := round(b.h\/b.ab,3) AS ba\r\n    , round(b.k\/@PA,3) as krate\r\n    , round((b.bb)\/@PA,3) as bbrate\r\n    , @OBP := round((b.h + b.bb + b.hp)\/(@PA-b.sh-b.ci),3) AS obp\r\n    , round(100*(@OBP\/r.woba),0) as OBPplus\r\n    , @SLG := round((b.h+b.d+2*b.t+3*b.hr)\/b.ab,3) as slg\r\n    , round(@OBP+@SLG,3) as ops\r\n    , round(@SLG-@BA,3) as iso\r\n    \/* NOT yet modified for OOTP and MySQL\r\n    , round((r.wobaBB*nz(b.bb,0) + r.wobahb*nz(b.hbp,0) + r.woba1b*(b.h-b.[2b]-b.[3b]-b.hr) + r.woba2b*b.[2b] + r.woba3b*b.[3b] + r.wobahr*b.hr)\/(b.ab+nz(b.bb,0)-nz(b.ibb,0)+nz(b.sf,0)+nz(b.hbp,0)),3) as woba\r\n    , round((([woba]-r.lgwoba)\/r.wobascale)*[PA],1) as wRAA\r\n    , round(((([woba]-r.lgwoba)\/r.wobascale)+(l.totr\/l.totpa))*[PA],0) as wRC\r\n    , ((([wRAA]\/[PA] + l.RperPA) + (l.RperPA - t.bpf*l.RperPA))\/(lb.wRC\/lb.PA))*100 AS [wRC+]\r\n    *\/\r\n    FROM \r\n      players_career_batting_stats b \r\n      INNER JOIN leagues l ON b.league_id=l.league_id \r\n      INNER JOIN teams t ON b.team_id=t.team_id\r\n      INNER JOIN tblRunValues2 r ON b.year=r.year AND b.league_id=r.league_id\r\n    WHERE b.ab&lt;&gt;0 AND b.split_id=1\r\n    ORDER BY b.player_id, b.year<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>A short post for three pretty straightforward rate stats: Slugging Percentage, On Base Plus Slugging, and Isolated Power. All three are measures of a batter&#8217;s hitting for power. \u00a0Keeping with my tradition here of not explaining things that I understand, I will get straight to the point. \u00a0Seeking to keep things simple and readable, and&hellip; <a class=\"more-link\" href=\"http:\/\/www.ootp.cavebutter.net\/blog\/archives\/160\">Continue reading <span class=\"screen-reader-text\">Batting Stats 3: SLG, OPS, and ISO<\/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_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},"jetpack_post_was_ever_published":false},"categories":[25],"tags":[],"class_list":["post-160","post","type-post","status-publish","format-standard","hentry","category-batting"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9cxb5-2A","jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"http:\/\/www.ootp.cavebutter.net\/blog\/wp-json\/wp\/v2\/posts\/160","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=160"}],"version-history":[{"count":1,"href":"http:\/\/www.ootp.cavebutter.net\/blog\/wp-json\/wp\/v2\/posts\/160\/revisions"}],"predecessor-version":[{"id":164,"href":"http:\/\/www.ootp.cavebutter.net\/blog\/wp-json\/wp\/v2\/posts\/160\/revisions\/164"}],"wp:attachment":[{"href":"http:\/\/www.ootp.cavebutter.net\/blog\/wp-json\/wp\/v2\/media?parent=160"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.ootp.cavebutter.net\/blog\/wp-json\/wp\/v2\/categories?post=160"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.ootp.cavebutter.net\/blog\/wp-json\/wp\/v2\/tags?post=160"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}