Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,7 +16,6 @@ creds = ServiceAccountCredentials.from_json_keyfile_name(
|
|
| 16 |
)
|
| 17 |
client = gspread.authorize(creds)
|
| 18 |
|
| 19 |
-
# YOUR SPREADSHEET URL
|
| 20 |
SHEET_URL = "https://docs.google.com/spreadsheets/d/1if4KoVQvw5ZbhknfdZbzMkcTiPfsD6bz9V3a1th-bwQ"
|
| 21 |
|
| 22 |
# -------------------- UTILS --------------------
|
|
@@ -29,7 +28,6 @@ def load_sheet_df(name):
|
|
| 29 |
if not data:
|
| 30 |
return pd.DataFrame()
|
| 31 |
raw_header, *rows = data
|
| 32 |
-
# make header unique
|
| 33 |
counts = Counter()
|
| 34 |
header = []
|
| 35 |
for col in raw_header:
|
|
@@ -167,9 +165,17 @@ def quote_year_choices():
|
|
| 167 |
|
| 168 |
def quote_month_choices(year=None):
|
| 169 |
df = get_quotes_df()
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
return months
|
| 174 |
return []
|
| 175 |
|
|
@@ -259,10 +265,8 @@ with gr.Blocks(title="Graffiti Admin Dashboard") as app:
|
|
| 259 |
|
| 260 |
# Dynamic month options for summary
|
| 261 |
def update_month_choices_summary(year):
|
| 262 |
-
if year
|
| 263 |
-
|
| 264 |
-
else:
|
| 265 |
-
return gr.Dropdown.update(choices=[""], value="")
|
| 266 |
year_qs.change(update_month_choices_summary, year_qs, month_qs)
|
| 267 |
|
| 268 |
def quotes_summary_wrapper(year, month):
|
|
@@ -278,10 +282,8 @@ with gr.Blocks(title="Graffiti Admin Dashboard") as app:
|
|
| 278 |
|
| 279 |
# Dynamic month options for rep quotes
|
| 280 |
def update_month_choices(year):
|
| 281 |
-
if year
|
| 282 |
-
|
| 283 |
-
else:
|
| 284 |
-
return gr.Dropdown.update(choices=[""], value="")
|
| 285 |
year_q.change(update_month_choices, year_q, month_q)
|
| 286 |
|
| 287 |
def get_rep_quotes_filtered_wrapper(rep, year, month):
|
|
|
|
| 16 |
)
|
| 17 |
client = gspread.authorize(creds)
|
| 18 |
|
|
|
|
| 19 |
SHEET_URL = "https://docs.google.com/spreadsheets/d/1if4KoVQvw5ZbhknfdZbzMkcTiPfsD6bz9V3a1th-bwQ"
|
| 20 |
|
| 21 |
# -------------------- UTILS --------------------
|
|
|
|
| 28 |
if not data:
|
| 29 |
return pd.DataFrame()
|
| 30 |
raw_header, *rows = data
|
|
|
|
| 31 |
counts = Counter()
|
| 32 |
header = []
|
| 33 |
for col in raw_header:
|
|
|
|
| 165 |
|
| 166 |
def quote_month_choices(year=None):
|
| 167 |
df = get_quotes_df()
|
| 168 |
+
# Always return a list (possibly empty)
|
| 169 |
+
if (
|
| 170 |
+
year
|
| 171 |
+
and "Year" in df.columns
|
| 172 |
+
and "Month" in df.columns
|
| 173 |
+
and not df.empty
|
| 174 |
+
):
|
| 175 |
+
subset = df[df["Year"].astype(str) == str(year)]
|
| 176 |
+
months = pd.to_numeric(subset["Month"], errors="coerce").dropna().astype(int).unique()
|
| 177 |
+
# Keep months only 1-12
|
| 178 |
+
months = sorted(set(str(m) for m in months if 1 <= m <= 12))
|
| 179 |
return months
|
| 180 |
return []
|
| 181 |
|
|
|
|
| 265 |
|
| 266 |
# Dynamic month options for summary
|
| 267 |
def update_month_choices_summary(year):
|
| 268 |
+
months = quote_month_choices(year) if year else []
|
| 269 |
+
return gr.Dropdown.update(choices=[""] + months, value="")
|
|
|
|
|
|
|
| 270 |
year_qs.change(update_month_choices_summary, year_qs, month_qs)
|
| 271 |
|
| 272 |
def quotes_summary_wrapper(year, month):
|
|
|
|
| 282 |
|
| 283 |
# Dynamic month options for rep quotes
|
| 284 |
def update_month_choices(year):
|
| 285 |
+
months = quote_month_choices(year) if year else []
|
| 286 |
+
return gr.Dropdown.update(choices=[""] + months, value="")
|
|
|
|
|
|
|
| 287 |
year_q.change(update_month_choices, year_q, month_q)
|
| 288 |
|
| 289 |
def get_rep_quotes_filtered_wrapper(rep, year, month):
|