<jupyter_start><jupyter_text>Position Player fWAR___           {    (Batting Runs + Base Running Runs + Fielding Runs +        }    fWAR = {  Positional Adjustment + League Adjustment +Replacement Runs) }           {                      / (Runs Per Win)                         }  Dynamic inputs<jupyter_code>import pandas as pd
import numpy as np
import sqlite3
import fantasy_machine

import matplotlib.pyplot as plt
%matplotlib inline
con = sqlite3.connect(fantasy_machine.config.mlb_db_path)

# df = pd.read_sql_query("""SELECT * 
#                        FROM {} 
#                        WHERE (gameid like '%OAK%' OR vteam='OAK')
#                        """.format('bevent'),
#                        con=con)
df = pd.read_sql_query("""SELECT * 
                       FROM {}
                       WHERE gameid like '%2018%'
                       """.format('bevent'),
                       con=con)

play_defs = {
     0:'Unknown event',
     1:'No event',
     2:'Generic out',
     3:'Strikeout',
     4:'Stolen base',
     5:'Defensive indifference',
     6:'Caught stealing',
     7:'Pickoff error',
     8:'Pickoff',
     9:'Wild pitch',
     10:'Passed ball',
     11:'Balk',
     12:'Other advance',
     13:'Foul error',
     14:'Walk',
     15:'Intentional walk',
     16:'Hit by pitch',
     17:'Interference',
     18:'Error',
     19:'Fielders choice',
     20:'Single',
     21:'Double',
     22:'Triple',
     23:'Home run',
     24:'Missing play'}<jupyter_output><empty_output><jupyter_text>Batting Runs___    player’s:        wOBA        PA        home park factor     League:         Average wOBA (lgwOBA)        the wOBA Scale        MLB R/PA (lgR/PA)        Specific league (AL or NL) wRC and PA for non-pitchers___    >> wRAA = ((wOBA – lgwOBA)/wOBA Scale) * PA    >>> Batting Runs = wRAA + (lgR/PA – (PF*lgR/PA))*PA + (lgR/PA – (AL or NL non-pitcher wRC/PA))*PA<jupyter_code>calc = fantasy_machine.model.metric_calculator(data=df)
df['year'] = df['gameid'].apply(lambda x: int(x[3:7]))<jupyter_output><empty_output><jupyter_text>BATTER<jupyter_code>team_id = 'ANA'

team = list(set(
    list(set(df[(df['year'] == 2018) & (df['gameid'].str.contains(team_id)) & (df['battingteam'] == 1)]['batter'])) + 
    list(set(df[(df['year'] == 2018) & (df['vteam']==team_id) & (df['battingteam'] == 0)]['batter']))
))
for player_id in team:
    print('{}:\t{}'.format(player_id, calc.calculate(player_ids=[player_id], metric='wOBA')))
player_ids = df['batter'].tolist()
p_stats = {}
# for player_id in team:
for player_id in player_ids:
    p_stats.update({player_id:[calc.calculate(player_ids=[player_id], metric='BA'),
                calc.calculate(player_ids=[player_id], metric='SLG'),
                calc.calculate(player_ids=[player_id], metric='wOBA'),
                calc.calculate(player_ids=[player_id], metric='wRAA')]})
pd.DataFrame.from_dict(p_stats,
                       orient='index',
                       columns=['BA','SLG','wOBA','wRAA']).plot(kind='scatter',
                                                         x='wOBA',
                                                         y='wRAA')<jupyter_output><empty_output><jupyter_text>PITCHER<jupyter_code>team_id = 'SFN'

team = list(set(
    list(set(df[(df['year'] == 2018) & (df['gameid'].str.contains(team_id)) & (df['battingteam'] == 0)]['pitcher'])) + 
    list(set(df[(df['year'] == 2018) & (df['vteam']==team_id) & (df['battingteam'] == 1)]['pitcher']))
))
for player_id in team:
    print('{}:\t{}'.format(player_id, calc.calculate(player_ids=[player_id], metric='FIP')))
p_stats = {}
for player_id in team:
    p_stats.update({player_id:[calc.calculate(player_ids=[player_id], metric='IP'),
                calc.calculate(player_ids=[player_id], metric='FIP'),
                calc.calculate(player_ids=[player_id], metric='WHIP')]})
pd.DataFrame.from_dict(p_stats,
                       orient='index',
                       columns=['IP','FIP','WHIP']).plot(kind='scatter',
                                                         x='WHIP',
                                                         y='FIP')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16494100650132434, 'fraction_numerical': 0.016373705754875994, 'mean_word_length': 2.347300564061241, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '633530', 'license': 'MIT', 'n_tokens_mistral': 1426, 'n_tokens_neox': 1343, 'n_words': 235, 'path': 'WAR.ipynb', 'repo_name': 'radspork/lou-machine', 'size': '4153'}