Spaces:
Sleeping
Sleeping
File size: 2,880 Bytes
4ab77a1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
import os
import pandas as pd
import streamlit as st
from tenacity import retry
from config import DEFAULT_ICON, LEAGUE_NAME, KEEPER_DATA_URL
from shared_page import common_page_config
from queries.supabase_db.client import get_all_selected_keepers
@st.cache_data(ttl=60 * 60 * 24)
def load_data():
data = pd.read_csv(os.path.join(os.path.dirname(__file__), KEEPER_DATA_URL), index_col=0)
# Hack to get position, replace with better position from yahoo api in future
data["position"] = (
data["eligible_positions"]
.apply(lambda x: x.split(" ")[0])
.str.replace("[", "")
.str.replace("]", "")
.str.replace("'", "")
)
data.columns = data.columns.str.lower()
data.sort_values(["team_name", "keeper_cost"], inplace=True)
teams_list = sorted(list(data["team_name"].unique()))
return data, teams_list
@retry()
def get_selected_keepers_with_retry():
return get_all_selected_keepers()
def get_page():
page_title = f"{LEAGUE_NAME} - Selected Keepers"
st.set_page_config(page_title=page_title, page_icon=DEFAULT_ICON, layout="wide")
common_page_config()
st.title(page_title)
data, _ = load_data()
st.header("Selected Keepers")
selected_keepers = get_selected_keepers_with_retry()
df_selected = pd.DataFrame(selected_keepers)
if len(df_selected):
cols_from_options = [
"player_id",
"headshot_url",
"name",
"position",
"years_eligible",
"team_name",
]
selected_data = data[cols_from_options].merge(df_selected, how="inner", on="player_id")
st.dataframe(
selected_data,
hide_index=True,
height=35 * (len(selected_data) + 1) + 5,
column_order=[
"team_name",
"headshot_url",
"name",
"position",
"keeper_cost",
"years_eligible",
],
column_config={
"team_name": st.column_config.TextColumn(label="Team Name"),
"headshot_url": st.column_config.ImageColumn(label="", help="Player image"),
"name": st.column_config.TextColumn(label="Name", help="Player's name"),
"position": st.column_config.TextColumn(label="Position", help="Player's position"),
"keeper_cost": st.column_config.NumberColumn(
label="Keeper Cost", help="Draft Round Cost to keep player. See Rules for details."
),
"years_eligible": st.column_config.NumberColumn(
label="Years Eligible",
help="Number of further consecutive seasons player can be kept (subject to maximum of 2)",
),
},
)
if __name__ == "__main__":
get_page()
|