Spaces:
Running
Running
#initial imports | |
import streamlit as st | |
st.set_page_config(layout="wide") | |
import numpy as np | |
import pandas as pd | |
import time | |
from fuzzywuzzy import process | |
# Bring in numpy reqs | |
from numpy import nan as np_nan | |
from numpy import where as np_where | |
from numpy import random as np_random | |
from numpy import zeros as np_zeros | |
from numpy import array as np_array | |
from pandas import concat as pd_concat | |
from pandas import merge as pd_merge | |
from pandas import DataFrame | |
#bring in functions | |
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() | |
with st.sidebar: | |
site_var_sb = st.selectbox("Select Site", ["Draftkings", "Fanduel"]) | |
distribution_type_sb = st.selectbox("Select Distribution Type", ['normal', 'poisson', 'bimodal']) | |
st.info("The distribution type will determine the shape of the distribution of the ROO values. The normal distribution is for more linear projections, the poisson distribution is for stats like HRs and other counting stats, and the bimodal distribution is useful for event oriented outcomes frequent in MMA.") | |
floor_var_sb = st.number_input("Floor (low end multiplier)", min_value=0.00, max_value=.50, value=.25, step=.01) | |
ceiling_var_sb = st.number_input("Ceiling (high end multiplier)", min_value=1.50, max_value=3.00, value=2.00, step=.01) | |
std_var_sb = st.number_input("Standard Deviation (variance within distribution)", min_value=1.00, max_value=5.00, value=4.00, step=.01) | |
if projections_file: | |
if st.button('Build ROO'): | |
if sport_var == "NBA": | |
if site_var_sb == "Draftkings": | |
disp_file = DK_NBA_ROO_Build(projections, floor_var_sb, ceiling_var_sb, std_var_sb, distribution_type_sb) | |
elif site_var_sb == "Fanduel": | |
disp_file = FD_NBA_ROO_Build(projections, floor_var_sb, ceiling_var_sb, std_var_sb, distribution_type_sb) | |
elif sport_var == "NFL": | |
if site_var_sb == "Draftkings": | |
disp_file = DK_NFL_ROO_Build(projections, floor_var_sb, ceiling_var_sb, std_var_sb, distribution_type_sb) | |
elif site_var_sb == "Fanduel": | |
disp_file = FD_NFL_ROO_Build(projections, floor_var_sb, ceiling_var_sb, std_var_sb, distribution_type_sb) | |
elif sport_var == "MLB": | |
if site_var_sb == "Draftkings": | |
disp_file = DK_MLB_ROO_Build(projections, floor_var_sb, ceiling_var_sb, std_var_sb, distribution_type_sb) | |
elif site_var_sb == "Fanduel": | |
disp_file = FD_MLB_ROO_Build(projections, floor_var_sb, ceiling_var_sb, std_var_sb, distribution_type_sb) | |
if disp_file is not None: | |
st.dataframe(disp_file.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), height=1000, use_container_width = True) | |