Spaces:
Running
Running
James McCool
Add ROO (Roster Optimization Output) functionality for NBA with site-specific builds
89881fc
import streamlit as st | |
st.set_page_config(layout="wide") | |
import numpy as np | |
import pandas as pd | |
import time | |
from fuzzywuzzy import process | |
from function_hold.NBA_functions import DK_NBA_ROO_Build, FD_NBA_ROO_Build | |
def load_file(upload): | |
if upload is not None: | |
try: | |
if upload.name.endswith('.csv'): | |
df = pd.read_csv(upload) | |
elif upload.name.endswith(('.xls', '.xlsx')): | |
df = pd.read_excel(upload) | |
else: | |
st.error('Please upload either a CSV or Excel file') | |
return None | |
export_df = df.copy() | |
return export_df, df | |
except Exception as e: | |
st.error(f'Error loading file: {str(e)}') | |
return None | |
return None | |
tab1, tab2 = st.tabs(["Data Load", "Manage Portfolio"]) | |
with tab1: | |
if st.button('Clear data', key='reset1'): | |
st.session_state.clear() | |
sport_var = st.selectbox("Select Sport", ["NBA", "NFL", "MLB"]) | |
st.subheader("Projections File") | |
if sport_var == "NBA": | |
st.info("upload a projections file that has Data oriented in the following format: 'Player', 'Team', 'Opp', 'Position', 'Salary', 'Median', 'Minutes', 'Own'") | |
elif sport_var == "NFL": | |
st.info("upload a projections file that has Data oriented in the following format: 'Player', 'Team', 'Opp', 'Position', 'Salary', 'Median', 'Minutes', 'Own'") | |
elif sport_var == "MLB": | |
st.info("upload a projections file that has Data oriented in the following format: 'Player', 'Team', 'Opp', 'Position', 'Salary', 'Median', 'Minutes', 'Own'") | |
# Create two columns for the uploader and template button | |
upload_col, template_col = st.columns([3, 1]) | |
with upload_col: | |
projections_file = st.file_uploader("Upload Projections File (CSV or Excel)", type=['csv', 'xlsx', 'xls']) | |
with template_col: | |
if sport_var == "NBA": | |
template_df = pd.DataFrame(columns=['Player', 'Team', 'Opp', 'Position', 'Salary', 'Median', 'Minutes', 'Own']) | |
elif sport_var == "NFL": | |
template_df = pd.DataFrame(columns=['Player', 'Team', 'Opp', 'Position', 'Salary', 'Median', 'Minutes', 'Own']) | |
elif sport_var == "MLB": | |
template_df = pd.DataFrame(columns=['Player', 'Team', 'Opp', 'Position', 'Salary', 'Median', 'Minutes', 'Own']) | |
# Add download button for template | |
st.download_button( | |
label="Template", | |
data=template_df.to_csv(index=False), | |
file_name="projections_template.csv", | |
mime="text/csv" | |
) | |
if projections_file: | |
export_projections, projections = load_file(projections_file) | |
if projections is not None: | |
st.success('Projections file loaded successfully!') | |
st.dataframe(projections) | |
with tab2: | |
if st.button('Clear data', key='reset2'): | |
st.session_state.clear() | |
site_var = st.selectbox("Select Site", ["Draftkings", "Fanduel"]) | |
if projections_file: | |
if st.button('Build ROO'): | |
if sport_var == "NBA": | |
if site_var == "Draftkings": | |
disp_file = DK_NBA_ROO_Build(projections) | |
elif site_var == "Fanduel": | |
disp_file = FD_NBA_ROO_Build(projections) | |
elif sport_var == "NFL": | |
if site_var == "Draftkings": | |
disp_file = DK_NFL_ROO_Build(projections) | |
elif site_var == "Fanduel": | |
disp_file = FD_NFL_ROO_Build(projections) | |
elif sport_var == "MLB": | |
if site_var == "Draftkings": | |
disp_file = DK_MLB_ROO_Build(projections) | |
elif site_var == "Fanduel": | |
disp_file = FD_MLB_ROO_Build(projections) | |
st.dataframe(disp_file) | |