Multichem commited on
Commit
18cc217
·
verified ·
1 Parent(s): 10365e4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -16
app.py CHANGED
@@ -6,7 +6,7 @@ import gspread
6
  import pymongo
7
  import time
8
 
9
- @st.cache_data(ttl = 599)
10
  def init_conn():
11
  scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
12
 
@@ -25,7 +25,20 @@ def init_conn():
25
  uri = "mongodb+srv://multichem:[email protected]/?retryWrites=true&w=majority&appName=TestCluster"
26
  client = pymongo.MongoClient(uri, retryWrites=True, serverSelectionTimeoutMS=100000)
27
  db = client["testing_db"]
 
 
 
 
 
 
 
 
 
 
 
28
 
 
 
29
  collection = db["DK_MLB_seed_frame"]
30
  cursor = collection.find()
31
 
@@ -39,19 +52,8 @@ def init_conn():
39
  raw_display = pd.DataFrame(list(cursor))
40
  raw_display = raw_display[['P', 'C_1B', '2B', '3B', 'SS', 'OF1', 'OF2', 'OF3', 'UTIL', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count']]
41
  FD_seed = raw_display.to_numpy()
42
-
43
- MLB_Data = 'https://docs.google.com/spreadsheets/d/1f42Ergav8K1VsOLOK9MUn7DM_MLMvv4GR2Fy7EfnZTc/edit#gid=340831852'
44
-
45
- gc_con = gspread.service_account_from_dict(credentials, scope)
46
 
47
- client.close()
48
-
49
- return gc_con, client, db, DK_seed, FD_seed, MLB_Data
50
-
51
- percentages_format = {'Exposure': '{:.2%}'}
52
- freq_format = {'Exposure': '{:.2%}', 'Proj Own': '{:.2%}', 'Edge': '{:.2%}'}
53
- dk_columns = ['SP1', 'SP2', 'C', '1B', '2B', '3B', 'SS', 'OF1', 'OF2', 'OF3', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count']
54
- fd_columns = ['P', 'C_1B', '2B', '3B', 'SS', 'OF1', 'OF2', 'OF3', 'UTIL', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count']
55
 
56
  @st.cache_data(ttl = 599)
57
  def init_baselines():
@@ -124,7 +126,7 @@ def sim_contest(Sim_size, seed_frame, maps_dict, sharp_split, Contest_Size):
124
 
125
  return Sim_Winners
126
 
127
- gcservice_account, client, db, DK_seed, FD_seed, MLB_Data = init_conn()
128
  dk_raw, fd_raw = init_baselines()
129
 
130
  tab1, tab2 = st.tabs(['Data Export', 'Contest Sims'])
@@ -135,7 +137,7 @@ with tab1:
135
  st.cache_data.clear()
136
  for key in st.session_state.keys():
137
  del st.session_state[key]
138
- gcservice_account, client, db, DK_seed, FD_seed, MLB_Data = init_conn()
139
  dk_raw, fd_raw = init_baselines()
140
 
141
  slate_var1 = st.radio("Which data are you loading?", ('Main Slate', 'Other Main Slate'))
@@ -221,7 +223,7 @@ with tab2:
221
  st.cache_data.clear()
222
  for key in st.session_state.keys():
223
  del st.session_state[key]
224
- gcservice_account, client, db, DK_seed, FD_seed, MLB_Data = init_conn()
225
  dk_raw, fd_raw = init_baselines()
226
  sim_slate_var1 = st.radio("Which data are you loading?", ('Main Slate', 'Other Main Slate'), key='sim_slate_var1')
227
  sim_site_var1 = st.radio("What site are you working with?", ('Draftkings', 'Fanduel'), key='sim_site_var1')
 
6
  import pymongo
7
  import time
8
 
9
+ @st.cache_resource
10
  def init_conn():
11
  scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
12
 
 
25
  uri = "mongodb+srv://multichem:[email protected]/?retryWrites=true&w=majority&appName=TestCluster"
26
  client = pymongo.MongoClient(uri, retryWrites=True, serverSelectionTimeoutMS=100000)
27
  db = client["testing_db"]
28
+
29
+ MLB_Data = 'https://docs.google.com/spreadsheets/d/1f42Ergav8K1VsOLOK9MUn7DM_MLMvv4GR2Fy7EfnZTc/edit#gid=340831852'
30
+
31
+ gc_con = gspread.service_account_from_dict(credentials, scope)
32
+
33
+ gcservice_account, db = init_conn()
34
+
35
+ percentages_format = {'Exposure': '{:.2%}'}
36
+ freq_format = {'Exposure': '{:.2%}', 'Proj Own': '{:.2%}', 'Edge': '{:.2%}'}
37
+ dk_columns = ['SP1', 'SP2', 'C', '1B', '2B', '3B', 'SS', 'OF1', 'OF2', 'OF3', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count']
38
+ fd_columns = ['P', 'C_1B', '2B', '3B', 'SS', 'OF1', 'OF2', 'OF3', 'UTIL', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count']
39
 
40
+ @st.cache_data(ttl = 599)
41
+ def init_seed_frames(database):
42
  collection = db["DK_MLB_seed_frame"]
43
  cursor = collection.find()
44
 
 
52
  raw_display = pd.DataFrame(list(cursor))
53
  raw_display = raw_display[['P', 'C_1B', '2B', '3B', 'SS', 'OF1', 'OF2', 'OF3', 'UTIL', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count']]
54
  FD_seed = raw_display.to_numpy()
 
 
 
 
55
 
56
+ return DK_Seed, FD_Seed
 
 
 
 
 
 
 
57
 
58
  @st.cache_data(ttl = 599)
59
  def init_baselines():
 
126
 
127
  return Sim_Winners
128
 
129
+ DK_Seed, FD_Seed = init_seed_frames(db)
130
  dk_raw, fd_raw = init_baselines()
131
 
132
  tab1, tab2 = st.tabs(['Data Export', 'Contest Sims'])
 
137
  st.cache_data.clear()
138
  for key in st.session_state.keys():
139
  del st.session_state[key]
140
+ DK_Seed, FD_Seed = init_seed_frames(db)
141
  dk_raw, fd_raw = init_baselines()
142
 
143
  slate_var1 = st.radio("Which data are you loading?", ('Main Slate', 'Other Main Slate'))
 
223
  st.cache_data.clear()
224
  for key in st.session_state.keys():
225
  del st.session_state[key]
226
+ DK_Seed, FD_Seed = init_seed_frames(db)
227
  dk_raw, fd_raw = init_baselines()
228
  sim_slate_var1 = st.radio("Which data are you loading?", ('Main Slate', 'Other Main Slate'), key='sim_slate_var1')
229
  sim_site_var1 = st.radio("What site are you working with?", ('Draftkings', 'Fanduel'), key='sim_site_var1')