Run Black formatter across 83 files and fix 1514 ruff violations: - E722: bare except → typed exceptions (17 fixes) - E711/E712/E721: comparison style fixes with noqa for SQLAlchemy (44 fixes) - F841: unused variable assignments (70 fixes) - F541/F401: f-string and import cleanup (1383 auto-fixes) Remaining 925 errors are all F403/F405 (star imports) — structural, requires converting to explicit imports in a separate effort. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
70 lines
2.5 KiB
Python
70 lines
2.5 KiB
Python
import discord
|
|
import helpers
|
|
import logging
|
|
import random
|
|
|
|
from in_game import data_cache
|
|
from dataclasses import asdict
|
|
|
|
logger = logging.getLogger("discord_app")
|
|
|
|
|
|
def get_result(pitcher: data_cache.PitchingWrapper, batter: data_cache.BattingWrapper):
|
|
which = random.choice(["pitcher", "batter"])
|
|
logger.info(f"in_game.simulations - get_result - which: {which}")
|
|
|
|
unused_fields = ["avg", "obp", "slg", "pull_rate", "center_rate", "slap_rate"]
|
|
pit_hand = pitcher.card.hand
|
|
bat_hand = batter.card.hand
|
|
|
|
if which == "pitcher":
|
|
logger.info("in_game.simulations - get_result - grabbing pitcher card chances")
|
|
ch_data = pitcher.ratings_vl if bat_hand == "L" else pitcher.ratings_vr
|
|
logger.info(f"ch_data: {ch_data}")
|
|
# for field in fields(ch_data):
|
|
# if field.name not in unused_fields:
|
|
# ch_results.append(field.name)
|
|
# ch_probs.append(getattr(data_cache.PitchingRatings, field.name))
|
|
else:
|
|
logger.info("in_game.simulations - get_result - grabbing batter card chances")
|
|
ch_data = batter.ratings_vl if pit_hand == "L" else batter.ratings_vr
|
|
logger.info(f"ch_data: {ch_data}")
|
|
# for field in fields(ch_data):
|
|
# if field.name not in unused_fields:
|
|
# ch_results.append(field.name)
|
|
# ch_probs.append(getattr(data_cache.BattingRatings, field.name))
|
|
ch_dict = {k: v for k, v in asdict(ch_data).items()}
|
|
for x in unused_fields:
|
|
if x in ch_dict:
|
|
del ch_dict[x]
|
|
|
|
ch_results = list(ch_dict.keys())
|
|
ch_probs = list(ch_dict.values())
|
|
|
|
logger.info(f"ch_results: {ch_results}")
|
|
logger.info(f"ch_probs: {ch_probs}")
|
|
result = random.choices(ch_results, ch_probs)
|
|
logger.info(f"result: {result}")
|
|
|
|
return result[0]
|
|
|
|
|
|
def get_pos_embeds(this_pitcher, this_batter, pit_card, bat_card):
|
|
pit_desc = helpers.player_desc(this_pitcher)
|
|
bat_desc = helpers.player_desc(this_batter)
|
|
embed = discord.Embed(
|
|
color=int(helpers.SBA_COLOR, 16), title=f"{pit_desc} vs. {bat_desc}"
|
|
)
|
|
embed.set_image(url=helpers.player_pcard(this_pitcher))
|
|
embed2 = discord.Embed(color=int(helpers.SBA_COLOR, 16))
|
|
embed2.set_image(url=helpers.player_bcard(this_batter))
|
|
embed3 = discord.Embed(color=int(helpers.SBA_COLOR, 16))
|
|
|
|
result = get_result(pit_card, bat_card)
|
|
|
|
embed3.add_field(name="Pitcher", value=pit_desc)
|
|
embed3.add_field(name="Batter", value=bat_desc)
|
|
embed3.add_field(name="Result", value=result, inline=False)
|
|
|
|
return [embed, embed2, embed3]
|