Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -25,90 +25,96 @@ def get_current_week_range():
|
|
25 |
end = start + timedelta(days=6)
|
26 |
return start.date(), end.date()
|
27 |
|
28 |
-
def
|
29 |
-
|
30 |
-
return str(datetime(int(year), int(month), int(day)).date())
|
31 |
-
except:
|
32 |
-
return None
|
33 |
-
|
34 |
-
def filter_week(df, column, rep=None):
|
35 |
-
df[column] = pd.to_datetime(df[column], errors='coerce').dt.date
|
36 |
start, end = get_current_week_range()
|
37 |
-
filtered = df[(df[
|
38 |
-
if rep:
|
39 |
-
filtered = filtered[filtered[
|
40 |
return filtered
|
41 |
|
42 |
-
def
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
|
|
51 |
|
52 |
# -------------------- FUNCTIONS --------------------
|
53 |
-
def
|
54 |
df = load_sheet("Calls")
|
55 |
if "Call Date" not in df.columns:
|
56 |
return pd.DataFrame([{"Error": "Missing 'Call Date' column"}])
|
57 |
-
return filter_week(df, "Call Date", rep)
|
58 |
|
59 |
-
def
|
60 |
df = load_sheet("Appointments")
|
61 |
if "Appointment Date" not in df.columns:
|
62 |
return pd.DataFrame([{"Error": "Missing 'Appointment Date' column"}])
|
63 |
-
return filter_week(df, "Appointment Date", rep)
|
64 |
|
65 |
-
def
|
66 |
df = load_sheet("Calls")
|
67 |
-
|
|
|
|
|
68 |
|
69 |
-
def
|
70 |
df = load_sheet("Appointments")
|
71 |
-
|
|
|
|
|
72 |
|
73 |
-
def
|
74 |
df = load_sheet("AllocatedLeads")
|
75 |
-
if "Assigned Rep" not in df.columns or "Company Name" not in df.columns:
|
76 |
return pd.DataFrame([{"Error": "Missing 'Assigned Rep' or 'Company Name' column"}])
|
77 |
-
return df.groupby("Assigned Rep")["Company Name"].apply(list).reset_index()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
|
79 |
# -------------------- UI --------------------
|
80 |
with gr.Blocks(title="Graffiti Admin Dashboard") as app:
|
81 |
-
gr.Markdown("
|
82 |
|
83 |
with gr.Tab("Calls Report"):
|
84 |
-
|
85 |
calls_btn = gr.Button("Load Current Week Calls")
|
86 |
calls_table = gr.Dataframe()
|
87 |
-
calls_btn.click(fn=
|
88 |
|
89 |
gr.Markdown("### π Search Calls by Specific Date")
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
|
96 |
with gr.Tab("Appointments Report"):
|
97 |
-
|
98 |
appt_btn = gr.Button("Load Current Week Appointments")
|
99 |
appt_table = gr.Dataframe()
|
100 |
-
appt_btn.click(fn=
|
101 |
|
102 |
gr.Markdown("### π Search Appointments by Specific Date")
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
|
109 |
with gr.Tab("Appointed Leads"):
|
110 |
leads_btn = gr.Button("View Appointed Leads")
|
111 |
leads_table = gr.Dataframe()
|
112 |
-
leads_btn.click(fn=
|
113 |
|
114 |
-
app.launch(
|
|
|
25 |
end = start + timedelta(days=6)
|
26 |
return start.date(), end.date()
|
27 |
|
28 |
+
def filter_week(df, date_column, rep_column=None, rep=None):
|
29 |
+
df[date_column] = pd.to_datetime(df[date_column], errors='coerce').dt.date
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
start, end = get_current_week_range()
|
31 |
+
filtered = df[(df[date_column] >= start) & (df[date_column] <= end)]
|
32 |
+
if rep and rep.strip():
|
33 |
+
filtered = filtered[filtered[rep_column] == rep]
|
34 |
return filtered
|
35 |
|
36 |
+
def filter_date(df, date_column, rep_column, y, m, d, rep):
|
37 |
+
try:
|
38 |
+
date_str = str(datetime(int(y), int(m), int(d)).date())
|
39 |
+
except:
|
40 |
+
return pd.DataFrame([{"Error": "Invalid date input"}])
|
41 |
+
df[date_column] = pd.to_datetime(df[date_column], errors='coerce').dt.date.astype(str)
|
42 |
+
filtered = df[df[date_column] == date_str]
|
43 |
+
if rep and rep.strip():
|
44 |
+
filtered = filtered[df[rep_column] == rep]
|
45 |
+
return filtered
|
46 |
|
47 |
# -------------------- FUNCTIONS --------------------
|
48 |
+
def get_calls(rep=None):
|
49 |
df = load_sheet("Calls")
|
50 |
if "Call Date" not in df.columns:
|
51 |
return pd.DataFrame([{"Error": "Missing 'Call Date' column"}])
|
52 |
+
return filter_week(df, "Call Date", "Rep", rep)
|
53 |
|
54 |
+
def get_appointments(rep=None):
|
55 |
df = load_sheet("Appointments")
|
56 |
if "Appointment Date" not in df.columns:
|
57 |
return pd.DataFrame([{"Error": "Missing 'Appointment Date' column"}])
|
58 |
+
return filter_week(df, "Appointment Date", "Rep", rep)
|
59 |
|
60 |
+
def search_calls_by_date(y, m, d, rep):
|
61 |
df = load_sheet("Calls")
|
62 |
+
if "Call Date" not in df.columns:
|
63 |
+
return pd.DataFrame([{"Error": "Missing 'Call Date' column"}])
|
64 |
+
return filter_date(df, "Call Date", "Rep", y, m, d, rep)
|
65 |
|
66 |
+
def search_appointments_by_date(y, m, d, rep):
|
67 |
df = load_sheet("Appointments")
|
68 |
+
if "Appointment Date" not in df.columns:
|
69 |
+
return pd.DataFrame([{"Error": "Missing 'Appointment Date' column"}])
|
70 |
+
return filter_date(df, "Appointment Date", "Rep", y, m, d, rep)
|
71 |
|
72 |
+
def get_leads():
|
73 |
df = load_sheet("AllocatedLeads")
|
74 |
+
if "Assigned Rep " not in df.columns or "Company Name" not in df.columns:
|
75 |
return pd.DataFrame([{"Error": "Missing 'Assigned Rep' or 'Company Name' column"}])
|
76 |
+
return df.groupby("Assigned Rep ")["Company Name"].apply(list).reset_index()
|
77 |
+
|
78 |
+
# -------------------- DROPDOWN OPTIONS --------------------
|
79 |
+
def rep_options(sheet_name, rep_col):
|
80 |
+
df = load_sheet(sheet_name)
|
81 |
+
if rep_col in df.columns:
|
82 |
+
return sorted(df[rep_col].dropna().unique().tolist())
|
83 |
+
return []
|
84 |
|
85 |
# -------------------- UI --------------------
|
86 |
with gr.Blocks(title="Graffiti Admin Dashboard") as app:
|
87 |
+
gr.Markdown("# π Graffiti Admin Dashboard")
|
88 |
|
89 |
with gr.Tab("Calls Report"):
|
90 |
+
rep_calls = gr.Dropdown(label="Optional Rep Filter", choices=rep_options("Calls", "Rep"), allow_custom_value=True)
|
91 |
calls_btn = gr.Button("Load Current Week Calls")
|
92 |
calls_table = gr.Dataframe()
|
93 |
+
calls_btn.click(fn=get_calls, inputs=rep_calls, outputs=calls_table)
|
94 |
|
95 |
gr.Markdown("### π Search Calls by Specific Date")
|
96 |
+
y1, m1, d1 = gr.Textbox(label="Year"), gr.Textbox(label="Month"), gr.Textbox(label="Day")
|
97 |
+
rep1 = gr.Dropdown(label="Optional Rep Filter", choices=rep_options("Calls", "Rep"), allow_custom_value=True)
|
98 |
+
calls_date_btn = gr.Button("Search Calls by Date")
|
99 |
+
calls_date_table = gr.Dataframe()
|
100 |
+
calls_date_btn.click(fn=search_calls_by_date, inputs=[y1, m1, d1, rep1], outputs=calls_date_table)
|
101 |
|
102 |
with gr.Tab("Appointments Report"):
|
103 |
+
rep_appt = gr.Dropdown(label="Optional Rep Filter", choices=rep_options("Appointments", "Rep"), allow_custom_value=True)
|
104 |
appt_btn = gr.Button("Load Current Week Appointments")
|
105 |
appt_table = gr.Dataframe()
|
106 |
+
appt_btn.click(fn=get_appointments, inputs=rep_appt, outputs=appt_table)
|
107 |
|
108 |
gr.Markdown("### π Search Appointments by Specific Date")
|
109 |
+
y2, m2, d2 = gr.Textbox(label="Year"), gr.Textbox(label="Month"), gr.Textbox(label="Day")
|
110 |
+
rep2 = gr.Dropdown(label="Optional Rep Filter", choices=rep_options("Appointments", "Rep"), allow_custom_value=True)
|
111 |
+
appt_date_btn = gr.Button("Search Appointments by Date")
|
112 |
+
appt_date_table = gr.Dataframe()
|
113 |
+
appt_date_btn.click(fn=search_appointments_by_date, inputs=[y2, m2, d2, rep2], outputs=appt_date_table)
|
114 |
|
115 |
with gr.Tab("Appointed Leads"):
|
116 |
leads_btn = gr.Button("View Appointed Leads")
|
117 |
leads_table = gr.Dataframe()
|
118 |
+
leads_btn.click(fn=get_leads, outputs=leads_table)
|
119 |
|
120 |
+
app.launch()
|