Merge pull request 'fix: batch-fetch PitchingCardRatings instead of per-row queries (#19)' (#44) from ai/paper-dynasty-database#19 into next-release
Reviewed-on: #44
This commit is contained in:
commit
e7c8b59201
@ -279,7 +279,6 @@ def get_scouting_dfs(allowed_players, position: str):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def get_total_ops(df_data):
|
def get_total_ops(df_data):
|
||||||
ops_vl = df_data["obp_vl"] + df_data["slg_vl"]
|
ops_vl = df_data["obp_vl"] + df_data["slg_vl"]
|
||||||
ops_vr = df_data["obp_vr"] + df_data["slg_vr"]
|
ops_vr = df_data["obp_vr"] + df_data["slg_vr"]
|
||||||
@ -587,15 +586,18 @@ def sort_pitchers(pitching_card_query) -> DataFrame | None:
|
|||||||
pitcher_df = pd.DataFrame(all_s).set_index("player", drop=False)
|
pitcher_df = pd.DataFrame(all_s).set_index("player", drop=False)
|
||||||
logging.debug(f"pitcher_df: {pitcher_df}")
|
logging.debug(f"pitcher_df: {pitcher_df}")
|
||||||
|
|
||||||
|
card_ids = pitcher_df["id"].tolist()
|
||||||
|
ratings_map = {
|
||||||
|
(r.pitchingcard_id, r.vs_hand): r
|
||||||
|
for r in PitchingCardRatings.select().where(
|
||||||
|
(PitchingCardRatings.pitchingcard_id << card_ids)
|
||||||
|
& (PitchingCardRatings.vs_hand << ["L", "R"])
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
def get_total_ops(df_data):
|
def get_total_ops(df_data):
|
||||||
vlval = PitchingCardRatings.get_or_none(
|
vlval = ratings_map.get((df_data["id"], "L"))
|
||||||
PitchingCardRatings.pitchingcard_id == df_data["id"],
|
vrval = ratings_map.get((df_data["id"], "R"))
|
||||||
PitchingCardRatings.vs_hand == "L",
|
|
||||||
)
|
|
||||||
vrval = PitchingCardRatings.get_or_none(
|
|
||||||
PitchingCardRatings.pitchingcard_id == df_data["id"],
|
|
||||||
PitchingCardRatings.vs_hand == "R",
|
|
||||||
)
|
|
||||||
|
|
||||||
ops_vl = vlval.obp + vlval.slg
|
ops_vl = vlval.obp + vlval.slg
|
||||||
ops_vr = vrval.obp + vrval.slg
|
ops_vr = vrval.obp + vrval.slg
|
||||||
@ -664,15 +666,18 @@ async def get_team_sp(
|
|||||||
starter_df = pd.DataFrame(all_s).set_index("player", drop=False)
|
starter_df = pd.DataFrame(all_s).set_index("player", drop=False)
|
||||||
logging.debug(f"starter_df: {starter_df}")
|
logging.debug(f"starter_df: {starter_df}")
|
||||||
|
|
||||||
|
card_ids = starter_df["id"].tolist()
|
||||||
|
ratings_map = {
|
||||||
|
(r.pitchingcard_id, r.vs_hand): r
|
||||||
|
for r in PitchingCardRatings.select().where(
|
||||||
|
(PitchingCardRatings.pitchingcard_id << card_ids)
|
||||||
|
& (PitchingCardRatings.vs_hand << ["L", "R"])
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
def get_total_ops(df_data):
|
def get_total_ops(df_data):
|
||||||
vlval = PitchingCardRatings.get_or_none(
|
vlval = ratings_map.get((df_data["id"], "L"))
|
||||||
PitchingCardRatings.pitchingcard_id == df_data["id"],
|
vrval = ratings_map.get((df_data["id"], "R"))
|
||||||
PitchingCardRatings.vs_hand == "L",
|
|
||||||
)
|
|
||||||
vrval = PitchingCardRatings.get_or_none(
|
|
||||||
PitchingCardRatings.pitchingcard_id == df_data["id"],
|
|
||||||
PitchingCardRatings.vs_hand == "R",
|
|
||||||
)
|
|
||||||
|
|
||||||
ops_vl = vlval.obp + vlval.slg
|
ops_vl = vlval.obp + vlval.slg
|
||||||
ops_vr = vrval.obp + vrval.slg
|
ops_vr = vrval.obp + vrval.slg
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user