feat: add limit/pagination to battingcardratings endpoint (#135)
Closes #135 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
6a217f97ee
commit
dc88b1539c
@ -145,6 +145,7 @@ async def get_card_ratings(
|
|||||||
vs_hand: Literal["R", "L", "vR", "vL"] = None,
|
vs_hand: Literal["R", "L", "vR", "vL"] = None,
|
||||||
short_output: bool = False,
|
short_output: bool = False,
|
||||||
csv: bool = False,
|
csv: bool = False,
|
||||||
|
limit: int = 100,
|
||||||
):
|
):
|
||||||
this_team = Team.get_or_none(Team.id == team_id)
|
this_team = Team.get_or_none(Team.id == team_id)
|
||||||
logging.debug(f"Team: {this_team} / has_guide: {this_team.has_guide}")
|
logging.debug(f"Team: {this_team} / has_guide: {this_team.has_guide}")
|
||||||
@ -178,6 +179,8 @@ async def get_card_ratings(
|
|||||||
)
|
)
|
||||||
all_ratings = all_ratings.where(BattingCardRatings.battingcard << set_cards)
|
all_ratings = all_ratings.where(BattingCardRatings.battingcard << set_cards)
|
||||||
|
|
||||||
|
all_ratings = all_ratings.limit(max(0, min(limit, 500)))
|
||||||
|
|
||||||
if csv:
|
if csv:
|
||||||
# return_val = query_to_csv(all_ratings)
|
# return_val = query_to_csv(all_ratings)
|
||||||
return_vals = [model_to_dict(x) for x in all_ratings]
|
return_vals = [model_to_dict(x) for x in all_ratings]
|
||||||
@ -281,7 +284,7 @@ def get_scouting_dfs(cardset_id: list = None):
|
|||||||
)
|
)
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
name=f"Arm OF",
|
name="Arm OF",
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
series_list.append(
|
series_list.append(
|
||||||
@ -292,7 +295,7 @@ def get_scouting_dfs(cardset_id: list = None):
|
|||||||
for x in positions.where(CardPosition.position == "C")
|
for x in positions.where(CardPosition.position == "C")
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
name=f"Arm C",
|
name="Arm C",
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
series_list.append(
|
series_list.append(
|
||||||
@ -303,7 +306,7 @@ def get_scouting_dfs(cardset_id: list = None):
|
|||||||
for x in positions.where(CardPosition.position == "C")
|
for x in positions.where(CardPosition.position == "C")
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
name=f"PB C",
|
name="PB C",
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
series_list.append(
|
series_list.append(
|
||||||
@ -314,7 +317,7 @@ def get_scouting_dfs(cardset_id: list = None):
|
|||||||
for x in positions.where(CardPosition.position == "C")
|
for x in positions.where(CardPosition.position == "C")
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
name=f"Throw C",
|
name="Throw C",
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
logging.debug(f"series_list: {series_list}")
|
logging.debug(f"series_list: {series_list}")
|
||||||
@ -334,9 +337,9 @@ async def get_card_scouting(team_id: int, ts: str):
|
|||||||
"https://ko-fi.com/manticorum/shop"
|
"https://ko-fi.com/manticorum/shop"
|
||||||
)
|
)
|
||||||
|
|
||||||
if os.path.isfile(f"storage/batting-ratings.csv"):
|
if os.path.isfile("storage/batting-ratings.csv"):
|
||||||
return FileResponse(
|
return FileResponse(
|
||||||
path=f"storage/batting-ratings.csv",
|
path="storage/batting-ratings.csv",
|
||||||
media_type="text/csv",
|
media_type="text/csv",
|
||||||
# headers=headers
|
# headers=headers
|
||||||
)
|
)
|
||||||
@ -354,7 +357,7 @@ async def post_calc_scouting(token: str = Depends(oauth2_scheme)):
|
|||||||
status_code=401, detail="You are not authorized to calculate card ratings."
|
status_code=401, detail="You are not authorized to calculate card ratings."
|
||||||
)
|
)
|
||||||
|
|
||||||
logging.warning(f"Re-calculating batting ratings\n\n")
|
logging.warning("Re-calculating batting ratings\n\n")
|
||||||
|
|
||||||
output = get_scouting_dfs()
|
output = get_scouting_dfs()
|
||||||
first = ["player_id", "player_name", "cardset_name", "rarity", "hand", "variant"]
|
first = ["player_id", "player_name", "cardset_name", "rarity", "hand", "variant"]
|
||||||
@ -370,9 +373,9 @@ async def post_calc_scouting(token: str = Depends(oauth2_scheme)):
|
|||||||
|
|
||||||
@router.get("/basic")
|
@router.get("/basic")
|
||||||
async def get_basic_scouting(cardset_id: list = Query(default=None)):
|
async def get_basic_scouting(cardset_id: list = Query(default=None)):
|
||||||
if os.path.isfile(f"storage/batting-basic.csv"):
|
if os.path.isfile("storage/batting-basic.csv"):
|
||||||
return FileResponse(
|
return FileResponse(
|
||||||
path=f"storage/batting-basic.csv",
|
path="storage/batting-basic.csv",
|
||||||
media_type="text/csv",
|
media_type="text/csv",
|
||||||
# headers=headers
|
# headers=headers
|
||||||
)
|
)
|
||||||
@ -390,7 +393,7 @@ async def post_calc_basic(token: str = Depends(oauth2_scheme)):
|
|||||||
status_code=401, detail="You are not authorized to calculate basic ratings."
|
status_code=401, detail="You are not authorized to calculate basic ratings."
|
||||||
)
|
)
|
||||||
|
|
||||||
logging.warning(f"Re-calculating basic batting ratings\n\n")
|
logging.warning("Re-calculating basic batting ratings\n\n")
|
||||||
|
|
||||||
raw_data = get_scouting_dfs()
|
raw_data = get_scouting_dfs()
|
||||||
logging.debug(f"output: {raw_data}")
|
logging.debug(f"output: {raw_data}")
|
||||||
@ -667,9 +670,11 @@ async def get_player_ratings(
|
|||||||
if variant is not None:
|
if variant is not None:
|
||||||
all_cards = all_cards.where(BattingCard.variant << variant)
|
all_cards = all_cards.where(BattingCard.variant << variant)
|
||||||
|
|
||||||
all_ratings = BattingCardRatings.select().where(
|
all_ratings = (
|
||||||
BattingCardRatings.battingcard << all_cards
|
BattingCardRatings.select()
|
||||||
).order_by(BattingCardRatings.id)
|
.where(BattingCardRatings.battingcard << all_cards)
|
||||||
|
.order_by(BattingCardRatings.id)
|
||||||
|
)
|
||||||
|
|
||||||
return_val = {
|
return_val = {
|
||||||
"count": all_ratings.count(),
|
"count": all_ratings.count(),
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user