Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,6 +8,7 @@ for name in dir():
|
|
| 8 |
import pulp
|
| 9 |
import numpy as np
|
| 10 |
import pandas as pd
|
|
|
|
| 11 |
import streamlit as st
|
| 12 |
import gspread
|
| 13 |
import time
|
|
@@ -174,42 +175,42 @@ def create_stack_options(player_data, wr_var):
|
|
| 174 |
|
| 175 |
return correl_dict
|
| 176 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
def create_overall_dfs(pos_players, table_name, dict_name, pos):
|
| 178 |
if pos == "FLEX":
|
| 179 |
-
pos_players = pos_players.
|
| 180 |
-
|
| 181 |
-
overall_table_name =
|
| 182 |
-
|
| 183 |
-
overall_dict_name = pd.Series(overall_table_name.Player.values, index=overall_table_name.Var).to_dict()
|
| 184 |
|
| 185 |
del pos_players
|
| 186 |
-
del table_name_raw
|
| 187 |
elif pos != "FLEX":
|
| 188 |
-
table_name_raw = pos_players
|
| 189 |
-
overall_table_name = table_name_raw.
|
| 190 |
-
overall_table_name = overall_table_name.
|
| 191 |
-
overall_dict_name =
|
| 192 |
|
| 193 |
del pos_players
|
| 194 |
-
del table_name_raw
|
| 195 |
|
| 196 |
return overall_table_name, overall_dict_name
|
| 197 |
|
| 198 |
|
| 199 |
def get_overall_merged_df():
|
| 200 |
ref_dict = {
|
| 201 |
-
'pos':['RB', 'WR', 'TE', 'FLEX'],
|
| 202 |
-
'pos_dfs':['RB_Table', 'WR_Table', 'TE_Table', 'FLEX_Table'],
|
| 203 |
-
'pos_dicts':['rb_dict', 'wr_dict', 'te_dict', 'flex_dict']
|
| 204 |
-
|
| 205 |
|
| 206 |
-
for i in range(0,4):
|
| 207 |
-
ref_dict['pos_dfs'][i], ref_dict['pos_dicts'][i]
|
| 208 |
create_overall_dfs(pos_players, ref_dict['pos_dfs'][i], ref_dict['pos_dicts'][i], ref_dict['pos'][i])
|
| 209 |
-
|
| 210 |
-
df_out = pd.concat(ref_dict['pos_dfs'], ignore_index=True)
|
| 211 |
|
| 212 |
-
|
|
|
|
| 213 |
|
| 214 |
def calculate_range_var(count, min_val, FieldStrength, field_growth):
|
| 215 |
var = round(len(count[0]) * FieldStrength)
|
|
|
|
| 8 |
import pulp
|
| 9 |
import numpy as np
|
| 10 |
import pandas as pd
|
| 11 |
+
import polars as pl
|
| 12 |
import streamlit as st
|
| 13 |
import gspread
|
| 14 |
import time
|
|
|
|
| 175 |
|
| 176 |
return correl_dict
|
| 177 |
|
| 178 |
+
@st.cache_data
|
| 179 |
+
def apply_range(s: pl.Series) -> pl.Series:
|
| 180 |
+
return pl.Series("Var", list(range(s.len())))
|
| 181 |
+
|
| 182 |
def create_overall_dfs(pos_players, table_name, dict_name, pos):
|
| 183 |
if pos == "FLEX":
|
| 184 |
+
pos_players = pos_players.sort("Value", reverse=True)
|
| 185 |
+
overall_table_name = pos_players.slice(0, round(pos_players.shape[0]))
|
| 186 |
+
overall_table_name = overall_table_name.with_column(pl.col("Var").apply_range())
|
| 187 |
+
overall_dict_name = {row[0]: row[1] for row in overall_table_name.select(["Var", "Player"]).collect()}
|
|
|
|
| 188 |
|
| 189 |
del pos_players
|
|
|
|
| 190 |
elif pos != "FLEX":
|
| 191 |
+
table_name_raw = pos_players.filter(pl.col("Position").str_contains(pos))
|
| 192 |
+
overall_table_name = table_name_raw.slice(0, round(table_name_raw.shape[0]))
|
| 193 |
+
overall_table_name = overall_table_name.with_column(pl.col("Var").apply_range())
|
| 194 |
+
overall_dict_name = {row[0]: row[1] for row in overall_table_name.select(["Var", "Player"]).collect()}
|
| 195 |
|
| 196 |
del pos_players
|
|
|
|
| 197 |
|
| 198 |
return overall_table_name, overall_dict_name
|
| 199 |
|
| 200 |
|
| 201 |
def get_overall_merged_df():
|
| 202 |
ref_dict = {
|
| 203 |
+
'pos': ['RB', 'WR', 'TE', 'FLEX'],
|
| 204 |
+
'pos_dfs': ['RB_Table', 'WR_Table', 'TE_Table', 'FLEX_Table'],
|
| 205 |
+
'pos_dicts': ['rb_dict', 'wr_dict', 'te_dict', 'flex_dict']
|
| 206 |
+
}
|
| 207 |
|
| 208 |
+
for i in range(0, 4):
|
| 209 |
+
ref_dict['pos_dfs'][i], ref_dict['pos_dicts'][i] = \
|
| 210 |
create_overall_dfs(pos_players, ref_dict['pos_dfs'][i], ref_dict['pos_dicts'][i], ref_dict['pos'][i])
|
|
|
|
|
|
|
| 211 |
|
| 212 |
+
# Assuming ref_dict['pos_dfs'] is a list of polars.Dataframe
|
| 213 |
+
df_out = pl.concat(ref_dict['pos_dfs'], rechunk=True)
|
| 214 |
|
| 215 |
def calculate_range_var(count, min_val, FieldStrength, field_growth):
|
| 216 |
var = round(len(count[0]) * FieldStrength)
|