Fixed HR unearned bug
Added pitching statline
This commit is contained in:
parent
f40347e0bb
commit
c3c88af14a
@ -700,16 +700,17 @@ def log_run_scored(session: Session, runner: Lineup, this_play: Play, is_earned:
|
||||
logger.info(f'last_ab: {last_ab}')
|
||||
|
||||
errors = session.exec(select(func.count(Play.id)).where(
|
||||
Play.game == this_play.game, Play.inning_num == last_ab.inning_num, Play.inning_half == last_ab.inning_half, Play.error == 1
|
||||
Play.game == this_play.game, Play.inning_num == last_ab.inning_num, Play.inning_half == last_ab.inning_half, Play.error == 1, Play.complete == True
|
||||
)).one()
|
||||
outs = session.exec(select(func.sum(Play.outs)).where(
|
||||
Play.game == this_play.game, Play.inning_num == last_ab.inning_num, Play.inning_half == last_ab.inning_half
|
||||
Play.game == this_play.game, Play.inning_num == last_ab.inning_num, Play.inning_half == last_ab.inning_half, Play.complete == True
|
||||
)).one()
|
||||
|
||||
logger.info(f'errors: {errors} / outs: {outs}')
|
||||
if errors + outs + this_play.error >= 3:
|
||||
logger.info(f'unearned run')
|
||||
is_earned = False
|
||||
|
||||
if outs is not None:
|
||||
if errors + outs + this_play.error >= 3:
|
||||
logger.info(f'unearned run')
|
||||
is_earned = False
|
||||
|
||||
last_ab.e_run = 1 if is_earned else 0
|
||||
session.add(last_ab)
|
||||
@ -1698,9 +1699,7 @@ async def homeruns(session: Session, interaction: discord.Interaction, this_play
|
||||
this_play.bphr = 1 if homerun_type == 'ballpark' else 0
|
||||
this_play = advance_runners(session, this_play, num_bases=4)
|
||||
this_play.rbi += 1
|
||||
|
||||
session.add(this_play)
|
||||
session.commit()
|
||||
log_run_scored(session, this_play.batter, this_play)
|
||||
|
||||
session.refresh(this_play)
|
||||
return this_play
|
||||
|
||||
@ -936,4 +936,47 @@ def get_pitching_statline(session: Session, this_lineup: Lineup) -> str:
|
||||
Play.game == this_lineup.game, Play.pitcher == this_lineup, Play.complete == True
|
||||
)).one()
|
||||
|
||||
## TODO: complete pitching statline
|
||||
if outs is None:
|
||||
return '1st Batter Faced'
|
||||
|
||||
whole_innings = math.floor(outs / 3)
|
||||
rem_outs = outs % 3
|
||||
|
||||
pit_string = f'{whole_innings}.{rem_outs} IP'
|
||||
logger.info(f'IP pit_string: {pit_string}')
|
||||
|
||||
runs = session.exec(select(func.count(Play.id)).where(
|
||||
Play.game == this_lineup.game, Play.pitcher == this_lineup, Play.run == 1
|
||||
)).one()
|
||||
if runs > 0:
|
||||
number_string = f'{runs} ' if runs > 1 else ""
|
||||
pit_string += f', {number_string}R'
|
||||
|
||||
e_runs = session.exec(select(func.count(Play.id)).where(
|
||||
Play.game == this_lineup.game, Play.pitcher == this_lineup, Play.e_run == 1
|
||||
)).one()
|
||||
if e_runs != runs:
|
||||
pit_string += f' ({e_runs} ER)'
|
||||
|
||||
hits = session.exec(select(func.count(Play.id)).where(
|
||||
Play.game == this_lineup.game, Play.pitcher == this_lineup, Play.hit == 1
|
||||
)).one()
|
||||
if hits > 0:
|
||||
pit_string += f', {hits} H'
|
||||
|
||||
walks = session.exec(select(func.count(Play.id)).where(
|
||||
Play.game == this_lineup.game, Play.pitcher == this_lineup, Play.bb == 1
|
||||
)).one()
|
||||
if walks > 0:
|
||||
number_string = f'{walks} ' if walks > 1 else ""
|
||||
pit_string += f', {number_string}BB'
|
||||
|
||||
strikeouts = session.exec(select(func.count(Play.id)).where(
|
||||
Play.game == this_lineup.game, Play.pitcher == this_lineup, Play.so == 1
|
||||
)).one()
|
||||
if strikeouts > 0:
|
||||
number_string = f'{strikeouts} ' if strikeouts > 1 else ""
|
||||
pit_string += f', {number_string}K'
|
||||
|
||||
return pit_string
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user