James McCool
commited on
Commit
·
d323d4b
1
Parent(s):
ff6fb00
Adding some database support
Browse files- app.py +23 -2
- database.py +16 -0
- database_queries.py +429 -0
- requirements.txt +1 -0
app.py
CHANGED
|
@@ -28,6 +28,20 @@ from global_func.exposure_spread import exposure_spread
|
|
| 28 |
from global_func.reassess_edge import reassess_edge
|
| 29 |
from global_func.recalc_diversity import recalc_diversity
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
freq_format = {'Finish_percentile': '{:.2%}', 'Lineup Edge': '{:.2%}', 'Lineup Edge_Raw': '{:.2%}', 'Win%': '{:.2%}'}
|
| 32 |
stacking_sports = ['MLB', 'NHL', 'NFL', 'LOL', 'NCAAF']
|
| 33 |
stack_column_dict = {
|
|
@@ -545,8 +559,14 @@ if selected_tab == 'Data Load':
|
|
| 545 |
st.subheader("Portfolio File")
|
| 546 |
st.info("Go ahead and upload a portfolio file here. Only include player columns.")
|
| 547 |
|
| 548 |
-
upload_toggle = st.selectbox("What source are you uploading from?", options=['SaberSim (Just IDs)', 'Draftkings/Fanduel (Names + IDs)', 'Other (Just Names)'])
|
| 549 |
-
if upload_toggle == '
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 550 |
portfolio_file = st.file_uploader("Upload Portfolio File (CSV or Excel)", type=['csv', 'xlsx', 'xls'])
|
| 551 |
if 'portfolio' in st.session_state:
|
| 552 |
del st.session_state['portfolio']
|
|
@@ -559,6 +579,7 @@ if selected_tab == 'Data Load':
|
|
| 559 |
del st.session_state['portfolio']
|
| 560 |
if 'export_portfolio' in st.session_state:
|
| 561 |
del st.session_state['export_portfolio']
|
|
|
|
| 562 |
if 'portfolio' not in st.session_state:
|
| 563 |
if portfolio_file:
|
| 564 |
if upload_toggle == 'SaberSim (Just IDs)':
|
|
|
|
| 28 |
from global_func.reassess_edge import reassess_edge
|
| 29 |
from global_func.recalc_diversity import recalc_diversity
|
| 30 |
|
| 31 |
+
from database_queries import *
|
| 32 |
+
from database import *
|
| 33 |
+
|
| 34 |
+
showdown_selections = ['Showdown #1', 'Showdown #2', 'Showdown #3', 'Showdown #4', 'Showdown #5', 'Showdown #6', 'Showdown #7', 'Showdown #8', 'Showdown #9', 'Showdown #10', 'Showdown #11', 'Showdown #12', 'Showdown #13', 'Showdown #14', 'Showdown #15']
|
| 35 |
+
dk_db_nfl_showdown_selections = ['DK_NFL_SD_seed_frame_Showdown #1', 'DK_NFL_SD_seed_frame_Showdown #2', 'DK_NFL_SD_seed_frame_Showdown #3', 'DK_NFL_SD_seed_frame_Showdown #4', 'DK_NFL_SD_seed_frame_Showdown #5', 'DK_NFL_SD_seed_frame_Showdown #6',
|
| 36 |
+
'DK_NFL_SD_seed_frame_Showdown #7', 'DK_NFL_SD_seed_frame_Showdown #8', 'DK_NFL_SD_seed_frame_Showdown #9', 'DK_NFL_SD_seed_frame_Showdown #10', 'DK_NFL_SD_seed_frame_Showdown #11', 'DK_NFL_SD_seed_frame_Showdown #12', 'DK_NFL_SD_seed_frame_Showdown #13',
|
| 37 |
+
'DK_NFL_SD_seed_frame_Showdown #14', 'DK_NFL_SD_seed_frame_Showdown #15']
|
| 38 |
+
fd_db_nfl_showdown_selections = ['FD_NFL_SD_seed_frame_Showdown #1', 'FD_NFL_SD_seed_frame_Showdown #2', 'FD_NFL_SD_seed_frame_Showdown #3', 'FD_NFL_SD_seed_frame_Showdown #4', 'FD_NFL_SD_seed_frame_Showdown #5', 'FD_NFL_SD_seed_frame_Showdown #6',
|
| 39 |
+
'FD_NFL_SD_seed_frame_Showdown #7', 'FD_NFL_SD_seed_frame_Showdown #8', 'FD_NFL_SD_seed_frame_Showdown #9', 'FD_NFL_SD_seed_frame_Showdown #10', 'FD_NFL_SD_seed_frame_Showdown #11', 'FD_NFL_SD_seed_frame_Showdown #12', 'FD_NFL_SD_seed_frame_Showdown #13',
|
| 40 |
+
'FD_NFL_SD_seed_frame_Showdown #14', 'FD_NFL_SD_seed_frame_Showdown #15']
|
| 41 |
+
|
| 42 |
+
dk_nfl_showdown_db_translation = dict(zip(showdown_selections, dk_db_nfl_showdown_selections))
|
| 43 |
+
fd_nfl_showdown_db_translation = dict(zip(showdown_selections, fd_db_nfl_showdown_selections))
|
| 44 |
+
|
| 45 |
freq_format = {'Finish_percentile': '{:.2%}', 'Lineup Edge': '{:.2%}', 'Lineup Edge_Raw': '{:.2%}', 'Win%': '{:.2%}'}
|
| 46 |
stacking_sports = ['MLB', 'NHL', 'NFL', 'LOL', 'NCAAF']
|
| 47 |
stack_column_dict = {
|
|
|
|
| 559 |
st.subheader("Portfolio File")
|
| 560 |
st.info("Go ahead and upload a portfolio file here. Only include player columns.")
|
| 561 |
|
| 562 |
+
upload_toggle = st.selectbox("What source are you uploading from?", options=['Paydirt DB', 'SaberSim (Just IDs)', 'Draftkings/Fanduel (Names + IDs)', 'Other (Just Names)'])
|
| 563 |
+
if upload_toggle == 'Paydirt DB':
|
| 564 |
+
if site_var == 'Draftkings':
|
| 565 |
+
portfolio_file = init_DK_NFL_lineups(type_var, 'Main Slate', 'proj', 50, dk_nfl_showdown_db_translation, 25000, [])
|
| 566 |
+
else:
|
| 567 |
+
portfolio_file = init_FD_NFL_lineups(type_var, 'Main Slate', 'proj', 50, fd_nfl_showdown_db_translation, 25000, [])
|
| 568 |
+
|
| 569 |
+
elif upload_toggle == 'SaberSim (Just IDs)' or upload_toggle == 'Draftkings/Fanduel (Names + IDs)':
|
| 570 |
portfolio_file = st.file_uploader("Upload Portfolio File (CSV or Excel)", type=['csv', 'xlsx', 'xls'])
|
| 571 |
if 'portfolio' in st.session_state:
|
| 572 |
del st.session_state['portfolio']
|
|
|
|
| 579 |
del st.session_state['portfolio']
|
| 580 |
if 'export_portfolio' in st.session_state:
|
| 581 |
del st.session_state['export_portfolio']
|
| 582 |
+
|
| 583 |
if 'portfolio' not in st.session_state:
|
| 584 |
if portfolio_file:
|
| 585 |
if upload_toggle == 'SaberSim (Just IDs)':
|
database.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pymongo
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
@st.cache_resource
|
| 6 |
+
def init_conn():
|
| 7 |
+
# Try to get from environment variable first, fall back to secrets
|
| 8 |
+
uri = os.getenv('MONGO_URI')
|
| 9 |
+
if not uri:
|
| 10 |
+
uri = st.secrets['mongo_uri']
|
| 11 |
+
client = pymongo.MongoClient(uri, retryWrites=True, serverSelectionTimeoutMS=500000)
|
| 12 |
+
nfl_db = client["NFL_Database"]
|
| 13 |
+
|
| 14 |
+
return nfl_db
|
| 15 |
+
|
| 16 |
+
nfl_db = init_conn()
|
database_queries.py
ADDED
|
@@ -0,0 +1,429 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
import numpy as np
|
| 3 |
+
import math
|
| 4 |
+
from database import *
|
| 5 |
+
|
| 6 |
+
# Probably should have done this in a dictionary to start with
|
| 7 |
+
wrong_nfl_team_names = ['Denver Broncos', 'Washington Commanders', 'Cincinnati Bengals', 'Arizona Cardinals', 'Los Angeles Rams', 'Pittsburgh Steelers',
|
| 8 |
+
'Jacksonville Jaguars', 'New England Patriots', 'Tampa Bay Buccaneers', 'San Francisco 49ers', 'Green Bay Packers', 'New York Jets',
|
| 9 |
+
'Indianapolis Colts', 'Miami Dolphins', 'Detroit Lions', 'Las Vegas Raiders', 'Atlanta Falcons', 'Seattle Seahawks', 'Houston Texans',
|
| 10 |
+
'New Orleans Saints', 'Carolina Panthers', 'New York Giants', 'Cleveland Browns', 'Tennessee Titans', 'Philadelphia Eagles', 'Dallas Cowboys',
|
| 11 |
+
'Kansas City Chiefs', 'Los Angeles Chargers', 'Baltimore Ravens', 'Buffalo Bills', 'Minnesota Vikings', 'Chicago Bears']
|
| 12 |
+
right_nfl_name_teams = ['Broncos', 'Commanders', 'Bengals', 'Cardinals', 'Rams', 'Steelers', 'Jaguars', 'Patriots', 'Buccaneers', '49ers', 'Packers',
|
| 13 |
+
'Jets', 'Colts', 'Dolphins', 'Lions', 'Raiders', 'Falcons', 'Seahawks', 'Texans', 'Saints', 'Panthers', 'Giants', 'Browns', 'Titans', 'Eagles', 'Cowboys',
|
| 14 |
+
'Chiefs', 'Chargers', 'Ravens', 'Bills', 'Vikings', 'Bears']
|
| 15 |
+
|
| 16 |
+
def init_nfl_baselines(type_var: str):
|
| 17 |
+
|
| 18 |
+
if type_var == 'Regular':
|
| 19 |
+
collection = nfl_db["DK_NFL_ROO"]
|
| 20 |
+
cursor = collection.find()
|
| 21 |
+
|
| 22 |
+
raw_display = pd.DataFrame(list(cursor))
|
| 23 |
+
raw_display = raw_display.rename(columns={'player_ID': 'player_id'})
|
| 24 |
+
raw_display = raw_display[['Player', 'Position', 'Team', 'Opp', 'Salary', 'Floor', 'Median', 'exFPTS', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%',
|
| 25 |
+
'Own', 'Small_Field_Own', 'Large_Field_Own', 'Cash_Field_Own', 'CPT_Own', 'LevX', 'version', 'slate', 'timestamp', 'player_id', 'site']]
|
| 26 |
+
raw_display['Player'] = raw_display['Player'].map(dict(zip(wrong_nfl_team_names, right_nfl_name_teams)), na_action='ignore').fillna(raw_display['Player'])
|
| 27 |
+
load_display = raw_display[raw_display['Position'] != 'K']
|
| 28 |
+
dk_roo_raw = load_display.dropna(subset=['Median'])
|
| 29 |
+
|
| 30 |
+
dk_id_map = dict(zip(dk_roo_raw['Player'], dk_roo_raw['player_id']))
|
| 31 |
+
|
| 32 |
+
collection = nfl_db["FD_NFL_ROO"]
|
| 33 |
+
cursor = collection.find()
|
| 34 |
+
|
| 35 |
+
raw_display = pd.DataFrame(list(cursor))
|
| 36 |
+
raw_display = raw_display.rename(columns={'player_ID': 'player_id'})
|
| 37 |
+
raw_display = raw_display[['Player', 'Position', 'Team', 'Opp', 'Salary', 'Floor', 'Median', 'exFPTS', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%',
|
| 38 |
+
'Own', 'Small_Field_Own', 'Large_Field_Own', 'Cash_Field_Own', 'CPT_Own', 'LevX', 'version', 'slate', 'timestamp', 'player_id', 'site']]
|
| 39 |
+
raw_display['Player'] = raw_display['Player'].map(dict(zip(wrong_nfl_team_names, right_nfl_name_teams)), na_action='ignore').fillna(raw_display['Player'])
|
| 40 |
+
load_display = raw_display[raw_display['Position'] != 'K']
|
| 41 |
+
fd_roo_raw = load_display.dropna(subset=['Median'])
|
| 42 |
+
|
| 43 |
+
fd_id_map = dict(zip(fd_roo_raw['Player'], fd_roo_raw['player_id']))
|
| 44 |
+
|
| 45 |
+
dk_roo_raw = dk_roo_raw.drop(columns=['player_id'])
|
| 46 |
+
fd_roo_raw = fd_roo_raw.drop(columns=['player_id'])
|
| 47 |
+
|
| 48 |
+
dk_roo_raw = dk_roo_raw.rename(columns={'Player': 'player_names', 'Position': 'position', 'Team': 'team', 'Salary': 'salary', 'Median': 'median', 'Own': 'ownership', 'CPT_Own': 'captain ownership'})
|
| 49 |
+
fd_roo_raw = fd_roo_raw.rename(columns={'Player': 'player_names', 'Position': 'position', 'Team': 'team', 'Salary': 'salary', 'Median': 'median', 'Own': 'ownership', 'CPT_Own': 'captain ownership'})
|
| 50 |
+
|
| 51 |
+
dk_sd_roo_raw = None
|
| 52 |
+
fd_sd_roo_raw = None
|
| 53 |
+
dk_sd_id_map = None
|
| 54 |
+
fd_sd_id_map = None
|
| 55 |
+
elif type_var == 'Showdown':
|
| 56 |
+
collection = nfl_db["DK_SD_NFL_ROO"]
|
| 57 |
+
cursor = collection.find()
|
| 58 |
+
|
| 59 |
+
raw_display = pd.DataFrame(list(cursor))
|
| 60 |
+
raw_display = raw_display.rename(columns={'player_ID': 'player_id'})
|
| 61 |
+
raw_display = raw_display[['Player', 'Position', 'Team', 'Salary', 'Median', 'Own', 'CPT_Own', 'player_id']]
|
| 62 |
+
raw_display['Player'] = raw_display['Player'].map(dict(zip(wrong_nfl_team_names, right_nfl_name_teams)), na_action='ignore').fillna(raw_display['Player'])
|
| 63 |
+
# load_display = raw_display[raw_display['Position'] != 'K']
|
| 64 |
+
dk_sd_roo_raw = raw_display.dropna(subset=['Median'])
|
| 65 |
+
|
| 66 |
+
dk_sd_id_map = dict(zip(dk_sd_roo_raw['Player'], dk_sd_roo_raw['player_id']))
|
| 67 |
+
|
| 68 |
+
collection = nfl_db["FD_SD_NFL_ROO"]
|
| 69 |
+
cursor = collection.find()
|
| 70 |
+
|
| 71 |
+
raw_display = pd.DataFrame(list(cursor))
|
| 72 |
+
raw_display = raw_display.rename(columns={'player_ID': 'player_id'})
|
| 73 |
+
raw_display = raw_display[['Player', 'Position', 'Team', 'Salary', 'Median', 'Own', 'CPT_Own', 'player_id']]
|
| 74 |
+
raw_display['Player'] = raw_display['Player'].map(dict(zip(wrong_nfl_team_names, right_nfl_name_teams)), na_action='ignore').fillna(raw_display['Player'])
|
| 75 |
+
# load_display = raw_display[raw_display['Position'] != 'K']
|
| 76 |
+
fd_sd_roo_raw = raw_display.dropna(subset=['Median'])
|
| 77 |
+
|
| 78 |
+
fd_sd_id_map = dict(zip(fd_sd_roo_raw['Player'], fd_sd_roo_raw['player_id']))
|
| 79 |
+
|
| 80 |
+
dk_sd_roo_raw = dk_sd_roo_raw.drop(columns=['player_id'])
|
| 81 |
+
fd_sd_roo_raw = fd_sd_roo_raw.drop(columns=['player_id'])
|
| 82 |
+
|
| 83 |
+
dk_sd_roo_raw = dk_sd_roo_raw.rename(columns={'Player': 'player_names', 'Position': 'position', 'Team': 'team', 'Salary': 'salary', 'Median': 'median', 'Own': 'ownership', 'CPT_Own': 'captain ownership'})
|
| 84 |
+
fd_sd_roo_raw = fd_sd_roo_raw.rename(columns={'Player': 'player_names', 'Position': 'position', 'Team': 'team', 'Salary': 'salary', 'Median': 'median', 'Own': 'ownership', 'CPT_Own': 'captain_ownership'})
|
| 85 |
+
|
| 86 |
+
dk_roo_raw = None
|
| 87 |
+
fd_roo_raw = None
|
| 88 |
+
dk_id_map = None
|
| 89 |
+
fd_id_map = None
|
| 90 |
+
|
| 91 |
+
return dk_roo_raw, fd_roo_raw, dk_sd_roo_raw, fd_sd_roo_raw, dk_id_map, fd_id_map, dk_sd_id_map, fd_sd_id_map
|
| 92 |
+
|
| 93 |
+
def init_DK_NFL_lineups(type_var, slate_var, prio_var, prio_mix, nfl_db_translation, lineup_num, player_var2):
|
| 94 |
+
|
| 95 |
+
if prio_var == 'Mix':
|
| 96 |
+
prio_var = None
|
| 97 |
+
|
| 98 |
+
if type_var == 'Regular':
|
| 99 |
+
if slate_var == 'Main':
|
| 100 |
+
collection = nfl_db['DK_NFL_name_map']
|
| 101 |
+
cursor = collection.find()
|
| 102 |
+
raw_data = pd.DataFrame(list(cursor))
|
| 103 |
+
raw_data['value'] = raw_data['value'].map(dict(zip(wrong_nfl_team_names, right_nfl_name_teams)), na_action='ignore').fillna(raw_data['value'])
|
| 104 |
+
names_dict = dict(zip(raw_data['key'], raw_data['value']))
|
| 105 |
+
|
| 106 |
+
collection = nfl_db['DK_NFL_seed_frame_Main Slate']
|
| 107 |
+
if prio_var == None:
|
| 108 |
+
if player_var2 != []:
|
| 109 |
+
player_columns = ['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST']
|
| 110 |
+
query_conditions = []
|
| 111 |
+
|
| 112 |
+
for player in player_var2:
|
| 113 |
+
# Create a condition for each player to check if they appear in any column
|
| 114 |
+
player_condition = {'$or': [{col: player} for col in player_columns]}
|
| 115 |
+
query_conditions.append(player_condition)
|
| 116 |
+
|
| 117 |
+
# Combine all player conditions with $or
|
| 118 |
+
if query_conditions:
|
| 119 |
+
filter_query = {'$or': query_conditions}
|
| 120 |
+
cursor1 = collection.find(filter_query).limit(math.ceil(lineup_num * (prio_mix / 100)))
|
| 121 |
+
cursor2 = collection.find(filter_query).sort('Own', -1).limit(math.ceil(lineup_num * ((100 - prio_mix) / 100)))
|
| 122 |
+
else:
|
| 123 |
+
cursor1 = collection.find().limit(math.ceil(lineup_num * (prio_mix / 100)))
|
| 124 |
+
cursor2 = collection.find().sort('Own', -1).limit(math.ceil(lineup_num * ((100 - prio_mix) / 100)))
|
| 125 |
+
raw_display = pd.concat([pd.DataFrame(list(cursor1)), pd.DataFrame(list(cursor2))])
|
| 126 |
+
else:
|
| 127 |
+
cursor1 = collection.find().limit(math.ceil(lineup_num * (prio_mix / 100)))
|
| 128 |
+
cursor2 = collection.find().sort('Own', -1).limit(math.ceil(lineup_num * ((100 - prio_mix) / 100)))
|
| 129 |
+
raw_display = pd.concat([pd.DataFrame(list(cursor1)), pd.DataFrame(list(cursor2))])
|
| 130 |
+
else:
|
| 131 |
+
cursor = collection.find().sort(prio_var, -1).limit(lineup_num)
|
| 132 |
+
raw_display = pd.DataFrame(list(cursor))
|
| 133 |
+
|
| 134 |
+
raw_display = raw_display.drop_duplicates(subset=['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST'])
|
| 135 |
+
|
| 136 |
+
raw_display = raw_display[['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST']]
|
| 137 |
+
dict_columns = ['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST']
|
| 138 |
+
# Map names
|
| 139 |
+
raw_display[dict_columns] = raw_display[dict_columns].apply(lambda x: x.map(names_dict))
|
| 140 |
+
elif slate_var == 'Secondary':
|
| 141 |
+
collection = nfl_db['DK_NFL_Secondary_name_map']
|
| 142 |
+
cursor = collection.find()
|
| 143 |
+
raw_data = pd.DataFrame(list(cursor))
|
| 144 |
+
raw_data['value'] = raw_data['value'].map(dict(zip(wrong_nfl_team_names, right_nfl_name_teams)), na_action='ignore').fillna(raw_data['value'])
|
| 145 |
+
names_dict = dict(zip(raw_data['key'], raw_data['value']))
|
| 146 |
+
|
| 147 |
+
collection = nfl_db['DK_NFL_seed_frame_Secondary Slate']
|
| 148 |
+
if prio_var == None:
|
| 149 |
+
if player_var2 != []:
|
| 150 |
+
player_columns = ['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST']
|
| 151 |
+
query_conditions = []
|
| 152 |
+
|
| 153 |
+
for player in player_var2:
|
| 154 |
+
# Create a condition for each player to check if they appear in any column
|
| 155 |
+
player_condition = {'$or': [{col: player} for col in player_columns]}
|
| 156 |
+
query_conditions.append(player_condition)
|
| 157 |
+
|
| 158 |
+
# Combine all player conditions with $or
|
| 159 |
+
if query_conditions:
|
| 160 |
+
filter_query = {'$or': query_conditions}
|
| 161 |
+
cursor1 = collection.find(filter_query).limit(math.ceil(lineup_num * (prio_mix / 100)))
|
| 162 |
+
cursor2 = collection.find(filter_query).sort('Own', -1).limit(math.ceil(lineup_num * ((100 - prio_mix) / 100)))
|
| 163 |
+
else:
|
| 164 |
+
cursor1 = collection.find().limit(math.ceil(lineup_num * (prio_mix / 100)))
|
| 165 |
+
cursor2 = collection.find().sort('Own', -1).limit(math.ceil(lineup_num * ((100 - prio_mix) / 100)))
|
| 166 |
+
raw_display = pd.concat([pd.DataFrame(list(cursor1)), pd.DataFrame(list(cursor2))])
|
| 167 |
+
else:
|
| 168 |
+
cursor1 = collection.find().limit(math.ceil(lineup_num * (prio_mix / 100)))
|
| 169 |
+
cursor2 = collection.find().sort('Own', -1).limit(math.ceil(lineup_num * ((100 - prio_mix) / 100)))
|
| 170 |
+
raw_display = pd.concat([pd.DataFrame(list(cursor1)), pd.DataFrame(list(cursor2))])
|
| 171 |
+
else:
|
| 172 |
+
cursor = collection.find().sort(prio_var, -1).limit(lineup_num)
|
| 173 |
+
raw_display = pd.DataFrame(list(cursor))
|
| 174 |
+
|
| 175 |
+
raw_display = raw_display.drop_duplicates(subset=['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST'])
|
| 176 |
+
|
| 177 |
+
raw_display = raw_display[['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST']]
|
| 178 |
+
dict_columns = ['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST']
|
| 179 |
+
# Map names
|
| 180 |
+
raw_display[dict_columns] = raw_display[dict_columns].apply(lambda x: x.map(names_dict))
|
| 181 |
+
elif slate_var == 'Auxiliary':
|
| 182 |
+
collection = nfl_db['DK_NFL_Late_name_map']
|
| 183 |
+
cursor = collection.find()
|
| 184 |
+
raw_data = pd.DataFrame(list(cursor))
|
| 185 |
+
raw_data['value'] = raw_data['value'].map(dict(zip(wrong_nfl_team_names, right_nfl_name_teams)), na_action='ignore').fillna(raw_data['value'])
|
| 186 |
+
names_dict = dict(zip(raw_data['key'], raw_data['value']))
|
| 187 |
+
|
| 188 |
+
collection = nfl_db['DK_NFL_seed_frame_Late Slate']
|
| 189 |
+
if prio_var == None:
|
| 190 |
+
if player_var2 != []:
|
| 191 |
+
player_columns = ['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST']
|
| 192 |
+
query_conditions = []
|
| 193 |
+
|
| 194 |
+
for player in player_var2:
|
| 195 |
+
# Create a condition for each player to check if they appear in any column
|
| 196 |
+
player_condition = {'$or': [{col: player} for col in player_columns]}
|
| 197 |
+
query_conditions.append(player_condition)
|
| 198 |
+
|
| 199 |
+
# Combine all player conditions with $or
|
| 200 |
+
if query_conditions:
|
| 201 |
+
filter_query = {'$or': query_conditions}
|
| 202 |
+
cursor1 = collection.find(filter_query).limit(math.ceil(lineup_num * (prio_mix / 100)))
|
| 203 |
+
cursor2 = collection.find(filter_query).sort('Own', -1).limit(math.ceil(lineup_num * ((100 - prio_mix) / 100)))
|
| 204 |
+
else:
|
| 205 |
+
cursor1 = collection.find().limit(math.ceil(lineup_num * (prio_mix / 100)))
|
| 206 |
+
cursor2 = collection.find().sort('Own', -1).limit(math.ceil(lineup_num * ((100 - prio_mix) / 100)))
|
| 207 |
+
raw_display = pd.concat([pd.DataFrame(list(cursor1)), pd.DataFrame(list(cursor2))])
|
| 208 |
+
else:
|
| 209 |
+
cursor1 = collection.find().limit(math.ceil(lineup_num * (prio_mix / 100)))
|
| 210 |
+
cursor2 = collection.find().sort('Own', -1).limit(math.ceil(lineup_num * ((100 - prio_mix) / 100)))
|
| 211 |
+
raw_display = pd.concat([pd.DataFrame(list(cursor1)), pd.DataFrame(list(cursor2))])
|
| 212 |
+
else:
|
| 213 |
+
cursor = collection.find().sort(prio_var, -1).limit(lineup_num)
|
| 214 |
+
raw_display = pd.DataFrame(list(cursor))
|
| 215 |
+
|
| 216 |
+
raw_display = raw_display.drop_duplicates(subset=['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST'])
|
| 217 |
+
|
| 218 |
+
raw_display = raw_display[['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST']]
|
| 219 |
+
dict_columns = ['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST']
|
| 220 |
+
# Map names
|
| 221 |
+
raw_display[dict_columns] = raw_display[dict_columns].apply(lambda x: x.map(names_dict))
|
| 222 |
+
elif type_var == 'Showdown':
|
| 223 |
+
collection = nfl_db[nfl_db_translation[slate_var]]
|
| 224 |
+
if prio_var == None:
|
| 225 |
+
if player_var2 != []:
|
| 226 |
+
player_columns = ['CPT', 'FLEX1', 'FLEX2', 'FLEX3', 'FLEX4', 'FLEX5']
|
| 227 |
+
query_conditions = []
|
| 228 |
+
|
| 229 |
+
for player in player_var2:
|
| 230 |
+
# Create a condition for each player to check if they appear in any column
|
| 231 |
+
player_condition = {'$or': [{col: player} for col in player_columns]}
|
| 232 |
+
query_conditions.append(player_condition)
|
| 233 |
+
|
| 234 |
+
# Combine all player conditions with $or
|
| 235 |
+
if query_conditions:
|
| 236 |
+
filter_query = {'$or': query_conditions}
|
| 237 |
+
cursor1 = collection.find(filter_query).limit(math.ceil(lineup_num * (prio_mix / 100)))
|
| 238 |
+
cursor2 = collection.find(filter_query).sort('Own', -1).limit(math.ceil(lineup_num * ((100 - prio_mix) / 100)))
|
| 239 |
+
else:
|
| 240 |
+
cursor1 = collection.find().limit(math.ceil(lineup_num * (prio_mix / 100)))
|
| 241 |
+
cursor2 = collection.find().sort('Own', -1).limit(math.ceil(lineup_num * ((100 - prio_mix) / 100)))
|
| 242 |
+
raw_display = pd.concat([pd.DataFrame(list(cursor1)), pd.DataFrame(list(cursor2))])
|
| 243 |
+
else:
|
| 244 |
+
cursor1 = collection.find().limit(math.ceil(lineup_num * (prio_mix / 100)))
|
| 245 |
+
cursor2 = collection.find().sort('Own', -1).limit(math.ceil(lineup_num * ((100 - prio_mix) / 100)))
|
| 246 |
+
raw_display = pd.concat([pd.DataFrame(list(cursor1)), pd.DataFrame(list(cursor2))])
|
| 247 |
+
else:
|
| 248 |
+
cursor = collection.find().sort(prio_var, -1).limit(lineup_num)
|
| 249 |
+
raw_display = pd.DataFrame(list(cursor))
|
| 250 |
+
|
| 251 |
+
raw_display = raw_display.drop_duplicates(subset=['CPT', 'FLEX1', 'FLEX2', 'FLEX3', 'FLEX4', 'FLEX5'])
|
| 252 |
+
|
| 253 |
+
raw_display = raw_display[['CPT', 'FLEX1', 'FLEX2', 'FLEX3', 'FLEX4', 'FLEX5']]
|
| 254 |
+
for column in ['CPT', 'FLEX1', 'FLEX2', 'FLEX3', 'FLEX4', 'FLEX5']:
|
| 255 |
+
raw_display[column] = raw_display[column].map(dict(zip(wrong_nfl_team_names, right_nfl_name_teams)), na_action='ignore').fillna(raw_display[column])
|
| 256 |
+
|
| 257 |
+
DK_seed = raw_display.to_numpy()
|
| 258 |
+
|
| 259 |
+
return DK_seed
|
| 260 |
+
|
| 261 |
+
def init_FD_NFL_lineups(type_var, slate_var, prio_var, prio_mix, nfl_db_translation, lineup_num, player_var2):
|
| 262 |
+
|
| 263 |
+
if prio_var == 'Mix':
|
| 264 |
+
prio_var = None
|
| 265 |
+
|
| 266 |
+
if type_var == 'Regular':
|
| 267 |
+
if slate_var == 'Main':
|
| 268 |
+
collection = nfl_db['FD_NFL_name_map']
|
| 269 |
+
cursor = collection.find()
|
| 270 |
+
raw_data = pd.DataFrame(list(cursor))
|
| 271 |
+
raw_data['value'] = raw_data['value'].map(dict(zip(wrong_nfl_team_names, right_nfl_name_teams)), na_action='ignore').fillna(raw_data['value'])
|
| 272 |
+
names_dict = dict(zip(raw_data['key'], raw_data['value']))
|
| 273 |
+
|
| 274 |
+
|
| 275 |
+
collection = nfl_db['FD_NFL_seed_frame_Main Slate']
|
| 276 |
+
if prio_var == None:
|
| 277 |
+
if player_var2 != []:
|
| 278 |
+
player_columns = ['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST']
|
| 279 |
+
query_conditions = []
|
| 280 |
+
|
| 281 |
+
for player in player_var2:
|
| 282 |
+
# Create a condition for each player to check if they appear in any column
|
| 283 |
+
player_condition = {'$or': [{col: player} for col in player_columns]}
|
| 284 |
+
query_conditions.append(player_condition)
|
| 285 |
+
|
| 286 |
+
# Combine all player conditions with $or
|
| 287 |
+
if query_conditions:
|
| 288 |
+
filter_query = {'$or': query_conditions}
|
| 289 |
+
cursor1 = collection.find(filter_query).limit(math.ceil(lineup_num * (prio_mix / 100)))
|
| 290 |
+
cursor2 = collection.find(filter_query).sort('Own', -1).limit(math.ceil(lineup_num * ((100 - prio_mix) / 100)))
|
| 291 |
+
else:
|
| 292 |
+
cursor1 = collection.find().limit(math.ceil(lineup_num * (prio_mix / 100)))
|
| 293 |
+
cursor2 = collection.find().sort('Own', -1).limit(math.ceil(lineup_num * ((100 - prio_mix) / 100)))
|
| 294 |
+
raw_display = pd.concat([pd.DataFrame(list(cursor1)), pd.DataFrame(list(cursor2))])
|
| 295 |
+
else:
|
| 296 |
+
cursor1 = collection.find().limit(math.ceil(lineup_num * (prio_mix / 100)))
|
| 297 |
+
cursor2 = collection.find().sort('Own', -1).limit(math.ceil(lineup_num * ((100 - prio_mix) / 100)))
|
| 298 |
+
raw_display = pd.concat([pd.DataFrame(list(cursor1)), pd.DataFrame(list(cursor2))])
|
| 299 |
+
else:
|
| 300 |
+
cursor = collection.find().sort(prio_var, -1).limit(lineup_num)
|
| 301 |
+
raw_display = pd.DataFrame(list(cursor))
|
| 302 |
+
|
| 303 |
+
raw_display = raw_display.drop_duplicates(subset=['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST'])
|
| 304 |
+
|
| 305 |
+
raw_display = raw_display[['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST']]
|
| 306 |
+
dict_columns = ['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST']
|
| 307 |
+
# Map names
|
| 308 |
+
raw_display[dict_columns] = raw_display[dict_columns].apply(lambda x: x.map(names_dict))
|
| 309 |
+
elif slate_var == 'Secondary':
|
| 310 |
+
collection = nfl_db['FD_NFL_Secondary_name_map']
|
| 311 |
+
cursor = collection.find()
|
| 312 |
+
raw_data = pd.DataFrame(list(cursor))
|
| 313 |
+
raw_data['value'] = raw_data['value'].map(dict(zip(wrong_nfl_team_names, right_nfl_name_teams)), na_action='ignore').fillna(raw_data['value'])
|
| 314 |
+
names_dict = dict(zip(raw_data['key'], raw_data['value']))
|
| 315 |
+
|
| 316 |
+
collection = nfl_db['FD_NFL_Secondary_seed_frame_Secondary Slate']
|
| 317 |
+
if prio_var == None:
|
| 318 |
+
if player_var2 != []:
|
| 319 |
+
player_columns = ['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST']
|
| 320 |
+
query_conditions = []
|
| 321 |
+
|
| 322 |
+
for player in player_var2:
|
| 323 |
+
# Create a condition for each player to check if they appear in any column
|
| 324 |
+
player_condition = {'$or': [{col: player} for col in player_columns]}
|
| 325 |
+
query_conditions.append(player_condition)
|
| 326 |
+
|
| 327 |
+
# Combine all player conditions with $or
|
| 328 |
+
if query_conditions:
|
| 329 |
+
filter_query = {'$or': query_conditions}
|
| 330 |
+
cursor1 = collection.find(filter_query).limit(math.ceil(lineup_num * (prio_mix / 100)))
|
| 331 |
+
cursor2 = collection.find(filter_query).sort('Own', -1).limit(math.ceil(lineup_num * ((100 - prio_mix) / 100)))
|
| 332 |
+
else:
|
| 333 |
+
cursor1 = collection.find().limit(math.ceil(lineup_num * (prio_mix / 100)))
|
| 334 |
+
cursor2 = collection.find().sort('Own', -1).limit(math.ceil(lineup_num * ((100 - prio_mix) / 100)))
|
| 335 |
+
raw_display = pd.concat([pd.DataFrame(list(cursor1)), pd.DataFrame(list(cursor2))])
|
| 336 |
+
else:
|
| 337 |
+
cursor1 = collection.find().limit(math.ceil(lineup_num * (prio_mix / 100)))
|
| 338 |
+
cursor2 = collection.find().sort('Own', -1).limit(math.ceil(lineup_num * ((100 - prio_mix) / 100)))
|
| 339 |
+
raw_display = pd.concat([pd.DataFrame(list(cursor1)), pd.DataFrame(list(cursor2))])
|
| 340 |
+
else:
|
| 341 |
+
cursor = collection.find().sort(prio_var, -1).limit(lineup_num)
|
| 342 |
+
raw_display = pd.DataFrame(list(cursor))
|
| 343 |
+
|
| 344 |
+
raw_display = raw_display.drop_duplicates(subset=['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST'])
|
| 345 |
+
|
| 346 |
+
raw_display = raw_display[['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST']]
|
| 347 |
+
dict_columns = ['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST']
|
| 348 |
+
# Map names
|
| 349 |
+
raw_display[dict_columns] = raw_display[dict_columns].apply(lambda x: x.map(names_dict))
|
| 350 |
+
elif slate_var == 'Auxiliary':
|
| 351 |
+
collection = nfl_db['FD_NFL_Late_name_map']
|
| 352 |
+
cursor = collection.find()
|
| 353 |
+
raw_data = pd.DataFrame(list(cursor))
|
| 354 |
+
raw_data['value'] = raw_data['value'].map(dict(zip(wrong_nfl_team_names, right_nfl_name_teams)), na_action='ignore').fillna(raw_data['value'])
|
| 355 |
+
names_dict = dict(zip(raw_data['key'], raw_data['value']))
|
| 356 |
+
|
| 357 |
+
collection = nfl_db['FD_NFL_Late_seed_frame_Late Slate']
|
| 358 |
+
if prio_var == None:
|
| 359 |
+
if player_var2 != []:
|
| 360 |
+
player_columns = ['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST']
|
| 361 |
+
query_conditions = []
|
| 362 |
+
|
| 363 |
+
for player in player_var2:
|
| 364 |
+
# Create a condition for each player to check if they appear in any column
|
| 365 |
+
player_condition = {'$or': [{col: player} for col in player_columns]}
|
| 366 |
+
query_conditions.append(player_condition)
|
| 367 |
+
|
| 368 |
+
# Combine all player conditions with $or
|
| 369 |
+
if query_conditions:
|
| 370 |
+
filter_query = {'$or': query_conditions}
|
| 371 |
+
cursor1 = collection.find(filter_query).limit(math.ceil(lineup_num * (prio_mix / 100)))
|
| 372 |
+
cursor2 = collection.find(filter_query).sort('Own', -1).limit(math.ceil(lineup_num = ((100 - prio_mix) / 100)))
|
| 373 |
+
else:
|
| 374 |
+
cursor1 = collection.find().limit(math.ceil(lineup_num * (prio_mix / 100)))
|
| 375 |
+
cursor2 = collection.find().sort('Own', -1).limit(math.ceil(lineup_num * ((100 - prio_mix) / 100)))
|
| 376 |
+
raw_display = pd.concat([pd.DataFrame(list(cursor1)), pd.DataFrame(list(cursor2))])
|
| 377 |
+
else:
|
| 378 |
+
cursor1 = collection.find().limit(math.ceil(lineup_num * (prio_mix / 100)))
|
| 379 |
+
cursor2 = collection.find().sort('Own', -1).limit(math.ceil(lineup_num * ((100 - prio_mix) / 100)))
|
| 380 |
+
raw_display = pd.concat([pd.DataFrame(list(cursor1)), pd.DataFrame(list(cursor2))])
|
| 381 |
+
else:
|
| 382 |
+
cursor = collection.find().sort(prio_var, -1).limit(lineup_num)
|
| 383 |
+
raw_display = pd.DataFrame(list(cursor))
|
| 384 |
+
|
| 385 |
+
raw_display = raw_display.drop_duplicates(subset=['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST'])
|
| 386 |
+
|
| 387 |
+
raw_display = raw_display[['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST']]
|
| 388 |
+
dict_columns = ['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST']
|
| 389 |
+
# Map names
|
| 390 |
+
raw_display[dict_columns] = raw_display[dict_columns].apply(lambda x: x.map(names_dict))
|
| 391 |
+
|
| 392 |
+
elif type_var == 'Showdown':
|
| 393 |
+
collection = nfl_db[nfl_db_translation[slate_var]]
|
| 394 |
+
if prio_var == None:
|
| 395 |
+
if player_var2 != []:
|
| 396 |
+
player_columns = ['CPT', 'FLEX1', 'FLEX2', 'FLEX3', 'FLEX4', 'FLEX5']
|
| 397 |
+
query_conditions = []
|
| 398 |
+
|
| 399 |
+
for player in player_var2:
|
| 400 |
+
# Create a condition for each player to check if they appear in any column
|
| 401 |
+
player_condition = {'$or': [{col: player} for col in player_columns]}
|
| 402 |
+
query_conditions.append(player_condition)
|
| 403 |
+
|
| 404 |
+
# Combine all player conditions with $or
|
| 405 |
+
if query_conditions:
|
| 406 |
+
filter_query = {'$or': query_conditions}
|
| 407 |
+
cursor1 = collection.find(filter_query).limit(math.ceil(lineup_num * (prio_mix / 100)))
|
| 408 |
+
cursor2 = collection.find(filter_query).sort('Own', -1).limit(math.ceil(lineup_num * ((100 - prio_mix) / 100)))
|
| 409 |
+
else:
|
| 410 |
+
cursor1 = collection.find().limit(math.ceil(lineup_num * (prio_mix / 100)))
|
| 411 |
+
cursor2 = collection.find().sort('Own', -1).limit(math.ceil(lineup_num * ((100 - prio_mix) / 100)))
|
| 412 |
+
raw_display = pd.concat([pd.DataFrame(list(cursor1)), pd.DataFrame(list(cursor2))])
|
| 413 |
+
else:
|
| 414 |
+
cursor1 = collection.find().limit(math.ceil(lineup_num * (prio_mix / 100)))
|
| 415 |
+
cursor2 = collection.find().sort('Own', -1).limit(math.ceil(lineup_num * ((100 - prio_mix) / 100)))
|
| 416 |
+
raw_display = pd.concat([pd.DataFrame(list(cursor1)), pd.DataFrame(list(cursor2))])
|
| 417 |
+
else:
|
| 418 |
+
cursor = collection.find().sort(prio_var, -1).limit(lineup_num)
|
| 419 |
+
raw_display = pd.DataFrame(list(cursor))
|
| 420 |
+
|
| 421 |
+
raw_display = raw_display.drop_duplicates(subset=['CPT', 'FLEX1', 'FLEX2', 'FLEX3', 'FLEX4', 'FLEX5'])
|
| 422 |
+
|
| 423 |
+
raw_display = raw_display[['CPT', 'FLEX1', 'FLEX2', 'FLEX3', 'FLEX4', 'FLEX5']]
|
| 424 |
+
for column in ['CPT', 'FLEX1', 'FLEX2', 'FLEX3', 'FLEX4', 'FLEX5']:
|
| 425 |
+
raw_display[column] = raw_display[column].map(dict(zip(wrong_nfl_team_names, right_nfl_name_teams)), na_action='ignore').fillna(raw_display[column])
|
| 426 |
+
|
| 427 |
+
FD_seed = raw_display.to_numpy()
|
| 428 |
+
|
| 429 |
+
return FD_seed
|
requirements.txt
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
streamlit==1.48.0
|
|
|
|
| 2 |
pandas
|
| 3 |
numpy
|
| 4 |
rapidfuzz
|
|
|
|
| 1 |
streamlit==1.48.0
|
| 2 |
+
pymongo
|
| 3 |
pandas
|
| 4 |
numpy
|
| 5 |
rapidfuzz
|