-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataLoader.py
More file actions
45 lines (36 loc) · 1.43 KB
/
Copy pathdataLoader.py
File metadata and controls
45 lines (36 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import pandas as pd
import numpy as np
import streamlit as st
#from shillelagh.backends.apsw.db import connect
import gspread
#@st.cache_data(ttl = 600)
#def runQuery(sheets_link):
# connection = connect(":memory:", adapters = 'gsheetsapi')
# cursor = connection.cursor()
# query = f'SELECT * FROM "{sheets_link}"'
# query_results = []
# for row in cursor.execute(query):
# query_results.append(row)
# return query_results
@st.cache_data(ttl = 600)
def runQuery(api_key, sheets_key, sheet_name = 'Sheet1', expected_headers = ['Game', 'When started']):
gc = gspread.api_key(api_key)
sh = gc.open_by_key(sheets_key)
results = pd.DataFrame(sh.worksheet(sheet_name).get_all_records(expected_headers = expected_headers))
return results
def loadData_results(year):
#sheets_query = runQuery(st.secrets['results_url'])
if year != '2025':
sheet_name = f'{year}_BGA_Journey [Archived]'
else:
sheet_name = f'{year}_BGA_Journey'
results = runQuery(st.secrets['api_key'], st.secrets['results_key'], sheet_name = sheet_name)
#only grab entries related to games
for i, val in enumerate(results['Game'] == ''):
if val:
game_end = i
break
results = results.iloc[:game_end]
results = results.astype({'When finished': 'datetime64[ns]', 'When started': 'datetime64[ns]'})
#results = results.dropna(subset = 'Are they the same')
return results