Add gauntlet team support to get_team_or_none
This commit is contained in:
parent
f67135e2cf
commit
55b35a242a
@ -60,22 +60,29 @@ def get_active_games_by_team(session: Session, team: Team) -> list[Game]:
|
||||
|
||||
|
||||
async def get_team_or_none(
|
||||
session: Session, team_id: int | None = None, gm_id: int | None = None, team_abbrev: str | None = None, skip_cache: bool = False) -> Team | None:
|
||||
logger.info(f'Getting team or none / team_id: {team_id} / gm_id: {gm_id} / team_abbrev: {team_abbrev} / skip_cache: {skip_cache}')
|
||||
session: Session, team_id: int | None = None, gm_id: int | None = None, team_abbrev: str | None = None, skip_cache: bool = False, main_team: bool = None, gauntlet_team: bool = None) -> Team | None:
|
||||
logger.info(f'Getting team or none / team_id: {team_id} / gm_id: {gm_id} / team_abbrev: {team_abbrev} / skip_cache: {skip_cache} / main_team: {main_team} / gauntlet_team: {gauntlet_team}')
|
||||
if gm_id is not None:
|
||||
if main_team is None and gauntlet_team is None:
|
||||
main_team = True
|
||||
gauntlet_team = False
|
||||
elif main_team == gauntlet_team:
|
||||
log_exception(KeyError, 'Must select either main_team or gauntlet_team')
|
||||
|
||||
if team_id is None and gm_id is None and team_abbrev is None:
|
||||
err = 'One of "team_id", "gm_id", or "team_abbrev" must be included in search'
|
||||
logger.error(f'gameplay_models - get_team - {err}')
|
||||
raise TypeError(err)
|
||||
log_exception(KeyError, 'One of "team_id", "gm_id", or "team_abbrev" must be included in search')
|
||||
|
||||
if not skip_cache:
|
||||
if team_id is not None:
|
||||
this_team = session.get(Team, team_id)
|
||||
else:
|
||||
if gm_id is not None:
|
||||
statement = select(Team).where(Team.gmid == gm_id)
|
||||
for team in session.exec(select(Team).where(Team.gmid == gm_id)).all():
|
||||
if ('gauntlet' in team.abbrev.lower() and gauntlet_team) or ('gauntlet' not in team.abbrev.lower() and main_team):
|
||||
this_team = team
|
||||
break
|
||||
else:
|
||||
statement = select(Team).where(func.lower(Team.abbrev) == team_abbrev.lower())
|
||||
this_team = session.exec(statement).one_or_none()
|
||||
this_team = session.exec(select(Team).where(func.lower(Team.abbrev) == team_abbrev.lower())).one_or_none()
|
||||
|
||||
if this_team is not None:
|
||||
logger.debug(f'we found a team: {this_team} / created: {this_team.created}')
|
||||
@ -112,6 +119,9 @@ async def get_team_or_none(
|
||||
elif team_abbrev is not None:
|
||||
t_query = await db_get('teams', params=[('abbrev', team_abbrev)])
|
||||
if t_query['count'] != 0:
|
||||
if 'gauntlet' in team_abbrev.lower():
|
||||
return cache_team(t_query['teams'][0])
|
||||
|
||||
for team in [x for x in t_query['teams'] if 'gauntlet' not in x['abbrev'].lower()]:
|
||||
return cache_team(team)
|
||||
|
||||
@ -906,3 +916,13 @@ def get_available_pitchers(session: Session, this_game: Game, this_team: Team, s
|
||||
pitchers.sort(key=sort_by_pow, reverse=True)
|
||||
|
||||
return pitchers
|
||||
|
||||
|
||||
def get_available_batters(session: Session, this_game: Game, this_team: Team) -> list[Card]:
|
||||
logger.info(f'getting available batters for team {this_team.id} in game {this_game.id}')
|
||||
all_subs = get_available_subs(session, this_game, this_team)
|
||||
logger.info(f'all_subs: {all_subs}')
|
||||
batters = [x for x in all_subs if x.batterscouting is not None]
|
||||
logger.info(f'batters: {batters}')
|
||||
|
||||
return batters
|
||||
|
||||
Loading…
Reference in New Issue
Block a user