File size: 6,827 Bytes
58cea02 d04558f 58cea02 d04558f 58cea02 5db8a23 9e80538 5db8a23 58cea02 5db8a23 58cea02 5db8a23 58cea02 5db8a23 58cea02 5db8a23 58cea02 |
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 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
import streamlit as st
st.set_page_config(layout="wide")
import numpy as np
import pandas as pd
import time
from fuzzywuzzy import process
import random
## import global functions
from global_func.clean_player_name import clean_player_name
from global_func.load_file import load_file
from global_func.load_ss_file import load_ss_file
from global_func.find_name_mismatches import find_name_mismatches
from global_func.predict_dupes import predict_dupes
from global_func.highlight_rows import highlight_changes, highlight_changes_winners, highlight_changes_losers
from global_func.load_csv import load_csv
from global_func.find_csv_mismatches import find_csv_mismatches
tab1, tab2 = st.tabs(["Data Load", "Contest Analysis"])
with tab1:
if st.button('Clear data', key='reset1'):
st.session_state.clear()
# Add file uploaders to your app
col1, col2, col3 = st.columns(3)
with col1:
st.subheader("Draftkings/Fanduel CSV")
st.info("Upload the player pricing CSV from the site you are playing on.")
upload_csv_col, csv_template_col = st.columns([3, 1])
with upload_csv_col:
csv_file = st.file_uploader("Upload CSV File", type=['csv'])
if 'csv_file' in st.session_state:
del st.session_state['csv_file']
with csv_template_col:
csv_template_df = pd.DataFrame(columns=['Name', 'ID', 'Roster Position', 'Salary'])
st.download_button(
label="CSV Template",
data=csv_template_df.to_csv(index=False),
file_name="csv_template.csv",
mime="text/csv"
)
st.session_state['csv_file'] = load_csv(csv_file)
try:
st.session_state['csv_file']['Salary'] = st.session_state['csv_file']['Salary'].astype(str).str.replace(',', '').astype(int)
except:
pass
if csv_file:
st.session_state['csv_file'] = st.session_state['csv_file'].drop_duplicates(subset=['Name'])
st.success('Projections file loaded successfully!')
st.dataframe(st.session_state['csv_file'].head(10))
with col2:
st.subheader("Contest File")
st.info("Go ahead and upload a Contest file here. Only include player columns and an optional 'Stack' column if you are playing MLB.")
Contest_file = st.file_uploader("Upload Contest File (CSV or Excel)", type=['csv', 'xlsx', 'xls'])
if 'Contest' in st.session_state:
del st.session_state['Contest']
if Contest_file:
st.session_state['Contest'], st.session_state['position_dict'], st.session_state['ownership_dict'], st.session_state['entry_list'] = load_file(Contest_file)
st.session_state['Contest'] = st.session_state['Contest'].dropna(how='all')
st.session_state['Contest'] = st.session_state['Contest'].reset_index(drop=True)
if st.session_state['Contest'] is not None:
st.success('Contest file loaded successfully!')
st.dataframe(st.session_state['Contest'].head(10))
with col3:
st.subheader("Projections File")
st.info("upload a projections file that has 'player_names', 'salary', 'median', 'ownership', and 'captain ownership' (Needed for Showdown) columns. Note that the salary for showdown needs to be the FLEX salary, not the captain salary.")
# 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'])
if 'projections_df' in st.session_state:
del st.session_state['projections_df']
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.head(10))
# if Contest_file and projections_file:
# if st.session_state['Contest'] is not None and projections is not None:
# st.subheader("Name Matching Analysis")
# # Initialize projections_df in session state if it doesn't exist
# if 'projections_df' not in st.session_state:
# st.session_state['projections_df'] = projections.copy()
# st.session_state['projections_df']['salary'] = (st.session_state['projections_df']['salary'].astype(str).str.replace(',', '').astype(float).astype(int))
# # Update projections_df with any new matches
# st.session_state['projections_df'] = find_name_mismatches(st.session_state['Contest'], st.session_state['projections_df'])
# if csv_file is not None and 'export_dict' not in st.session_state:
# # Create a dictionary of Name to Name+ID from csv_file
# try:
# name_id_map = dict(zip(
# st.session_state['csv_file']['Name'],
# st.session_state['csv_file']['Name + ID']
# ))
# except:
# name_id_map = dict(zip(
# st.session_state['csv_file']['Nickname'],
# st.session_state['csv_file']['Id']
# ))
# # Function to find best match
# def find_best_match(name):
# best_match = process.extractOne(name, name_id_map.keys())
# if best_match and best_match[1] >= 85: # 85% match threshold
# return name_id_map[best_match[0]]
# return name # Return original name if no good match found
# # Apply the matching
# projections['upload_match'] = projections['player_names'].apply(find_best_match)
# st.session_state['export_dict'] = dict(zip(projections['player_names'], projections['upload_match']))
with tab2:
if st.button('Clear data', key='reset3'):
st.session_state.clear()
|