def play_check(game,url=None,auto=None): brc = ranges_calc.brc_calc(game) if game.Ump_Mode == 'Manual': if auto: result = auto game.Situation = auto game.save() msg = (f"Game {game.Game_ID} has an {result}.") if url: msg += (f"Please visit {url} to manage this game.") webhook_functions.ump_ping(game,msg) elif game.C_Throw and game.R_Steal: msg = (f"Steal and throw are in for game {game.Game_ID}. ") if url: msg += (f"Please visit {url} to manage this game.") webhook_functions.ump_ping(game,msg) elif game.Pitch and game.Swing and game.Runner == None: msg = (f"Pitch and swing are in for game {game.Game_ID}. ") if url: msg += (f"Please visit {url} to manage this game.") webhook_functions.ump_ping(game,msg) else: play_process(game,auto) if game.Step == 3: play_process_end_PA(game) if game.Step == 1: play_process_start_PA(game) if game.Step == 2 and game.Pitch and game.Swing and game.Runner == None: play_process(game) play_process_end_PA(game) play_process_start_PA(game)
def play_process(game,auto=None): brc = ranges_calc.brc_calc(game) if game.Step == 1: play_process_start_PA(game) elif game.Step == 2: if auto: result = auto runs_scored,outs,runners_scored,new_outcome = play_outcome(game,brc,result) if result[0:6] == 'AutoSB': play_type = 'Steal' else: play_type = 'Swing' result_msg = [game.Inning, game.Outs, brc, play_type, game.Pitcher.Player_Name, game.Batter.Player_Name, '', '', '', result] result_msg.append(runs_scored) msg = auto_result_bug(game,result_msg) reddit_autoresultbug(game,result_msg) webhook_functions.swing_result(game,msg) scorebook_line = save_play_result(game,result_msg,runs_scored,outs,result,runners_scored) game.Step = 3 game.Situation = None game.save() elif game.C_Throw and game.R_Steal: result,runner = resulting_steal(game) result_msg = [game.Inning, game.Outs, brc, "Steal", game.Catcher.Player_Name, runner.Player_Name, game.C_Throw, game.R_Steal, ranges_calc.calc_diff(game.C_Throw,game.R_Steal), result] runs_scored,outs,runners_scored,new_outcome = play_outcome(game,brc,result) result_msg.append(runs_scored) msg = steal_result_bug(game,result_msg) reddit_stealresultbug(game,result_msg) webhook_functions.steal_result(game,runner,msg) scorebook_line = save_play_result(game,result_msg,runs_scored,outs,result,runners_scored,runner) game.Step = 3 game.save() elif game.Pitch and game.Swing and game.Runner == None: result = resulting_swing(game) result_msg = [game.Inning, game.Outs, brc, "Swing", game.Pitcher.Player_Name, game.Batter.Player_Name, game.Pitch, game.Swing, ranges_calc.calc_diff(game.Pitch,game.Swing), result] runs_scored,outs,runners_scored,new_outcome = play_outcome(game,brc,result) result_msg.append(runs_scored) msg = swing_result_bug(game,result_msg) reddit_resultbug(game,result_msg) webhook_functions.swing_result(game,msg) scorebook_line = save_play_result(game,result_msg,runs_scored,outs,result,runners_scored) game.Step = 3 game.save() elif game.Step == 3: play_process_end_PA(game)
def game_page(game_number): game = Games.get(Games.Game_Number == game_number) lineups = Lineups.select().where(Lineups.Game_Number == game.Game_Number).order_by(Lineups.Team, Lineups.Order.asc(), Lineups.Box.asc()) game_pas = All_PAs.select().where(All_PAs.Game_No == game.Game_Number).order_by(All_PAs.Play_No.desc()) brc = brc_calc(game) gamestats = stat_generator(game,lineups,game_pas) thread_url = reddit_threadURL(game) return render_template( 'game_page.html', game = game, brc = brc, lineups = lineups, game_pas = game_pas, gamestats = gamestats, thread_url = thread_url )
def resulting_swing(game): handedness = ranges_calc.calc_handedness(game.Pitcher,game.Batter) ranges = ranges_calc.calc_ranges(ranges_lookup.obr_dict, ranges_lookup.modifiers_dict, game.Pitcher, game.Batter, handedness) if game.Bunt == True: ranges, all_order = ranges_calc.bunt_calc(game, ranges, ranges_lookup.bunt_dict) else: if (game.First_Base != None or game.Second_Base != None): ranges, obr_ordering = ranges_calc.wh_calc(game, ranges) else: obr_ordering = ['HR', '3B', '2B', '1B', 'IF1B', 'BB'] ranges = ranges_calc.go_calc(game, ranges, ranges_lookup.go_order_dict) if game.Outs != 2 and (game.Second_Base != None or game.Third_Base != None): ranges, fo_ordering = ranges_calc.dfo_calc(game, ranges) else: fo_ordering = ['FO'] brc = ranges_calc.brc_calc(game) outs_ordering = ranges_lookup.go_order_dict[str(brc) + '_' + str(game.Outs)] if outs_ordering[0] == 'GORA': all_order = obr_ordering + ['GORA'] + fo_ordering + outs_ordering[1:] else: all_order = obr_ordering + fo_ordering + outs_ordering result_list = [] for result in all_order: for _ in range(ranges[result]): result_list.append(result) diff = ranges_calc.calc_diff(game.Pitch,game.Swing) try: result = result_list[diff] except: if game.First_Base != None: firstb = game.First_Base.Player_Name else: firstb = None if game.Second_Base != None: secondb = game.Second_Base.Player_Name else: secondb = None if game.Third_Base != None: thirdb = game.Third_Base.Player_Name else: thirdb = None print(game.Outs, game.Pitcher.Player_Name, game.Batter.Player_Name, firstb, secondb, thirdb, ranges) return result
def calc_code(game, bunt, if_i): handedness = calc.ranges_calc.calc_handedness(game.Pitcher, game.Batter) ranges = ranges_calc.calc_ranges(ranges_lookup.obr_dict, ranges_lookup.modifiers_dict, game.Pitcher, game.Batter, handedness) if bunt: ranges, all_order = ranges_calc.bunt_calc(game, ranges, ranges_lookup.bunt_dict) else: if (game.First_Base != None or game.Second_Base != None): ranges, obr_ordering = ranges_calc.wh_calc(game, ranges) else: obr_ordering = ['HR', '3B', '2B', '1B', 'IF1B', 'BB'] ranges = ranges_calc.go_calc(game, ranges, ranges_lookup.go_order_dict) if game.Outs != 2 and (game.Second_Base != None or game.Third_Base != None): ranges, fo_ordering = ranges_calc.dfo_calc(game, ranges) else: fo_ordering = ['FO'] brc = ranges_calc.brc_calc(game) outs_ordering = ranges_lookup.go_order_dict[str(brc) + '_' + str(game.Outs)] all_order = obr_ordering + fo_ordering + outs_ordering result_list = [] for result in all_order: for _ in range(ranges[result]): result_list.append(result) current = 0 results = [] for outcome in all_order: window = ranges[outcome] start = current end = current + window - 1 line = {} line['Outcome'] = outcome line['Range'] = window line['Start'] = start line['End'] = end results.append(line) current = end + 1 ranges_html = gen_ranges_html(results) return (ranges_html, result_list)
async def steal(received): if received['Redditor']: reddit_name = received['Redditor'] runners = (Games.select( Games, Players).join(Lineups).join(Players).join(Users).where( (Users.Reddit_Name == reddit_name) & (Games.Status == 'Started') & (((Games.First_Base == Players.Player_ID) & (Games.Second_Base.is_null(True))) | ( (Games.Second_Base == Players.Player_ID) & (Games.Third_Base.is_null(True))) | ((Games.Third_Base == Players.Player_ID))))).objects() elif received['Discord']: snowflake = received['Discord'] runners = (Games.select( Games, Players).join(Lineups).join(Players).join(Users).where( (Users.Discord_ID == snowflake) & (Games.Status == 'Started') & (((Games.First_Base == Players.Player_ID) & (Games.Second_Base.is_null(True))) | ( (Games.Second_Base == Players.Player_ID) & (Games.Third_Base.is_null(True))) | ((Games.Third_Base == Players.Player_ID))))).objects() if len(runners) > 0: with db.atomic(): game_no = None for entry in runners: brc = brc_calc(entry) if (brc == 1 or brc == 5 ) and entry.First_Base.Player_ID == entry.Player_ID: runner_num = 1 runner_name = entry.First_Base.Player_Name game_no = entry.Game_Number break elif (brc == 2 or brc == 4) and entry.Second_Base.Player_ID == entry.Player_ID: runner_num = 2 runner_name = entry.Second_Base.Player_Name game_no = entry.Game_Number break elif entry.Third_Base.Player_ID == entry.Player_ID: runner_num = 3 runner_name = entry.Third_Base.Player_Name game_no = entry.Game_Number break if game_no: if runner_num == 1: to_steal = 'second base' elif runner_num == 2: to_steal = 'third base' elif runner_num == 3: to_steal = 'home plate' game = Games.get(Games.Game_Number == game_no) game.Steal_Timer = time.time() game.Runner = runner_num game.R_Steal = int(received['Number']) game.save() webhook_functions.steal_start(game, runner_num) msg = ( f"You are stealing {to_steal} with {int(received['Number'])}." ) # return([msg,game,runner_name,to_steal]) return (msg) else: return ("You are not in a position to steal currently.")
def game_manage(game_number): game = Games.get(Games.Game_Number == game_number) lineups = Lineups.select().where(Lineups.Game_Number == game.Game_Number).order_by(Lineups.Team, Lineups.Order.asc(), Lineups.Box.asc()) game_pas = All_PAs.select().where(All_PAs.Game_No == game.Game_Number).order_by(All_PAs.Play_No.desc()) brc = brc_calc(game) gamestats = stat_generator(game,lineups,game_pas) if request.method == 'POST': form = GameStatusForm() if form.validate_on_submit(): auto = None game.Ump_Mode = form.ump_mode.data if form.status.data != '' and form.step.data != None: game.Status = form.status.data if form.step.data != '' and form.step.data != None: game.Step = int(form.step.data) game.save() if game.Step == 1: if form.ump_flavor.data != '': with db.atomic(): game.Ump_Flavor = form.ump_flavor.data game.save() elif game.Step == 2: if form.auto_options.data == 'Reset Timer': game.Situation = None if game.Steal_Timer: game.Steal_Timer = time.time() else: game.PA_Timer = time.time() game.save() elif form.auto_options.data == 'Process Auto': auto = game.Situation else: if form.r_steal.data != '' and form.runner.data != '' and not game.R_Steal: webhook_functions.steal_start(game,form.runner.data) try: if form.bunt.data: bunt = True else: bunt = False except: bunt = False try: if form.infield_in.data: infield_in = True else: infield_in = False except: infield_in = False with db.atomic(): if form.runner.data == '': form.runner.data = None game_update = {'Status':form.status.data, 'Pitch':form.pitch.data,'Swing':form.swing.data,'R_Steal':form.r_steal.data,'C_Throw':form.c_throw.data,'Runner':form.runner.data, 'Ump_Flavor':form.ump_flavor.data,'B_Flavor':form.b_flavor.data,'Bunt':bunt,'Infield_In':infield_in} Games.update(game_update).where(Games.Game_Number == game.Game_Number).execute() game = Games.get(Games.Game_Number == game_number) calc.play_process(game,auto) return redirect(url_for('games_bp.game_manage',game_number=game_number)) else: form = GameStatusForm(data=game_populate(game)) return render_template( 'manage/game_manage.html', game = game, form = form, brc = brc, lineups = lineups, game_pas = game_pas, gamestats = gamestats, user = g.user )