File size: 2,044 Bytes
8c22e49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
st.set_page_config(layout="wide")
import numpy as np
import pandas as pd
import time
from fuzzywuzzy import process

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()

    st.subheader("Projections File")
    st.info("upload a projections file that has Data oriented in the following format:")
    
    # 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:
        # Create empty DataFrame with required columns
        template_df = pd.DataFrame(columns=['player_names', 'position', 'team', 'salary', 'median', 'ownership', 'captain ownership'])
        # 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()