Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -164,6 +164,9 @@ def quote_year_choices():
|
|
164 |
return []
|
165 |
|
166 |
def quote_month_choices(year=None):
|
|
|
|
|
|
|
167 |
df = get_quotes_df()
|
168 |
if (
|
169 |
year
|
@@ -172,11 +175,13 @@ def quote_month_choices(year=None):
|
|
172 |
and not df.empty
|
173 |
):
|
174 |
subset = df[df["Year"].astype(str) == str(year)]
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
|
|
|
|
180 |
|
181 |
def quotes_summary(year=None, month=None):
|
182 |
df = get_quotes_df()
|
@@ -207,6 +212,14 @@ def get_rep_quotes_filtered(rep, year=None, month=None):
|
|
207 |
df = df[df["Month"].astype(str) == str(month)]
|
208 |
return df
|
209 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
210 |
# -------------------- UI LAYOUT --------------------
|
211 |
with gr.Blocks(title="Graffiti Admin Dashboard") as app:
|
212 |
gr.Markdown("# 📆 Graffiti Admin Dashboard")
|
@@ -263,12 +276,6 @@ with gr.Blocks(title="Graffiti Admin Dashboard") as app:
|
|
263 |
sum_qs = gr.Dataframe(label="Summary by Rep")
|
264 |
|
265 |
# Dynamic month options for summary
|
266 |
-
def update_month_choices_summary(year):
|
267 |
-
try:
|
268 |
-
months = quote_month_choices(year) if year else []
|
269 |
-
return gr.Dropdown.update(choices=[""] + months, value="")
|
270 |
-
except:
|
271 |
-
return gr.Dropdown.update(choices=[""], value="")
|
272 |
year_qs.change(update_month_choices_summary, year_qs, month_qs)
|
273 |
|
274 |
def quotes_summary_wrapper(year, month):
|
@@ -283,12 +290,6 @@ with gr.Blocks(title="Graffiti Admin Dashboard") as app:
|
|
283 |
tbl_qr = gr.Dataframe(label="Quotes for Selection")
|
284 |
|
285 |
# Dynamic month options for rep quotes
|
286 |
-
def update_month_choices(year):
|
287 |
-
try:
|
288 |
-
months = quote_month_choices(year) if year else []
|
289 |
-
return gr.Dropdown.update(choices=[""] + months, value="")
|
290 |
-
except:
|
291 |
-
return gr.Dropdown.update(choices=[""], value="")
|
292 |
year_q.change(update_month_choices, year_q, month_q)
|
293 |
|
294 |
def get_rep_quotes_filtered_wrapper(rep, year, month):
|
|
|
164 |
return []
|
165 |
|
166 |
def quote_month_choices(year=None):
|
167 |
+
"""
|
168 |
+
Returns a sorted list of valid month strings for a given year, or [''] if none.
|
169 |
+
"""
|
170 |
df = get_quotes_df()
|
171 |
if (
|
172 |
year
|
|
|
175 |
and not df.empty
|
176 |
):
|
177 |
subset = df[df["Year"].astype(str) == str(year)]
|
178 |
+
try:
|
179 |
+
months = pd.to_numeric(subset["Month"], errors="coerce").dropna().astype(int)
|
180 |
+
months = sorted({str(m) for m in months if 1 <= m <= 12})
|
181 |
+
return months if months else [""]
|
182 |
+
except Exception:
|
183 |
+
return [""]
|
184 |
+
return [""]
|
185 |
|
186 |
def quotes_summary(year=None, month=None):
|
187 |
df = get_quotes_df()
|
|
|
212 |
df = df[df["Month"].astype(str) == str(month)]
|
213 |
return df
|
214 |
|
215 |
+
def update_month_choices_summary(year):
|
216 |
+
months = quote_month_choices(year)
|
217 |
+
return gr.Dropdown.update(choices=months, value="")
|
218 |
+
|
219 |
+
def update_month_choices(year):
|
220 |
+
months = quote_month_choices(year)
|
221 |
+
return gr.Dropdown.update(choices=months, value="")
|
222 |
+
|
223 |
# -------------------- UI LAYOUT --------------------
|
224 |
with gr.Blocks(title="Graffiti Admin Dashboard") as app:
|
225 |
gr.Markdown("# 📆 Graffiti Admin Dashboard")
|
|
|
276 |
sum_qs = gr.Dataframe(label="Summary by Rep")
|
277 |
|
278 |
# Dynamic month options for summary
|
|
|
|
|
|
|
|
|
|
|
|
|
279 |
year_qs.change(update_month_choices_summary, year_qs, month_qs)
|
280 |
|
281 |
def quotes_summary_wrapper(year, month):
|
|
|
290 |
tbl_qr = gr.Dataframe(label="Quotes for Selection")
|
291 |
|
292 |
# Dynamic month options for rep quotes
|
|
|
|
|
|
|
|
|
|
|
|
|
293 |
year_q.change(update_month_choices, year_q, month_q)
|
294 |
|
295 |
def get_rep_quotes_filtered_wrapper(rep, year, month):
|