Bug fix & stats added
add error checks for scorecard submission & add stats to !player command
This commit is contained in:
parent
bb6cc8ee84
commit
f1e0fc18f6
@ -249,10 +249,10 @@ class Players(commands.Cog):
|
||||
# ('season', current['season']), ('week_start', current['week']), ('week_end', current['week'])
|
||||
# ])
|
||||
gp_query = await db_get('games', params=[
|
||||
('season', current['season']), ('week', current['week']), ('played', True)
|
||||
('season', current['season']), ('week', current['week']), ('played', True), ('short_output', True)
|
||||
])
|
||||
all_query = await db_get('games', params=[
|
||||
('season', current['season']), ('week', current['week'])
|
||||
('season', current['season']), ('week', current['week']), ('short_output', True)
|
||||
])
|
||||
|
||||
return {'games_played': gp_query['count'], 'game_count': all_query['count']}
|
||||
@ -1123,8 +1123,14 @@ class Players(commands.Cog):
|
||||
content='Okay, let me wipe the old shit...',
|
||||
view=None
|
||||
)
|
||||
await db_delete('plays/game', object_id=dupe_game['id'])
|
||||
await db_delete('decisions/game', object_id=dupe_game['id'])
|
||||
try:
|
||||
await db_delete('plays/game', object_id=dupe_game['id'])
|
||||
except ValueError as e:
|
||||
logging.error(f'No plays for game {dupe_game["id"]}')
|
||||
try:
|
||||
await db_delete('decisions/game', object_id=dupe_game['id'])
|
||||
except ValueError as e:
|
||||
logging.error(f'No decisions for game {dupe_game["id"]}')
|
||||
await db_post(f'games/wipe/{dupe_game["id"]}')
|
||||
else:
|
||||
await interaction.edit_original_response(
|
||||
|
||||
166
helpers.py
166
helpers.py
@ -1,4 +1,5 @@
|
||||
import datetime
|
||||
import math
|
||||
|
||||
import pygsheets
|
||||
|
||||
@ -871,74 +872,115 @@ async def get_player_embed(player, current, ctx=None, season=None):
|
||||
num = 16
|
||||
embed.add_field(name='Draft Pick', value=f'{pick["round"]}.{num} ({pick["owner"]["abbrev"]})')
|
||||
|
||||
b, p = None, None
|
||||
batting_string = None
|
||||
pitching_string = None
|
||||
batter_priority = True
|
||||
if player['season'] < 8:
|
||||
b, p = None, None
|
||||
batting_string = None
|
||||
pitching_string = None
|
||||
batter_priority = True
|
||||
|
||||
b_query = await db_get('battingstats/totals', params=[('season', season), ('player_id', player['id'])])
|
||||
if b_query['count'] > 0:
|
||||
b = b_query['stats'][0]
|
||||
b_query = await db_get('battingstats/totals', params=[('season', season), ('player_id', player['id'])])
|
||||
if b_query['count'] > 0:
|
||||
b = b_query['stats'][0]
|
||||
|
||||
if b['ab'] > 0:
|
||||
singles = b['hit'] - b['hr'] - b['triple'] - b['double']
|
||||
avg = b['hit'] / b['ab']
|
||||
obp = (b['hit'] + b['bb'] + b['ibb'] + b['hbp']) / b['pa']
|
||||
slg = ((b['hr'] * 4) + (b['triple'] * 3) + (b['double'] * 2) + singles) / b['ab']
|
||||
ops = obp + slg
|
||||
woba = ((b['bb'] * .69) + (b['hbp'] * .72) + (singles * .89) + (b['double'] * 1.27) +
|
||||
(b['triple'] * 1.62) + (b['hr'] * 2.1)) / (b['pa'] - b['hbp'] - b['sac'])
|
||||
ab = f'{b["ab"]:.0f}'
|
||||
run = f'{b["run"]:.0f}'
|
||||
hit = f'{b["hit"]:.0f}'
|
||||
double = f'{b["double"]:.0f}'
|
||||
triple = f'{b["triple"]:.0f}'
|
||||
hr = f'{b["hr"]:.0f}'
|
||||
rbi = f'{b["rbi"]:.0f}'
|
||||
sb = f'{b["sb"]:.0f}'
|
||||
cs = f'{b["cs"]:.0f}'
|
||||
so = f'{b["so"]:.0f}'
|
||||
if b['ab'] > 0:
|
||||
singles = b['hit'] - b['hr'] - b['triple'] - b['double']
|
||||
avg = b['hit'] / b['ab']
|
||||
obp = (b['hit'] + b['bb'] + b['ibb'] + b['hbp']) / b['pa']
|
||||
slg = ((b['hr'] * 4) + (b['triple'] * 3) + (b['double'] * 2) + singles) / b['ab']
|
||||
ops = obp + slg
|
||||
woba = ((b['bb'] * .69) + (b['hbp'] * .72) + (singles * .89) + (b['double'] * 1.27) +
|
||||
(b['triple'] * 1.62) + (b['hr'] * 2.1)) / (b['pa'] - b['hbp'] - b['sac'])
|
||||
ab = f'{b["ab"]:.0f}'
|
||||
run = f'{b["run"]:.0f}'
|
||||
hit = f'{b["hit"]:.0f}'
|
||||
double = f'{b["double"]:.0f}'
|
||||
triple = f'{b["triple"]:.0f}'
|
||||
hr = f'{b["hr"]:.0f}'
|
||||
rbi = f'{b["rbi"]:.0f}'
|
||||
sb = f'{b["sb"]:.0f}'
|
||||
cs = f'{b["cs"]:.0f}'
|
||||
so = f'{b["so"]:.0f}'
|
||||
|
||||
batting_string = f'```\n' \
|
||||
f' AVG OBP SLG OPS\n' \
|
||||
f' {avg:.3f} {obp:.3f} {slg:.3f} {ops:.3f}\n``````\n' \
|
||||
f' AB R H 2B 3B HR RBI SB SO\n' \
|
||||
f'{ab: >3} {run: >2} {hit: ^3} {double: >2} {triple: >2} {hr: >2} {rbi: >3} ' \
|
||||
f'{sb: >2} {so: ^3}\n```'
|
||||
|
||||
p_query = await db_get('pitchingstats/totals', params=[('season', season), ('player_id', player['id'])])
|
||||
if p_query['count'] > 0:
|
||||
p = p_query['stats'][0]
|
||||
|
||||
if p['ip'] > 0:
|
||||
if b is not None and p['ip'] > b['pa']:
|
||||
batter_priority = False
|
||||
win = f'{p["win"]:.0f}'
|
||||
loss = f'{p["loss"]:.0f}'
|
||||
save = f'{p["sv"]:.0f}'
|
||||
era = f'{(p["erun"] * 9) / p["ip"]:.2f}'
|
||||
# game = f'{p["game"]:.0f}'
|
||||
# gs = f'{p["gs"]:.0f}'
|
||||
ip = f'{p["ip"]:.0f}'
|
||||
if p["ip"] % 1 == 0:
|
||||
ip += '.0'
|
||||
elif str(p["ip"] % 1)[2] == '3':
|
||||
ip += '.1'
|
||||
else:
|
||||
ip += '.2'
|
||||
so = f'{p["so"]:.0f}'
|
||||
whip = f'{(p["bb"] + p["hit"]) / p["ip"]:.2f}'
|
||||
pitching_string = f'```\n' \
|
||||
f' W L SV ERA IP SO WHIP\n' \
|
||||
f'{win: >2} {loss: >2} {save: >2} {era: >5} {ip: >5}\n``````\n' \
|
||||
f'{so: >3} {whip: >4}\n```'
|
||||
|
||||
if batting_string and batter_priority:
|
||||
embed.add_field(name='Batting Stats', value=batting_string, inline=False)
|
||||
if pitching_string:
|
||||
embed.add_field(name='Pitching Stats', value=pitching_string, inline=False)
|
||||
if batting_string and not batter_priority:
|
||||
embed.add_field(name='Batting Stats', value=batting_string, inline=False)
|
||||
else:
|
||||
b_query = await db_get('plays/batting', params=[('player_id', player['id'])])
|
||||
p_query = await db_get('plays/pitching', params=[('player_id', player['id'])])
|
||||
batter_priority = True
|
||||
b, p, batting_string, pitching_string = None, None, None, None
|
||||
|
||||
if b_query['count'] > 0:
|
||||
b = b_query['stats'][0]
|
||||
batting_string = f'```\n' \
|
||||
f' AVG OBP SLG OPS\n' \
|
||||
f' {avg:.3f} {obp:.3f} {slg:.3f} {ops:.3f}\n``````\n' \
|
||||
f' AB R H 2B 3B HR RBI SB SO\n' \
|
||||
f'{ab: >3} {run: >2} {hit: ^3} {double: >2} {triple: >2} {hr: >2} {rbi: >3} ' \
|
||||
f'{sb: >2} {so: ^3}\n```'
|
||||
|
||||
p_query = await db_get('pitchingstats/totals', params=[('season', season), ('player_id', player['id'])])
|
||||
if p_query['count'] > 0:
|
||||
p = p_query['stats'][0]
|
||||
|
||||
if p['ip'] > 0:
|
||||
if b is not None and p['ip'] > b['pa']:
|
||||
f' AVG OBP SLG\n' \
|
||||
f' {b["avg"]:.3f} {b["obp"]:.3f} {b["slg"]:.3f}\n``````\n' \
|
||||
f' OPS wOBA WPA\n' \
|
||||
f' {b["ops"]:.3f} {b["woba"]:.3f} {b["wpa"]:.3f}\n``````\n' \
|
||||
f' PA H RBI 2B 3B HR SB\n' \
|
||||
f'{b["pa"]: >3} {b["hit"]: ^3} {b["rbi"]: ^3} {b["double"]: >2} {b["triple"]: >2} ' \
|
||||
f'{b["hr"]: >2} {b["sb"]: >2}```\n'
|
||||
if p_query['count'] > 0:
|
||||
p = p_query['stats'][0]
|
||||
if b is None or p["tbf"] > b["pa"]:
|
||||
batter_priority = False
|
||||
win = f'{p["win"]:.0f}'
|
||||
loss = f'{p["loss"]:.0f}'
|
||||
save = f'{p["sv"]:.0f}'
|
||||
era = f'{(p["erun"] * 9) / p["ip"]:.2f}'
|
||||
# game = f'{p["game"]:.0f}'
|
||||
# gs = f'{p["gs"]:.0f}'
|
||||
ip = f'{p["ip"]:.0f}'
|
||||
if p["ip"] % 1 == 0:
|
||||
ip += '.0'
|
||||
elif str(p["ip"] % 1)[2] == '3':
|
||||
ip += '.1'
|
||||
else:
|
||||
ip += '.2'
|
||||
so = f'{p["so"]:.0f}'
|
||||
whip = f'{(p["bb"] + p["hit"]) / p["ip"]:.2f}'
|
||||
pitching_string = f'```\n' \
|
||||
f' W L SV ERA IP SO WHIP\n' \
|
||||
f'{win: >2} {loss: >2} {save: >2} {era: >5} {ip: >5} ' \
|
||||
f'{so: >3} {whip: >4}\n```'
|
||||
|
||||
if batting_string and batter_priority:
|
||||
embed.add_field(name='Batting Stats', value=batting_string, inline=False)
|
||||
if pitching_string:
|
||||
embed.add_field(name='Pitching Stats', value=pitching_string, inline=False)
|
||||
if batting_string and not batter_priority:
|
||||
embed.add_field(name='Batting Stats', value=batting_string, inline=False)
|
||||
ip_whole = math.floor(p['outs'] / 3)
|
||||
ip_denom = p['outs'] % 3
|
||||
ips = ip_whole + (ip_denom * 0.1)
|
||||
|
||||
kpbb = f'{p["k/bb"]:.1f}'
|
||||
era = f'{p["era"]:.2f}'
|
||||
whip = f'{p["whip"]:.2f}'
|
||||
pitching_string = f'```\n' \
|
||||
f' W-L SV ERA WHIP\n' \
|
||||
f'{p["win"]: >2}-{p["loss"]: <2} {p["save"]: >2} {era: >5} {whip: >4}\n``````\n' \
|
||||
f' IP SO K/BB WPA\n' \
|
||||
f'{ips: >5} {p["so"]: ^3} {kpbb: ^4} {p["wpa"]:.3f}\n```'
|
||||
|
||||
if batting_string and batter_priority:
|
||||
embed.add_field(name='Batting Stats', value=batting_string, inline=False)
|
||||
if pitching_string:
|
||||
embed.add_field(name='Pitching Stats', value=pitching_string, inline=False)
|
||||
if batting_string and not batter_priority:
|
||||
embed.add_field(name='Batting Stats', value=batting_string, inline=False)
|
||||
|
||||
return embed
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user