James McCool
commited on
Commit
·
d09a5ca
1
Parent(s):
c11ed09
Enhance position management in Streamlit app by implementing position limits for DraftKings and FanDuel. Update styling for tabs and add functionality to validate player combinations based on eligible positions. Refactor position selection logic for improved user experience.
Browse files
app.py
CHANGED
@@ -36,7 +36,7 @@ st.markdown("""
|
|
36 |
.stTabs [data-baseweb="tab"] {
|
37 |
height: 50px;
|
38 |
white-space: pre-wrap;
|
39 |
-
background-color: #
|
40 |
color: white;
|
41 |
border-radius: 10px;
|
42 |
gap: 1px;
|
@@ -46,12 +46,20 @@ st.markdown("""
|
|
46 |
}
|
47 |
.stTabs [aria-selected="true"] {
|
48 |
background-color: #DAA520;
|
|
|
49 |
color: white;
|
50 |
}
|
51 |
.stTabs [data-baseweb="tab"]:hover {
|
52 |
-
background-color: #
|
53 |
cursor: pointer;
|
54 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
</style>""", unsafe_allow_html=True)
|
56 |
|
57 |
@st.cache_resource(ttl = 60)
|
@@ -105,7 +113,7 @@ with col1:
|
|
105 |
team_var2 = raw_baselines.Team.unique().tolist()
|
106 |
pos_split2 = st.radio("Are you viewing all positions, specific groups, or specific positions?", ('All Positions', 'Specific Positions'), key='pos_split2')
|
107 |
if pos_split2 == 'Specific Positions':
|
108 |
-
pos_var2 = st.multiselect('What Positions would you like to view?', options = ['
|
109 |
elif pos_split2 == 'All Positions':
|
110 |
pos_var2 = 'All'
|
111 |
if site_var1 == 'Draftkings':
|
@@ -126,6 +134,30 @@ with col1:
|
|
126 |
cost_dict = dict(zip(raw_baselines.Player, raw_baselines.Salary))
|
127 |
|
128 |
with col2:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
stack_hold_container = st.empty()
|
130 |
comb_list = []
|
131 |
if pos_split2 == 'All Positions':
|
@@ -133,6 +165,41 @@ with col2:
|
|
133 |
elif pos_split2 != 'All Positions':
|
134 |
raw_baselines = raw_baselines[raw_baselines['Position'].str.contains('|'.join(pos_var2))]
|
135 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
for cur_team in team_var2:
|
137 |
working_baselines = raw_baselines
|
138 |
working_baselines = working_baselines[working_baselines['Team'] == cur_team]
|
@@ -142,8 +209,10 @@ with col2:
|
|
142 |
|
143 |
comb = combinations(order_list, stack_size)
|
144 |
|
|
|
145 |
for i in list(comb):
|
146 |
-
|
|
|
147 |
|
148 |
comb_DF = pd.DataFrame(comb_list)
|
149 |
|
|
|
36 |
.stTabs [data-baseweb="tab"] {
|
37 |
height: 50px;
|
38 |
white-space: pre-wrap;
|
39 |
+
background-color: #DAA520;
|
40 |
color: white;
|
41 |
border-radius: 10px;
|
42 |
gap: 1px;
|
|
|
46 |
}
|
47 |
.stTabs [aria-selected="true"] {
|
48 |
background-color: #DAA520;
|
49 |
+
border: 3px solid #FFD700;
|
50 |
color: white;
|
51 |
}
|
52 |
.stTabs [data-baseweb="tab"]:hover {
|
53 |
+
background-color: #FFD700;
|
54 |
cursor: pointer;
|
55 |
}
|
56 |
+
div[data-baseweb="select"] > div {
|
57 |
+
background-color: #DAA520;
|
58 |
+
color: white;
|
59 |
+
}
|
60 |
+
div{
|
61 |
+
box-sizing: content-box !important;
|
62 |
+
}
|
63 |
</style>""", unsafe_allow_html=True)
|
64 |
|
65 |
@st.cache_resource(ttl = 60)
|
|
|
113 |
team_var2 = raw_baselines.Team.unique().tolist()
|
114 |
pos_split2 = st.radio("Are you viewing all positions, specific groups, or specific positions?", ('All Positions', 'Specific Positions'), key='pos_split2')
|
115 |
if pos_split2 == 'Specific Positions':
|
116 |
+
pos_var2 = st.multiselect('What Positions would you like to view?', options = ['C', '1B', '2B', '3B', 'SS', 'OF'])
|
117 |
elif pos_split2 == 'All Positions':
|
118 |
pos_var2 = 'All'
|
119 |
if site_var1 == 'Draftkings':
|
|
|
134 |
cost_dict = dict(zip(raw_baselines.Player, raw_baselines.Salary))
|
135 |
|
136 |
with col2:
|
137 |
+
|
138 |
+
if site_var1 == 'Draftkings':
|
139 |
+
position_limits = {
|
140 |
+
'C': 1,
|
141 |
+
'1B': 1,
|
142 |
+
'2B': 1,
|
143 |
+
'3B': 1,
|
144 |
+
'SS': 1,
|
145 |
+
'OF': 3,
|
146 |
+
# Add more as needed
|
147 |
+
}
|
148 |
+
max_salary = 50000
|
149 |
+
max_players = 10
|
150 |
+
else:
|
151 |
+
position_limits = {
|
152 |
+
'C_1B': 1,
|
153 |
+
'2B': 1,
|
154 |
+
'3B': 1,
|
155 |
+
'SS': 1,
|
156 |
+
'OF': 3,
|
157 |
+
'UTIL': 1,
|
158 |
+
# Add more as needed
|
159 |
+
}
|
160 |
+
|
161 |
stack_hold_container = st.empty()
|
162 |
comb_list = []
|
163 |
if pos_split2 == 'All Positions':
|
|
|
165 |
elif pos_split2 != 'All Positions':
|
166 |
raw_baselines = raw_baselines[raw_baselines['Position'].str.contains('|'.join(pos_var2))]
|
167 |
|
168 |
+
# Create a position dictionary mapping players to their eligible positions
|
169 |
+
pos_dict = dict(zip(raw_baselines.Player, raw_baselines.Position))
|
170 |
+
|
171 |
+
def is_valid_combination(combo):
|
172 |
+
# Count positions in this combination
|
173 |
+
position_counts = {pos: 0 for pos in position_limits.keys()}
|
174 |
+
|
175 |
+
# For each player in the combination
|
176 |
+
for player in combo:
|
177 |
+
# Get their eligible positions
|
178 |
+
player_positions = pos_dict[player].split('/')
|
179 |
+
|
180 |
+
# For each position they can play
|
181 |
+
for pos in player_positions:
|
182 |
+
# Handle special cases for FanDuel
|
183 |
+
if site_var1 == 'Fanduel':
|
184 |
+
if pos in ['C', '1B']:
|
185 |
+
position_counts['C_1B'] += 1
|
186 |
+
elif pos == 'UTIL':
|
187 |
+
# UTIL can be filled by any position
|
188 |
+
for p in position_counts:
|
189 |
+
position_counts[p] += 1
|
190 |
+
else: # DraftKings
|
191 |
+
if pos in position_counts:
|
192 |
+
position_counts[pos] += 1
|
193 |
+
|
194 |
+
# Check if any position exceeds its limit
|
195 |
+
for pos, limit in position_limits.items():
|
196 |
+
if position_counts[pos] > limit:
|
197 |
+
return False
|
198 |
+
|
199 |
+
return True
|
200 |
+
|
201 |
+
# Modify the combination generation code
|
202 |
+
comb_list = []
|
203 |
for cur_team in team_var2:
|
204 |
working_baselines = raw_baselines
|
205 |
working_baselines = working_baselines[working_baselines['Team'] == cur_team]
|
|
|
209 |
|
210 |
comb = combinations(order_list, stack_size)
|
211 |
|
212 |
+
# Only add combinations that satisfy position limits
|
213 |
for i in list(comb):
|
214 |
+
if is_valid_combination(i):
|
215 |
+
comb_list.append(i)
|
216 |
|
217 |
comb_DF = pd.DataFrame(comb_list)
|
218 |
|