IAMTFRMZA commited on
Commit
4fc9ed6
Β·
verified Β·
1 Parent(s): f68916e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -0
app.py CHANGED
@@ -42,6 +42,36 @@ def refresh_data():
42
 
43
  return df
44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  # ------------------ DASHBOARD FUNCTIONS ------------------
46
  def generate_summary(date_str):
47
  df = refresh_data()
@@ -158,6 +188,14 @@ with gr.Blocks() as app:
158
  date_picker.change(fn=get_reps, inputs=date_picker, outputs=rep_picker)
159
  btn.click(fn=show_map, inputs=[date_picker, rep_picker], outputs=[table, map_plot])
160
 
 
 
 
 
 
 
 
 
161
  def do_login(user, pw):
162
  if VALID_USERS.get(user) == pw:
163
  return gr.update(visible=False), gr.update(visible=True), ""
 
42
 
43
  return df
44
 
45
+ # ------------------ DEALER ESCALATIONS DATA FUNCTION ------------------
46
+ def get_dealer_escalations():
47
+ dealers_sheet = client.open_by_url(sheet_url).worksheet("Dealers")
48
+ dealers_data = dealers_sheet.get_all_records()
49
+ dealers_df = pd.DataFrame(dealers_data)
50
+
51
+ # Standardize column names (in case of different casing/spacing)
52
+ dealers_df.columns = [c.strip() for c in dealers_df.columns]
53
+
54
+ # Filter for rows where Escalate Dealer == 'yes' (case-insensitive)
55
+ mask = dealers_df['Escalate Dealer'].str.strip().str.lower() == 'yes'
56
+ filtered_df = dealers_df.loc[mask, [
57
+ 'Dealership Name',
58
+ 'Rep Name',
59
+ 'Escalate Dealer',
60
+ 'Escalation Comment'
61
+ ]]
62
+
63
+ # Optional: Sort by Rep Name and Dealership Name
64
+ filtered_df = filtered_df.sort_values(by=['Rep Name', 'Dealership Name'])
65
+
66
+ # If there are no escalations, show a friendly empty DataFrame
67
+ if filtered_df.empty:
68
+ filtered_df = pd.DataFrame(
69
+ [["No dealer escalations found.", "", "", ""]],
70
+ columns=['Dealership Name', 'Rep Name', 'Escalate Dealer', 'Escalation Comment']
71
+ )
72
+
73
+ return filtered_df
74
+
75
  # ------------------ DASHBOARD FUNCTIONS ------------------
76
  def generate_summary(date_str):
77
  df = refresh_data()
 
188
  date_picker.change(fn=get_reps, inputs=date_picker, outputs=rep_picker)
189
  btn.click(fn=show_map, inputs=[date_picker, rep_picker], outputs=[table, map_plot])
190
 
191
+ with gr.Tab("🚨 Dealer Escalations"):
192
+ gr.Markdown("### 🚨 Dealer Escalations (Only showing escalated dealers)")
193
+ escalations_df = gr.Dataframe(value=get_dealer_escalations, label="Escalated Dealers", interactive=False)
194
+ refresh_btn = gr.Button("πŸ”„ Refresh Escalations")
195
+
196
+ # Refreshes the dataframe on button click
197
+ refresh_btn.click(fn=get_dealer_escalations, outputs=escalations_df)
198
+
199
  def do_login(user, pw):
200
  if VALID_USERS.get(user) == pw:
201
  return gr.update(visible=False), gr.update(visible=True), ""