Added Devil Rays to club and franchise lists
Fixed bphr fraction bug Removed player post limit
This commit is contained in:
parent
b3cce68576
commit
b3102201c8
@ -266,9 +266,9 @@ def bp_homeruns(all_hr, hr_rate):
|
||||
if all_hr == 0 or hr_rate == 0:
|
||||
return mround(0)
|
||||
elif hr_rate > .2:
|
||||
return sanitize_chance_output(all_hr * mround(.4), rounding=1.0)
|
||||
return mround(all_hr * 0.4, base=1.0)
|
||||
else:
|
||||
return sanitize_chance_output(all_hr * mround(.8), rounding=1.0)
|
||||
return mround(all_hr * 0.8, base=1.0)
|
||||
|
||||
|
||||
def triples(all_xbh, tr_count, do_count):
|
||||
|
||||
@ -446,6 +446,7 @@ CLUB_LIST = {
|
||||
'SEA': 'Seattle Mariners',
|
||||
'SFG': 'San Francisco Giants',
|
||||
'STL': 'St Louis Cardinals',
|
||||
'TBD': 'Tampa Bay Devil Rays',
|
||||
'TBR': 'Tampa Bay Rays',
|
||||
'TEX': 'Texas Rangers',
|
||||
'TOR': 'Toronto Blue Jays',
|
||||
@ -485,6 +486,7 @@ FRANCHISE_LIST = {
|
||||
'SEA': 'Seattle Mariners',
|
||||
'SFG': 'San Francisco Giants',
|
||||
'STL': 'St Louis Cardinals',
|
||||
'TBD': 'Tampa Bay Rays',
|
||||
'TBR': 'Tampa Bay Rays',
|
||||
'TEX': 'Texas Rangers',
|
||||
'TOR': 'Toronto Blue Jays',
|
||||
@ -574,7 +576,9 @@ def get_pitching_peripherals(season: int):
|
||||
|
||||
|
||||
def mround(x, prec=2, base=.05):
|
||||
return float(round(Decimal(str(x)) / Decimal(str(base)) * Decimal(str(base)), prec))
|
||||
num, to = Decimal(str(x)), Decimal(str(base))
|
||||
return float(round(num / to) * to)
|
||||
# return float(round(Decimal(str(x)) / Decimal(str(base)) * Decimal(str(base)), prec))
|
||||
# return round(base * round(float(x) / base), prec)
|
||||
|
||||
|
||||
|
||||
@ -586,7 +586,7 @@ async def get_or_post_players(stat_df: pd.DataFrame, bat_card_df: pd.DataFrame,
|
||||
|
||||
dev_count = 0
|
||||
for index, row in stat_df.iterrows():
|
||||
if dev_count > 5:
|
||||
if dev_count < 0:
|
||||
break
|
||||
|
||||
p_query = await db_get('players', params=[('bbref_id', row["key_bbref"]), ('cardset_id', CARDSET_ID)])
|
||||
@ -680,11 +680,22 @@ async def post_batting_cards(cards_df: pd.DataFrame):
|
||||
}), axis=1)
|
||||
resp = await db_put('battingcards', payload={'cards': all_cards}, timeout=6)
|
||||
if resp is not None:
|
||||
return True
|
||||
pass
|
||||
else:
|
||||
e_msg = 'Unable to post batting cards'
|
||||
logging.debug(e_msg, stack_info=True)
|
||||
raise ValueError(e_msg)
|
||||
|
||||
bc_query = await db_get('battingcards', params=[('cardset_id', CARDSET_ID)])
|
||||
if bc_query['count'] > 0:
|
||||
bc_data = bc_query['cards']
|
||||
|
||||
for line in bc_data:
|
||||
line['player_id'] = line['player']['player_id']
|
||||
line['key_bbref'] = line['player']['bbref_id']
|
||||
line['battingcard_id'] = line['id']
|
||||
|
||||
return pd.DataFrame(bc_data).set_index('key_bbref')
|
||||
|
||||
|
||||
async def post_batting_ratings(ratings_df: pd.DataFrame):
|
||||
@ -693,9 +704,11 @@ async def post_batting_ratings(ratings_df: pd.DataFrame):
|
||||
def append_ratings(row):
|
||||
vl = row['ratings_vL']
|
||||
vl['player_id'] = row['player_id']
|
||||
vl['battingcard_id'] = row['battingcard_id']
|
||||
|
||||
vr = row['ratings_vR']
|
||||
vr['player_id'] = row['player_id']
|
||||
vr['battingcard_id'] = row['battingcard_id']
|
||||
|
||||
all_ratings.append(vl)
|
||||
all_ratings.append(vr)
|
||||
@ -714,7 +727,8 @@ async def post_positions(pos_df: pd.DataFrame):
|
||||
all_pos = []
|
||||
|
||||
def append_positions(row):
|
||||
new_val = row.to_dict()
|
||||
clean_row = row.dropna()
|
||||
new_val = clean_row.to_dict()
|
||||
new_val['player_id'] = int(row['player_id'])
|
||||
all_pos.append(new_val)
|
||||
pos_df.apply(append_positions, axis=1)
|
||||
@ -739,17 +753,17 @@ async def post_batter_data(bs: pd.DataFrame, bc: pd.DataFrame, br: pd.DataFrame,
|
||||
left_on='key_bbref',
|
||||
right_on='bbref_id'
|
||||
)
|
||||
await post_batting_cards(bc)
|
||||
bc = await post_batting_cards(bc)
|
||||
|
||||
# Post Batting Ratings
|
||||
br = pd.merge(
|
||||
left=br,
|
||||
right=all_players,
|
||||
how='right', #'left',
|
||||
right=bc,
|
||||
how='right', #'left', TODO: switch back to left when all players are pulled
|
||||
left_on='key_bbref',
|
||||
right_on='bbref_id'
|
||||
right_on='key_bbref'
|
||||
)
|
||||
await post_batting_ratings(br)
|
||||
br = await post_batting_ratings(br)
|
||||
|
||||
# Post Positions
|
||||
dr = pd.merge(
|
||||
|
||||
@ -10,6 +10,8 @@ def test_positions_df():
|
||||
def test_mround():
|
||||
assert mround(6.4) == 6.4
|
||||
assert mround(6.66) == 6.65
|
||||
assert mround(2.14, base=1.0) == 2.0
|
||||
assert mround(6.69, base=0.25) == 6.75
|
||||
|
||||
|
||||
def test_sanitize():
|
||||
|
||||
Loading…
Reference in New Issue
Block a user