Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -30,19 +30,23 @@ def init_conn():
|
|
| 30 |
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/gspread-connection%40model-sheets-connect.iam.gserviceaccount.com"
|
| 31 |
}
|
| 32 |
|
| 33 |
-
|
| 34 |
-
db = client["testing_db"]
|
| 35 |
|
| 36 |
gc_con = gspread.service_account_from_dict(credentials, scope)
|
| 37 |
|
| 38 |
-
return gc_con,
|
| 39 |
|
| 40 |
-
gcservice_account,
|
| 41 |
|
| 42 |
percentages_format = {'PG': '{:.2%}', 'SG': '{:.2%}', 'SF': '{:.2%}', 'PF': '{:.2%}', 'C': '{:.2%}'}
|
| 43 |
|
| 44 |
@st.cache_resource(ttl = 600)
|
| 45 |
def init_baselines():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
collection = db["MLB_Hitters_DB"]
|
| 47 |
cursor = collection.find() # Finds all documents in the collection
|
| 48 |
|
|
@@ -56,6 +60,12 @@ def init_baselines():
|
|
| 56 |
|
| 57 |
hitter_gamelog_table = hitter_gamelog_table.set_axis(['Player', 'Team', 'Date', 'G', 'AB', 'PA', 'H', '1B', '2B', '3B', 'HR', 'R', 'RBI', 'BB', 'IBB', 'SO', 'HBP', 'SF', 'SH',
|
| 58 |
'GDP', 'SB', 'CS', 'AVG', 'SLG', 'wRC+', 'LD%', 'GB%', 'FB%', 'Hard%', 'Barrels', 'Barrel%'], axis=1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
collection = db["MLB_Pitchers_DB"]
|
| 61 |
cursor = collection.find() # Finds all documents in the collection
|
|
@@ -78,6 +88,8 @@ def init_baselines():
|
|
| 78 |
'FB%', 'HR/FB', 'Hard%', 'Barrels', 'Barrel%', 'xERA', 'vFA', 'vFT', 'vFC', 'vFS', 'vFO', 'vSI',
|
| 79 |
'vSL', 'vCU', 'vKC', 'vEP', 'vCH', 'vSC', 'vKN'], axis=1)
|
| 80 |
|
|
|
|
|
|
|
| 81 |
timestamp = pitcher_gamelog_table['Date'].max()
|
| 82 |
|
| 83 |
return hitter_gamelog_table, pitcher_gamelog_table, timestamp
|
|
|
|
| 30 |
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/gspread-connection%40model-sheets-connect.iam.gserviceaccount.com"
|
| 31 |
}
|
| 32 |
|
| 33 |
+
uri = "mongodb+srv://multichem:G4yDYEX46uSft4gg@testcluster.lgwtp5i.mongodb.net/?retryWrites=true&w=majority"
|
|
|
|
| 34 |
|
| 35 |
gc_con = gspread.service_account_from_dict(credentials, scope)
|
| 36 |
|
| 37 |
+
return gc_con, uri, db
|
| 38 |
|
| 39 |
+
gcservice_account, uri, db = init_conn()
|
| 40 |
|
| 41 |
percentages_format = {'PG': '{:.2%}', 'SG': '{:.2%}', 'SF': '{:.2%}', 'PF': '{:.2%}', 'C': '{:.2%}'}
|
| 42 |
|
| 43 |
@st.cache_resource(ttl = 600)
|
| 44 |
def init_baselines():
|
| 45 |
+
|
| 46 |
+
# Create a new client and connect to the server
|
| 47 |
+
client = MongoClient(uri, retryWrites=True, serverSelectionTimeoutMS=100000)
|
| 48 |
+
db = client['testing_db']
|
| 49 |
+
|
| 50 |
collection = db["MLB_Hitters_DB"]
|
| 51 |
cursor = collection.find() # Finds all documents in the collection
|
| 52 |
|
|
|
|
| 60 |
|
| 61 |
hitter_gamelog_table = hitter_gamelog_table.set_axis(['Player', 'Team', 'Date', 'G', 'AB', 'PA', 'H', '1B', '2B', '3B', 'HR', 'R', 'RBI', 'BB', 'IBB', 'SO', 'HBP', 'SF', 'SH',
|
| 62 |
'GDP', 'SB', 'CS', 'AVG', 'SLG', 'wRC+', 'LD%', 'GB%', 'FB%', 'Hard%', 'Barrels', 'Barrel%'], axis=1)
|
| 63 |
+
|
| 64 |
+
client.close()
|
| 65 |
+
|
| 66 |
+
time.sleep(1)
|
| 67 |
+
|
| 68 |
+
client = MongoClient(uri, retryWrites=True, serverSelectionTimeoutMS=100000)
|
| 69 |
|
| 70 |
collection = db["MLB_Pitchers_DB"]
|
| 71 |
cursor = collection.find() # Finds all documents in the collection
|
|
|
|
| 88 |
'FB%', 'HR/FB', 'Hard%', 'Barrels', 'Barrel%', 'xERA', 'vFA', 'vFT', 'vFC', 'vFS', 'vFO', 'vSI',
|
| 89 |
'vSL', 'vCU', 'vKC', 'vEP', 'vCH', 'vSC', 'vKN'], axis=1)
|
| 90 |
|
| 91 |
+
client.close()
|
| 92 |
+
|
| 93 |
timestamp = pitcher_gamelog_table['Date'].max()
|
| 94 |
|
| 95 |
return hitter_gamelog_table, pitcher_gamelog_table, timestamp
|