James McCool
commited on
Commit
·
440bba8
1
Parent(s):
48da594
Refactor load_contest_file function to include contest type parameter for improved data handling
Browse files- Updated the load_contest_file function to accept a new 'type' parameter, allowing for differentiated processing of 'Classic' and 'Showdown' contest types.
- Adjusted the logic for cleaning and structuring lineups based on the contest type, enhancing the flexibility and clarity of data handling.
- Maintained existing functionality while improving the organization and readability of contest data processing in both app.py and load_contest_file.py.
- app.py +1 -1
- global_func/load_contest_file.py +36 -25
app.py
CHANGED
@@ -124,7 +124,7 @@ with tab1:
|
|
124 |
pass
|
125 |
|
126 |
if 'Contest_file' in st.session_state:
|
127 |
-
st.session_state['Contest'], st.session_state['ownership_df'], st.session_state['actual_df'], st.session_state['entry_list'], check_lineups = load_contest_file(st.session_state['Contest_file'], st.session_state['player_info'], sport_select)
|
128 |
st.session_state['Contest'] = st.session_state['Contest'].dropna(how='all')
|
129 |
st.session_state['Contest'] = st.session_state['Contest'].reset_index(drop=True)
|
130 |
if st.session_state['Contest'] is not None:
|
|
|
124 |
pass
|
125 |
|
126 |
if 'Contest_file' in st.session_state:
|
127 |
+
st.session_state['Contest'], st.session_state['ownership_df'], st.session_state['actual_df'], st.session_state['entry_list'], check_lineups = load_contest_file(st.session_state['Contest_file'], type_var, st.session_state['player_info'], sport_select)
|
128 |
st.session_state['Contest'] = st.session_state['Contest'].dropna(how='all')
|
129 |
st.session_state['Contest'] = st.session_state['Contest'].reset_index(drop=True)
|
130 |
if st.session_state['Contest'] is not None:
|
global_func/load_contest_file.py
CHANGED
@@ -2,7 +2,7 @@ import streamlit as st
|
|
2 |
import pandas as pd
|
3 |
from rapidfuzz import process, fuzz
|
4 |
|
5 |
-
def load_contest_file(upload, helper = None, sport = None):
|
6 |
if upload is not None:
|
7 |
try:
|
8 |
try:
|
@@ -101,30 +101,41 @@ def load_contest_file(upload, helper = None, sport = None):
|
|
101 |
|
102 |
# Create the cleaned dataframe with just the essential columns
|
103 |
cleaned_df = df[['BaseName', 'Lineup']]
|
104 |
-
if
|
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 |
print('Made it through check_lineups')
|
130 |
|
|
|
2 |
import pandas as pd
|
3 |
from rapidfuzz import process, fuzz
|
4 |
|
5 |
+
def load_contest_file(upload, type, helper = None, sport = None):
|
6 |
if upload is not None:
|
7 |
try:
|
8 |
try:
|
|
|
101 |
|
102 |
# Create the cleaned dataframe with just the essential columns
|
103 |
cleaned_df = df[['BaseName', 'Lineup']]
|
104 |
+
if type == 'Classic':
|
105 |
+
if sport == 'MLB':
|
106 |
+
cleaned_df['Lineup'] = cleaned_df['Lineup'].replace([' P ', ' C ', '1B ', ' 2B ', ' 3B ', ' SS ', ' OF '], value=',', regex=True)
|
107 |
+
elif sport == 'MMA':
|
108 |
+
cleaned_df['Lineup'] = cleaned_df['Lineup'].replace([' P ', ' C ', '1B ', ' 2B ', ' 3B ', ' SS ', ' OF ', ' F ', 'F '], value=',', regex=True)
|
109 |
+
elif sport == 'GOLF':
|
110 |
+
cleaned_df['Lineup'] = cleaned_df['Lineup'].replace([' P ', ' C ', '1B ', ' 2B ', ' 3B ', ' SS ', ' OF ', ' G ', 'G '], value=',', regex=True)
|
111 |
+
print(sport)
|
112 |
+
check_lineups = cleaned_df.copy()
|
113 |
+
if sport == 'MLB':
|
114 |
+
cleaned_df[['Remove', '1B', '2B', '3B', 'C', 'OF1', 'OF2', 'OF3', 'P1', 'P2', 'SS']] = cleaned_df['Lineup'].str.split(',', expand=True)
|
115 |
+
elif sport == 'MMA':
|
116 |
+
cleaned_df[['Remove', 'Guy', 'Dude', 'Pooba', 'Bub', 'Chief', 'Buddy']] = cleaned_df['Lineup'].str.split(',', expand=True)
|
117 |
+
elif sport == 'GOLF':
|
118 |
+
cleaned_df[['Remove', 'Guy', 'Dude', 'Pooba', 'Bub', 'Chief', 'Buddy']] = cleaned_df['Lineup'].str.split(',', expand=True)
|
119 |
+
cleaned_df = cleaned_df.drop(columns=['Lineup', 'Remove'])
|
120 |
+
entry_counts = cleaned_df['BaseName'].value_counts()
|
121 |
+
cleaned_df['EntryCount'] = cleaned_df['BaseName'].map(entry_counts)
|
122 |
+
if sport == 'MLB':
|
123 |
+
cleaned_df = cleaned_df[['BaseName', 'EntryCount', 'P1', 'P2', 'C', '1B', '2B', '3B', 'SS', 'OF1', 'OF2', 'OF3']]
|
124 |
+
elif sport == 'MMA':
|
125 |
+
cleaned_df = cleaned_df[['BaseName', 'EntryCount', 'Guy', 'Dude', 'Pooba', 'Bub', 'Chief', 'Buddy']]
|
126 |
+
elif sport == 'GOLF':
|
127 |
+
cleaned_df = cleaned_df[['BaseName', 'EntryCount', 'Guy', 'Dude', 'Pooba', 'Bub', 'Chief', 'Buddy']]
|
128 |
+
st.table(cleaned_df.head(10))
|
129 |
+
elif type == 'Showdown':
|
130 |
+
cleaned_df['Lineup'] = cleaned_df['Lineup'].replace([' UTIL ', 'CPT '], value=',', regex=True)
|
131 |
+
print(type)
|
132 |
+
check_lineups = cleaned_df.copy()
|
133 |
+
cleaned_df[['Remove', 'CPT', 'UTIL', 'UTIL', 'UTIL', 'UTIL', 'UTIL']] = cleaned_df['Lineup'].str.split(',', expand=True)
|
134 |
+
cleaned_df = cleaned_df.drop(columns=['Lineup', 'Remove'])
|
135 |
+
entry_counts = cleaned_df['BaseName'].value_counts()
|
136 |
+
cleaned_df['EntryCount'] = cleaned_df['BaseName'].map(entry_counts)
|
137 |
+
cleaned_df = cleaned_df[['BaseName', 'EntryCount', 'CPT', 'UTIL', 'UTIL', 'UTIL', 'UTIL', 'UTIL']]
|
138 |
+
st.table(cleaned_df.head(10))
|
139 |
|
140 |
print('Made it through check_lineups')
|
141 |
|