IAMTFRMZA commited on
Commit
bc61590
Β·
verified Β·
1 Parent(s): 2f4c490

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -48
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 compose_date(year, month, day):
29
- try:
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[column] >= start) & (df[column] <= end)]
38
- if rep:
39
- filtered = filtered[filtered['Rep'].fillna('').str.lower() == rep.lower()]
40
  return filtered
41
 
42
- def filter_by_date(df, column, y, m, d, rep=None):
43
- date_str = compose_date(y, m, d)
44
- if not date_str:
45
- return pd.DataFrame([{"Error": "Invalid date"}])
46
- df[column] = pd.to_datetime(df[column], errors='coerce').dt.date.astype(str)
47
- result = df[df[column] == date_str]
48
- if rep:
49
- result = result[result['Rep'].fillna('').str.lower() == rep.lower()]
50
- return result
 
51
 
52
  # -------------------- FUNCTIONS --------------------
53
- def current_week_calls(rep=None):
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 current_week_appointments(rep=None):
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 custom_date_calls(y, m, d, rep=None):
66
  df = load_sheet("Calls")
67
- return filter_by_date(df, "Call Date", y, m, d, rep)
 
 
68
 
69
- def custom_date_appointments(y, m, d, rep=None):
70
  df = load_sheet("Appointments")
71
- return filter_by_date(df, "Appointment Date", y, m, d, rep)
 
 
72
 
73
- def appointed_leads():
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("## πŸ“… Graffiti Admin Dashboard")
82
 
83
  with gr.Tab("Calls Report"):
84
- calls_rep = gr.Textbox(label="Optional Rep Filter")
85
  calls_btn = gr.Button("Load Current Week Calls")
86
  calls_table = gr.Dataframe()
87
- calls_btn.click(fn=current_week_calls, inputs=calls_rep, outputs=calls_table)
88
 
89
  gr.Markdown("### πŸ” Search Calls by Specific Date")
90
- y, m, d = gr.Textbox(label="Year"), gr.Textbox(label="Month"), gr.Textbox(label="Day")
91
- call_rep = gr.Textbox(label="Optional Rep Filter")
92
- date_calls_btn = gr.Button("Search Calls by Date")
93
- date_calls_table = gr.Dataframe()
94
- date_calls_btn.click(fn=custom_date_calls, inputs=[y, m, d, call_rep], outputs=date_calls_table)
95
 
96
  with gr.Tab("Appointments Report"):
97
- appt_rep = gr.Textbox(label="Optional Rep Filter")
98
  appt_btn = gr.Button("Load Current Week Appointments")
99
  appt_table = gr.Dataframe()
100
- appt_btn.click(fn=current_week_appointments, inputs=appt_rep, outputs=appt_table)
101
 
102
  gr.Markdown("### πŸ” Search Appointments by Specific Date")
103
- ay, am, ad = gr.Textbox(label="Year"), gr.Textbox(label="Month"), gr.Textbox(label="Day")
104
- appt_rep2 = gr.Textbox(label="Optional Rep Filter")
105
- date_appt_btn = gr.Button("Search Appointments by Date")
106
- date_appt_table = gr.Dataframe()
107
- date_appt_btn.click(fn=custom_date_appointments, inputs=[ay, am, ad, appt_rep2], outputs=date_appt_table)
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=appointed_leads, outputs=leads_table)
113
 
114
- app.launch(share=True)
 
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()