File size: 4,218 Bytes
ba104a9
8c22e49
 
 
 
 
 
ba104a9
 
 
 
 
 
 
 
 
 
 
 
89881fc
8c22e49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0cd4d7f
8c22e49
0cd4d7f
 
 
 
 
 
8c22e49
 
 
 
 
 
 
 
0cd4d7f
 
 
 
 
 
8c22e49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89881fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ba104a9
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#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()
    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)