Support for Exhibition games & Swagger updates
This commit is contained in:
parent
75e2f05f48
commit
18a6ed2ebd
@ -25,7 +25,9 @@ master_debug = False
|
||||
DB_URL = 'https://pd.manticorum.com/api/'
|
||||
AUTH_TOKEN = f'{os.environ.get("API_TOKEN")}'
|
||||
AUTH_HEADER = {'Authorization': f'Bearer {AUTH_TOKEN}'}
|
||||
PRIVATE_IN_SCHEMA = True if os.environ.get('PRIVATE_IN_SCHEMA').upper() == 'TRUE' else False
|
||||
|
||||
priv_help = False if not os.environ.get('PRIVATE_IN_SCHEMA') else os.environ.get('PRIVATE_IN_SCHEMA').upper()
|
||||
PRIVATE_IN_SCHEMA = True if priv_help else False
|
||||
|
||||
|
||||
if os.environ.get('TESTING') == 'False':
|
||||
|
||||
@ -2,7 +2,7 @@ from fastapi import APIRouter, Depends, HTTPException
|
||||
import logging
|
||||
|
||||
from ..db_engine import db, Player
|
||||
from ..dependencies import oauth2_scheme, valid_token, LOG_DATA
|
||||
from ..dependencies import oauth2_scheme, valid_token, LOG_DATA, PRIVATE_IN_SCHEMA
|
||||
|
||||
logging.basicConfig(
|
||||
filename=LOG_DATA['filename'],
|
||||
@ -12,11 +12,11 @@ logging.basicConfig(
|
||||
|
||||
router = APIRouter(
|
||||
prefix='/api/v2/admin',
|
||||
tags=['admin']
|
||||
tags=['Admin']
|
||||
)
|
||||
|
||||
|
||||
@router.post('/stl-fix')
|
||||
@router.post('/stl-fix', include_in_schema=PRIVATE_IN_SCHEMA)
|
||||
async def stl_cardinals_fix(token: str = Depends(oauth2_scheme)):
|
||||
if not valid_token(token):
|
||||
logging.warning(f'Bad Token: {token}')
|
||||
|
||||
@ -5,7 +5,7 @@ import pydantic
|
||||
from pandas import DataFrame
|
||||
|
||||
from ..db_engine import db, Award, model_to_dict
|
||||
from ..dependencies import oauth2_scheme, valid_token, LOG_DATA
|
||||
from ..dependencies import oauth2_scheme, valid_token, LOG_DATA, PRIVATE_IN_SCHEMA
|
||||
|
||||
logging.basicConfig(
|
||||
filename=LOG_DATA['filename'],
|
||||
@ -28,7 +28,12 @@ class AwardModel(pydantic.BaseModel):
|
||||
image: Optional[str] = None
|
||||
|
||||
|
||||
@app.get('/api/v1/awards')
|
||||
class AwardReturnList(pydantic.BaseModel):
|
||||
count: int
|
||||
awards: list[AwardModel]
|
||||
|
||||
|
||||
@router.get('')
|
||||
async def get_awards(
|
||||
name: Optional[str] = None, season: Optional[int] = None, timing: Optional[str] = None,
|
||||
card_id: Optional[int] = None, team_id: Optional[int] = None, image: Optional[str] = None,
|
||||
@ -72,7 +77,7 @@ async def get_awards(
|
||||
return return_val
|
||||
|
||||
|
||||
@app.get('/api/v1/awards/{award_id}')
|
||||
@router.get('/{award_id}')
|
||||
async def get_one_award(award_id, csv: Optional[bool] = None):
|
||||
try:
|
||||
this_award = Award.get_by_id(award_id)
|
||||
@ -97,7 +102,7 @@ async def get_one_award(award_id, csv: Optional[bool] = None):
|
||||
return return_val
|
||||
|
||||
|
||||
@app.post('/api/v1/awards')
|
||||
@router.post('', include_in_schema=PRIVATE_IN_SCHEMA)
|
||||
async def post_awards(award: AwardModel, token: str = Depends(oauth2_scheme)):
|
||||
if not valid_token(token):
|
||||
logging.warning(f'Bad Token: {token}')
|
||||
@ -129,7 +134,7 @@ async def post_awards(award: AwardModel, token: str = Depends(oauth2_scheme)):
|
||||
)
|
||||
|
||||
|
||||
@app.delete('/api/v1/awards/{award_id}')
|
||||
@router.delete('/{award_id}', include_in_schema=PRIVATE_IN_SCHEMA)
|
||||
async def delete_award(award_id, token: str = Depends(oauth2_scheme)):
|
||||
if not valid_token(token):
|
||||
logging.warning(f'Bad Token: {token}')
|
||||
|
||||
@ -7,7 +7,7 @@ import pydantic
|
||||
from pandas import DataFrame
|
||||
|
||||
from ..db_engine import db, BattingStat, model_to_dict, fn, Card, Player, Current
|
||||
from ..dependencies import oauth2_scheme, valid_token, LOG_DATA
|
||||
from ..dependencies import oauth2_scheme, valid_token, LOG_DATA, PRIVATE_IN_SCHEMA
|
||||
|
||||
logging.basicConfig(
|
||||
filename=LOG_DATA['filename'],
|
||||
@ -17,7 +17,7 @@ logging.basicConfig(
|
||||
|
||||
router = APIRouter(
|
||||
prefix='/api/v2/batstats',
|
||||
tags=['batstats']
|
||||
tags=['Pre-Season 7 Batting Stats']
|
||||
)
|
||||
|
||||
|
||||
@ -63,7 +63,12 @@ class BattingStatModel(pydantic.BaseModel):
|
||||
stats: List[BatStat]
|
||||
|
||||
|
||||
@router.get('')
|
||||
class BatStatReturnList(pydantic.BaseModel):
|
||||
count: int
|
||||
stats: list[BatStat]
|
||||
|
||||
|
||||
@router.get('', response_model=BatStatReturnList)
|
||||
async def get_batstats(
|
||||
card_id: int = None, player_id: int = None, team_id: int = None, vs_team_id: int = None, week: int = None,
|
||||
season: int = None, week_start: int = None, week_end: int = None, created: int = None, csv: bool = None):
|
||||
@ -124,7 +129,7 @@ async def get_batstats(
|
||||
return return_val
|
||||
|
||||
|
||||
@router.get('/player/{player_id}')
|
||||
@router.get('/player/{player_id}', response_model=BatStat)
|
||||
async def get_player_stats(
|
||||
player_id: int, team_id: int = None, vs_team_id: int = None, week_start: int = None, week_end: int = None,
|
||||
csv: bool = None):
|
||||
@ -172,7 +177,7 @@ async def get_player_stats(
|
||||
return return_val
|
||||
|
||||
|
||||
@router.post('')
|
||||
@router.post('', include_in_schema=PRIVATE_IN_SCHEMA)
|
||||
async def post_batstats(stats: BattingStatModel, token: str = Depends(oauth2_scheme)):
|
||||
if not valid_token(token):
|
||||
logging.warning(f'Bad Token: {token}')
|
||||
@ -230,7 +235,7 @@ async def post_batstats(stats: BattingStatModel, token: str = Depends(oauth2_sch
|
||||
raise HTTPException(status_code=200, detail=f'{len(new_stats)} batting lines have been added')
|
||||
|
||||
|
||||
@router.delete('/{stat_id}')
|
||||
@router.delete('/{stat_id}', include_in_schema=PRIVATE_IN_SCHEMA)
|
||||
async def delete_batstat(stat_id, token: str = Depends(oauth2_scheme)):
|
||||
if not valid_token(token):
|
||||
logging.warning(f'Bad Token: {token}')
|
||||
|
||||
@ -11,7 +11,7 @@ from pydantic import validator, root_validator
|
||||
|
||||
from ..db_engine import db, BattingCardRatings, model_to_dict, chunked, BattingCard, Player, query_to_csv, Team, \
|
||||
CardPosition
|
||||
from ..dependencies import oauth2_scheme, valid_token, LOG_DATA
|
||||
from ..dependencies import oauth2_scheme, valid_token, LOG_DATA, PRIVATE_IN_SCHEMA
|
||||
|
||||
logging.basicConfig(
|
||||
filename=LOG_DATA['filename'],
|
||||
@ -90,11 +90,16 @@ class BattingCardRatingsModel(pydantic.BaseModel):
|
||||
return values
|
||||
|
||||
|
||||
class RatingsReturnList(pydantic.BaseModel):
|
||||
count: int
|
||||
awards: list[BattingCardRatingsModel]
|
||||
|
||||
|
||||
class RatingsList(pydantic.BaseModel):
|
||||
ratings: List[BattingCardRatingsModel]
|
||||
|
||||
|
||||
@router.get('')
|
||||
@router.get('', response_model=RatingsReturnList)
|
||||
async def get_card_ratings(
|
||||
team_id: int, ts: str, battingcard_id: list = Query(default=None), cardset_id: list = Query(default=None),
|
||||
vs_hand: Literal['R', 'L', 'vR', 'vL'] = None, short_output: bool = False, csv: bool = False):
|
||||
@ -237,7 +242,7 @@ async def get_card_scouting(team_id: int, ts: str):
|
||||
raise HTTPException(status_code=400, detail='Go pester Cal - the scouting file is missing')
|
||||
|
||||
|
||||
@router.post('/calculate/scouting')
|
||||
@router.post('/calculate/scouting', include_in_schema=PRIVATE_IN_SCHEMA)
|
||||
async def post_calc_scouting(token: str = Depends(oauth2_scheme)):
|
||||
if not valid_token(token):
|
||||
logging.warning(f'Bad Token: {token}')
|
||||
@ -273,7 +278,7 @@ async def get_basic_scouting(cardset_id: list = Query(default=None)):
|
||||
raise HTTPException(status_code=400, detail='Go pester Cal - the scouting file is missing')
|
||||
|
||||
|
||||
@router.post('/calculate/basic')
|
||||
@router.post('/calculate/basic', include_in_schema=PRIVATE_IN_SCHEMA)
|
||||
async def post_calc_basic(token: str = Depends(oauth2_scheme)):
|
||||
if not valid_token(token):
|
||||
logging.warning(f'Bad Token: {token}')
|
||||
@ -470,7 +475,7 @@ async def post_calc_basic(token: str = Depends(oauth2_scheme)):
|
||||
return Response(content=csv_file, media_type='text/csv')
|
||||
|
||||
|
||||
@router.get('/{ratings_id}')
|
||||
@router.get('/{ratings_id}', response_model=BattingCardRatingsModel)
|
||||
async def get_one_rating(ratings_id: int, token: str = Depends(oauth2_scheme)):
|
||||
if not valid_token(token):
|
||||
logging.warning(f'Bad Token: {token}')
|
||||
@ -490,7 +495,7 @@ async def get_one_rating(ratings_id: int, token: str = Depends(oauth2_scheme)):
|
||||
return r_data
|
||||
|
||||
|
||||
@router.get('/player/{player_id}')
|
||||
@router.get('/player/{player_id}', response_model=BattingCardRatingsModel)
|
||||
async def get_player_ratings(
|
||||
player_id: int, variant: list = Query(default=None), short_output: bool = False,
|
||||
token: str = Depends(oauth2_scheme)):
|
||||
@ -515,7 +520,7 @@ async def get_player_ratings(
|
||||
return return_val
|
||||
|
||||
|
||||
@router.put('')
|
||||
@router.put('', include_in_schema=PRIVATE_IN_SCHEMA)
|
||||
async def put_ratings(ratings: RatingsList, token: str = Depends(oauth2_scheme)):
|
||||
if not valid_token(token):
|
||||
logging.warning(f'Bad Token: {token}')
|
||||
@ -546,7 +551,7 @@ async def put_ratings(ratings: RatingsList, token: str = Depends(oauth2_scheme))
|
||||
return f'Updated ratings: {updates}; new ratings: {len(new_ratings)}'
|
||||
|
||||
|
||||
@router.delete('/{ratings_id}')
|
||||
@router.delete('/{ratings_id}', include_in_schema=PRIVATE_IN_SCHEMA)
|
||||
async def delete_rating(
|
||||
ratings_id: int, token: str = Depends(oauth2_scheme)):
|
||||
if not valid_token(token):
|
||||
|
||||
@ -38,7 +38,7 @@ class BattingCardList(pydantic.BaseModel):
|
||||
cards: List[BattingCardModel]
|
||||
|
||||
|
||||
@router.get('')
|
||||
@router.get('', response_model=BattingCardList)
|
||||
async def get_batting_cards(
|
||||
player_id: list = Query(default=None), player_name: list = Query(default=None),
|
||||
cardset_id: list = Query(default=None), short_output: bool = False, limit: Optional[int] = None,
|
||||
|
||||
@ -26,7 +26,7 @@ class CurrentModel(pydantic.BaseModel):
|
||||
gsheet_version: str
|
||||
|
||||
|
||||
@router.get('', response_model=CurrentModel)
|
||||
@router.get('')
|
||||
async def get_current(season: Optional[int] = None, csv: Optional[bool] = False):
|
||||
if season:
|
||||
current = Current.get_or_none(season=season)
|
||||
@ -48,7 +48,7 @@ async def get_current(season: Optional[int] = None, csv: Optional[bool] = False)
|
||||
return return_val
|
||||
|
||||
|
||||
@router.get('/{current_id}', response_model=CurrentModel, include_in_schema=PRIVATE_IN_SCHEMA)
|
||||
@router.get('/{current_id}', include_in_schema=PRIVATE_IN_SCHEMA)
|
||||
async def get_one_current(current_id, csv: Optional[bool] = False):
|
||||
try:
|
||||
current = Current.get_by_id(current_id)
|
||||
@ -71,7 +71,7 @@ async def get_one_current(current_id, csv: Optional[bool] = False):
|
||||
return return_val
|
||||
|
||||
|
||||
@router.post('', response_model=CurrentModel, include_in_schema=PRIVATE_IN_SCHEMA)
|
||||
@router.post('', include_in_schema=PRIVATE_IN_SCHEMA)
|
||||
async def post_current(current: CurrentModel, token: str = Depends(oauth2_scheme)):
|
||||
if not valid_token(token):
|
||||
logging.warning(f'Bad Token: {token}')
|
||||
@ -102,7 +102,7 @@ async def post_current(current: CurrentModel, token: str = Depends(oauth2_scheme
|
||||
raise HTTPException(status_code=418, detail='Well slap my ass and call me a teapot; I could not save that team')
|
||||
|
||||
|
||||
@router.patch('/{current_id}', response_model=CurrentModel, include_in_schema=PRIVATE_IN_SCHEMA)
|
||||
@router.patch('/{current_id}', include_in_schema=PRIVATE_IN_SCHEMA)
|
||||
async def patch_current(
|
||||
current_id: int, season: Optional[int] = None, week: Optional[int] = None,
|
||||
gsheet_template: Optional[str] = None, gsheet_version: Optional[str] = None,
|
||||
|
||||
@ -11,7 +11,7 @@ from pandas import DataFrame
|
||||
from ..db_engine import db, Team, model_to_dict, fn, Pack, Card, Player, Paperdex, Notification, PackType, \
|
||||
Rarity, Current, query_to_csv, complex_data_to_csv, CARDSETS, CardPosition, BattingCardRatings, BattingCard, \
|
||||
PitchingCard, PitchingCardRatings, StratGame, LIVE_PROMO_CARDSET_ID
|
||||
from ..dependencies import oauth2_scheme, valid_token, LOG_DATA, int_timestamp
|
||||
from ..dependencies import oauth2_scheme, valid_token, LOG_DATA, int_timestamp, PRIVATE_IN_SCHEMA
|
||||
|
||||
logging.basicConfig(
|
||||
filename=LOG_DATA['filename'],
|
||||
@ -157,10 +157,15 @@ async def get_one_team(team_id, inc_packs: bool = True, csv: Optional[bool] = Fa
|
||||
|
||||
|
||||
def get_scouting_dfs(allowed_players, position: str):
|
||||
logging.info(f'allowed_players: {allowed_players}\nposition: {position}')
|
||||
positions = CardPosition.select().where(
|
||||
(CardPosition.player << allowed_players) & (CardPosition.position == position)
|
||||
)
|
||||
pos_players = [x.player.player_id for x in positions]
|
||||
logging.info(f'pos_players: {pos_players}')
|
||||
|
||||
if len(pos_players) == 0:
|
||||
return None
|
||||
|
||||
all_cards = BattingCard.select().where(BattingCard.player << pos_players)
|
||||
all_ratings = BattingCardRatings.select().where(BattingCardRatings.battingcard << all_cards)
|
||||
@ -235,7 +240,9 @@ def get_scouting_dfs(allowed_players, position: str):
|
||||
|
||||
|
||||
@router.get('/{team_id}/lineup/{difficulty_name}')
|
||||
async def get_team_lineup(team_id: int, difficulty_name: str, pitcher_name: str, build_type: str):
|
||||
async def get_team_lineup(
|
||||
team_id: int, difficulty_name: str, pitcher_name: str, build_type: str, cardset_id: list = Query(default=None),
|
||||
backup_cardset_id: list = Query(default=None)):
|
||||
"""
|
||||
d_rank: int - 10: best overall, 9: prioritize range, 8: prioritize error
|
||||
"""
|
||||
@ -244,7 +251,7 @@ async def get_team_lineup(team_id: int, difficulty_name: str, pitcher_name: str,
|
||||
db.close()
|
||||
raise HTTPException(status_code=404, detail=f'Team id {team_id} not found')
|
||||
|
||||
if difficulty_name not in CARDSETS.keys():
|
||||
if difficulty_name not in CARDSETS.keys() and difficulty_name != 'exhibition':
|
||||
db.close()
|
||||
raise HTTPException(status_code=400, detail=f'Difficulty name {difficulty_name} not a valid check')
|
||||
|
||||
@ -253,6 +260,18 @@ async def get_team_lineup(team_id: int, difficulty_name: str, pitcher_name: str,
|
||||
# )
|
||||
all_players = Player.select().where(Player.franchise == this_team.lname)
|
||||
|
||||
if difficulty_name == 'exhibition':
|
||||
logging.info(f'pulling an exhibition lineup')
|
||||
if cardset_id is None:
|
||||
db.close()
|
||||
raise HTTPException(status_code=400, detail=f'Must provide at least one cardset_id for exhibition lineups')
|
||||
legal_players = all_players.where(Player.cardset_id << cardset_id)
|
||||
|
||||
if backup_cardset_id is not None:
|
||||
backup_players = all_players.where(Player.cardset_id << backup_cardset_id)
|
||||
else:
|
||||
backup_players = all_players.where(Player.cardset_id << CARDSETS['minor-league']['primary'])
|
||||
else:
|
||||
legal_players = all_players.where(Player.cardset_id << CARDSETS[difficulty_name]['primary'])
|
||||
if 'secondary' in CARDSETS[difficulty_name]:
|
||||
backup_players = all_players.where(Player.cardset_id << CARDSETS[difficulty_name]['secondary'])
|
||||
@ -260,6 +279,7 @@ async def get_team_lineup(team_id: int, difficulty_name: str, pitcher_name: str,
|
||||
backup_players = None
|
||||
|
||||
logging.info(f'legal_players: {legal_players.count()}')
|
||||
logging.info(f'legal query: {legal_players}')
|
||||
if backup_players is not None:
|
||||
logging.info(f'backup_players: {backup_players.count()}')
|
||||
player_names = []
|
||||
@ -361,7 +381,8 @@ async def get_team_lineup(team_id: int, difficulty_name: str, pitcher_name: str,
|
||||
player_names.append(x.player.p_name)
|
||||
break
|
||||
|
||||
elif difficulty_name in ['major-league', 'flashback', 'hall-of-fame']:
|
||||
# elif difficulty_name in ['major-league', 'flashback', 'hall-of-fame']:
|
||||
else:
|
||||
logging.debug(f'entering difficulty: {difficulty_name}')
|
||||
eligible_cards = get_scouting_dfs(legal_players, position)
|
||||
logging.debug(f'got dataframe:\n{eligible_cards}')
|
||||
@ -387,7 +408,7 @@ async def get_team_lineup(team_id: int, difficulty_name: str, pitcher_name: str,
|
||||
f'final OPS: {final_ops}')
|
||||
return final_ops
|
||||
|
||||
if len(eligible_cards.index) >= 1:
|
||||
if eligible_cards is not None and len(eligible_cards.index) >= 1:
|
||||
eligible_cards['final_ops'] = eligible_cards.apply(rank_cards, axis=1)
|
||||
logging.debug(f'final_ops:\n{eligible_cards["final_ops"]}')
|
||||
eligible_cards.sort_values(by=['final_ops'], ascending=False, inplace=True)
|
||||
@ -477,6 +498,7 @@ def sort_pitchers(pitching_card_query) -> DataFrame | None:
|
||||
|
||||
ops_vl = vlval.obp + vlval.slg
|
||||
ops_vr = vrval.obp + vrval.slg
|
||||
# TODO: should this be max??
|
||||
return (ops_vr + ops_vl + min(ops_vl, ops_vr)) / 3
|
||||
|
||||
pitcher_df['total_ops'] = pitcher_df.apply(get_total_ops, axis=1)
|
||||
@ -484,19 +506,33 @@ def sort_pitchers(pitching_card_query) -> DataFrame | None:
|
||||
|
||||
|
||||
@router.get('/{team_id}/sp/{difficulty_name}')
|
||||
async def get_team_sp(team_id: int, difficulty_name: str, sp_rank: int):
|
||||
async def get_team_sp(
|
||||
team_id: int, difficulty_name: str, sp_rank: int, cardset_id: list = Query(default=None),
|
||||
backup_cardset_id: list = Query(default=None)):
|
||||
logging.info(f'get_team_sp - team_id: {team_id} / difficulty_name: {difficulty_name} / sp_rank: {sp_rank}')
|
||||
this_team = Team.get_or_none(Team.id == team_id)
|
||||
if this_team is None:
|
||||
db.close()
|
||||
raise HTTPException(status_code=404, detail=f'Team id {team_id} not found')
|
||||
|
||||
if difficulty_name not in CARDSETS.keys():
|
||||
if difficulty_name not in CARDSETS.keys() and difficulty_name != 'exhibition':
|
||||
db.close()
|
||||
raise HTTPException(status_code=400, detail=f'Difficulty name {difficulty_name} not a valid check')
|
||||
|
||||
all_players = Player.select().where(Player.mlbclub == this_team.lname)
|
||||
|
||||
if difficulty_name == 'exhibition':
|
||||
logging.info(f'pulling an exhibition lineup')
|
||||
if cardset_id is None:
|
||||
db.close()
|
||||
raise HTTPException(status_code=400, detail=f'Must provide at least one cardset_id for exhibition lineups')
|
||||
legal_players = all_players.where(Player.cardset_id << cardset_id)
|
||||
|
||||
if backup_cardset_id is not None:
|
||||
backup_players = all_players.where(Player.cardset_id << backup_cardset_id)
|
||||
else:
|
||||
backup_players = all_players.where(Player.cardset_id << CARDSETS['minor-league']['primary'])
|
||||
else:
|
||||
legal_players = all_players.where(Player.cardset_id << CARDSETS[difficulty_name]['primary'])
|
||||
if 'secondary' in CARDSETS[difficulty_name]:
|
||||
backup_players = all_players.where(Player.cardset_id << CARDSETS[difficulty_name]['secondary'])
|
||||
@ -563,13 +599,14 @@ async def get_team_sp(team_id: int, difficulty_name: str, sp_rank: int):
|
||||
db.close()
|
||||
return this_player
|
||||
|
||||
raise HTTPException(status_code=500, detail=f'No SP #{sp_rank} found for Team {team_id}')
|
||||
raise HTTPException(status_code=400, detail=f'No SP #{sp_rank} found for Team {team_id}')
|
||||
|
||||
|
||||
@router.get('/{team_id}/rp/{difficulty_name}')
|
||||
async def get_team_rp(
|
||||
team_id: int, difficulty_name: str, need: Literal['length', 'setup', 'closer', 'middle'],
|
||||
used_pitcher_ids: list = Query(default=[])):
|
||||
used_pitcher_ids: list = Query(default=[]), cardset_id: list = Query(default=None),
|
||||
backup_cardset_id: list = Query(default=None)):
|
||||
logging.info(f'get_team_rp - team_id: {team_id} / difficulty_name: {difficulty_name} / need: {need} '
|
||||
f'/ used_pitcher_ids: {used_pitcher_ids}')
|
||||
this_team = Team.get_or_none(Team.id == team_id)
|
||||
@ -577,7 +614,7 @@ async def get_team_rp(
|
||||
db.close()
|
||||
raise HTTPException(status_code=404, detail=f'Team id {team_id} not found')
|
||||
|
||||
if difficulty_name not in CARDSETS.keys():
|
||||
if difficulty_name not in CARDSETS.keys() and difficulty_name != 'exhibition':
|
||||
db.close()
|
||||
raise HTTPException(status_code=400, detail=f'Difficulty name {difficulty_name} not a valid check')
|
||||
|
||||
@ -585,12 +622,27 @@ async def get_team_rp(
|
||||
(Player.mlbclub == this_team.lname) & (Player.player_id.not_in(used_pitcher_ids))
|
||||
)
|
||||
|
||||
if difficulty_name == 'exhibition':
|
||||
logging.info(f'pulling an exhibition RP')
|
||||
if cardset_id is None:
|
||||
db.close()
|
||||
raise HTTPException(status_code=400, detail=f'Must provide at least one cardset_id for exhibition lineups')
|
||||
legal_players = all_players.where(Player.cardset_id << cardset_id)
|
||||
|
||||
if backup_cardset_id is not None:
|
||||
backup_players = all_players.where(Player.cardset_id << backup_cardset_id)
|
||||
else:
|
||||
backup_players = all_players.where(Player.cardset_id << CARDSETS['minor-league']['primary'])
|
||||
else:
|
||||
legal_players = all_players.where(Player.cardset_id << CARDSETS[difficulty_name]['primary'])
|
||||
if 'secondary' in CARDSETS[difficulty_name]:
|
||||
backup_players = all_players.where(Player.cardset_id << CARDSETS[difficulty_name]['secondary'])
|
||||
else:
|
||||
backup_players = None
|
||||
|
||||
logging.info(f'legal_players: {legal_players.count()}')
|
||||
logging.info(f'legal query: {legal_players}')
|
||||
|
||||
if need == 'closer':
|
||||
for query in [PitchingCard.select().join(Player).where(
|
||||
(PitchingCard.player << legal_players) & (PitchingCard.closer_rating >= 3) &
|
||||
@ -610,6 +662,7 @@ async def get_team_rp(
|
||||
all_relievers = sort_pitchers(query)
|
||||
|
||||
if all_relievers is not None:
|
||||
logging.info(f'RP query: {query}')
|
||||
this_player_id = all_relievers.iloc[0].player
|
||||
this_player = model_to_dict(Player.get_by_id(this_player_id), recurse=False)
|
||||
db.close()
|
||||
@ -675,6 +728,8 @@ async def get_team_rp(
|
||||
db.close()
|
||||
return this_player
|
||||
|
||||
raise HTTPException(status_code=400, detail=f'No RP found for Team {team_id}')
|
||||
|
||||
|
||||
@router.get('/{team_id}/season-record/{season}')
|
||||
async def get_team_record(team_id: int, season: int):
|
||||
@ -732,7 +787,7 @@ async def get_team_record(team_id: int, season: int):
|
||||
return standings
|
||||
|
||||
|
||||
@router.get('/{team_id}/buy/players')
|
||||
@router.get('/{team_id}/buy/players', include_in_schema=PRIVATE_IN_SCHEMA)
|
||||
async def team_buy_players(team_id: int, ids: str, ts: str):
|
||||
try:
|
||||
this_team = Team.get_by_id(team_id)
|
||||
@ -814,7 +869,7 @@ async def team_buy_players(team_id: int, ids: str, ts: str):
|
||||
f'Final Wallet: {this_team.wallet}')
|
||||
|
||||
|
||||
@router.get('/{team_id}/buy/pack/{packtype_id}')
|
||||
@router.get('/{team_id}/buy/pack/{packtype_id}', include_in_schema=PRIVATE_IN_SCHEMA)
|
||||
async def team_buy_packs(team_id: int, packtype_id: int, ts: str, quantity: Optional[int] = 1):
|
||||
try:
|
||||
this_packtype = PackType.get_by_id(packtype_id)
|
||||
@ -872,7 +927,7 @@ async def team_buy_packs(team_id: int, packtype_id: int, ts: str, quantity: Opti
|
||||
)
|
||||
|
||||
|
||||
@router.get('/{team_id}/sell/cards')
|
||||
@router.get('/{team_id}/sell/cards', include_in_schema=PRIVATE_IN_SCHEMA)
|
||||
async def team_sell_cards(team_id: int, ids: str, ts: str):
|
||||
try:
|
||||
this_team = Team.get_by_id(team_id)
|
||||
@ -997,7 +1052,7 @@ async def get_team_cards(team_id, csv: Optional[bool] = True):
|
||||
return Response(content=pd.DataFrame(output).to_csv(index=False), media_type='text/csv')
|
||||
|
||||
|
||||
@router.post('')
|
||||
@router.post('', include_in_schema=PRIVATE_IN_SCHEMA)
|
||||
async def post_team(team: TeamModel, token: str = Depends(oauth2_scheme)):
|
||||
if not valid_token(token):
|
||||
logging.warning(f'Bad Token: {token}')
|
||||
@ -1040,7 +1095,7 @@ async def post_team(team: TeamModel, token: str = Depends(oauth2_scheme)):
|
||||
raise HTTPException(status_code=418, detail='Well slap my ass and call me a teapot; I could not save that team')
|
||||
|
||||
|
||||
@router.post('/new-season/{new_season}')
|
||||
@router.post('/new-season/{new_season}', include_in_schema=PRIVATE_IN_SCHEMA)
|
||||
async def team_season_update(new_season: int, token: str = Depends(oauth2_scheme)):
|
||||
if not valid_token(token):
|
||||
logging.warning(f'Bad Token: {token}')
|
||||
@ -1059,7 +1114,7 @@ async def team_season_update(new_season: int, token: str = Depends(oauth2_scheme
|
||||
return {'detail': f'Team rankings, season, guides, and wallets updated for season {new_season}'}
|
||||
|
||||
|
||||
@router.post('/{team_id}/money/{delta}')
|
||||
@router.post('/{team_id}/money/{delta}', include_in_schema=PRIVATE_IN_SCHEMA)
|
||||
async def team_update_money(team_id: int, delta: int, token: str = Depends(oauth2_scheme)):
|
||||
if not valid_token(token):
|
||||
logging.warning(f'Bad Token: {token}')
|
||||
@ -1085,7 +1140,7 @@ async def team_update_money(team_id: int, delta: int, token: str = Depends(oauth
|
||||
raise HTTPException(status_code=418, detail='Well slap my ass and call me a teapot; I could not save that team')
|
||||
|
||||
|
||||
@router.patch('/{team_id}')
|
||||
@router.patch('/{team_id}', include_in_schema=PRIVATE_IN_SCHEMA)
|
||||
async def patch_team(
|
||||
team_id, sname: Optional[str] = None, lname: Optional[str] = None, gmid: Optional[int] = None,
|
||||
gmname: Optional[str] = None, gsheet: Optional[str] = None, team_value: Optional[int] = None,
|
||||
@ -1153,7 +1208,7 @@ async def patch_team(
|
||||
raise HTTPException(status_code=418, detail='Well slap my ass and call me a teapot; I could not save that team')
|
||||
|
||||
|
||||
@router.delete('/{team_id}')
|
||||
@router.delete('/{team_id}', include_in_schema=PRIVATE_IN_SCHEMA)
|
||||
async def delete_team(team_id, token: str = Depends(oauth2_scheme)):
|
||||
if not valid_token(token):
|
||||
logging.warning(f'Bad Token: {token}')
|
||||
|
||||
Loading…
Reference in New Issue
Block a user