Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -15,7 +15,7 @@ VALID_USERS = {
|
|
15 |
scope = ["https://spreadsheets.google.com/feeds", "https://www.googleapis.com/auth/drive"]
|
16 |
creds = ServiceAccountCredentials.from_json_keyfile_name("credentials.json", scope)
|
17 |
client = gspread.authorize(creds)
|
18 |
-
sheet_file = client.open("userAccess")
|
19 |
|
20 |
# ------------------ HELPERS ------------------
|
21 |
def load_tab(sheet_name):
|
@@ -42,13 +42,19 @@ def generate_summary(date_str):
|
|
42 |
day_df = df[df['DateStr'] == date_str]
|
43 |
|
44 |
total_visits = day_df.groupby("Rep").size().reset_index(name="Total Visits")
|
45 |
-
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
47 |
breakdown = pd.DataFrame({
|
48 |
"Rep": all_reps,
|
49 |
"Current": [len(current[current["Rep"] == rep]) for rep in all_reps],
|
50 |
"Prospect": [len(prospect[prospect["Rep"] == rep]) for rep in all_reps]
|
51 |
})
|
|
|
52 |
active_list = total_visits['Rep'].tolist()
|
53 |
inactive_list = [rep for rep in all_reps if rep not in active_list]
|
54 |
inactive_df = pd.DataFrame({'Inactive Reps': inactive_list})
|
@@ -57,6 +63,10 @@ def generate_summary(date_str):
|
|
57 |
def get_order_summary(date_str):
|
58 |
df = load_field_sales()
|
59 |
day_df = df[df['DateStr'] == date_str]
|
|
|
|
|
|
|
|
|
60 |
rep_group = day_df.groupby("Rep").agg({
|
61 |
"Order Received": lambda x: (x == "Yes").sum(),
|
62 |
"Order Value": "sum"
|
@@ -68,8 +78,12 @@ def get_order_summary(date_str):
|
|
68 |
|
69 |
def get_escalations():
|
70 |
df = load_field_sales()
|
71 |
-
|
72 |
-
|
|
|
|
|
|
|
|
|
73 |
|
74 |
# ------------------ TELESALeS ------------------
|
75 |
def get_telesales_summary():
|
@@ -110,7 +124,6 @@ with gr.Blocks() as app:
|
|
110 |
with gr.Column(visible=False) as main_ui:
|
111 |
gr.Markdown("## 🗂️ CarMat Dashboard")
|
112 |
|
113 |
-
# preload dates for field sales
|
114 |
df_initial = load_field_sales()
|
115 |
unique_dates = sorted(df_initial["DateStr"].unique(), reverse=True)
|
116 |
|
|
|
15 |
scope = ["https://spreadsheets.google.com/feeds", "https://www.googleapis.com/auth/drive"]
|
16 |
creds = ServiceAccountCredentials.from_json_keyfile_name("credentials.json", scope)
|
17 |
client = gspread.authorize(creds)
|
18 |
+
sheet_file = client.open("userAccess") # Ensure this is the exact sheet name in Google Sheets
|
19 |
|
20 |
# ------------------ HELPERS ------------------
|
21 |
def load_tab(sheet_name):
|
|
|
42 |
day_df = df[df['DateStr'] == date_str]
|
43 |
|
44 |
total_visits = day_df.groupby("Rep").size().reset_index(name="Total Visits")
|
45 |
+
|
46 |
+
curr_col = "Current/Prospect Custor"
|
47 |
+
if curr_col not in df.columns:
|
48 |
+
df[curr_col] = ""
|
49 |
+
|
50 |
+
current = day_df[day_df[curr_col] == "Current"]
|
51 |
+
prospect = day_df[day_df[curr_col] == "Prospect"]
|
52 |
breakdown = pd.DataFrame({
|
53 |
"Rep": all_reps,
|
54 |
"Current": [len(current[current["Rep"] == rep]) for rep in all_reps],
|
55 |
"Prospect": [len(prospect[prospect["Rep"] == rep]) for rep in all_reps]
|
56 |
})
|
57 |
+
|
58 |
active_list = total_visits['Rep'].tolist()
|
59 |
inactive_list = [rep for rep in all_reps if rep not in active_list]
|
60 |
inactive_df = pd.DataFrame({'Inactive Reps': inactive_list})
|
|
|
63 |
def get_order_summary(date_str):
|
64 |
df = load_field_sales()
|
65 |
day_df = df[df['DateStr'] == date_str]
|
66 |
+
|
67 |
+
if "Order Received" not in df.columns:
|
68 |
+
df["Order Received"] = ""
|
69 |
+
|
70 |
rep_group = day_df.groupby("Rep").agg({
|
71 |
"Order Received": lambda x: (x == "Yes").sum(),
|
72 |
"Order Value": "sum"
|
|
|
78 |
|
79 |
def get_escalations():
|
80 |
df = load_field_sales()
|
81 |
+
col = "Customer Type & Status"
|
82 |
+
if col in df.columns:
|
83 |
+
flagged = df[df[col].str.contains("Second", na=False)]
|
84 |
+
return flagged if not flagged.empty else pd.DataFrame([["No second-hand dealerships flagged."]], columns=["Status"])
|
85 |
+
else:
|
86 |
+
return pd.DataFrame([["⚠️ Column 'Customer Type & Status' not found."]], columns=["Status"])
|
87 |
|
88 |
# ------------------ TELESALeS ------------------
|
89 |
def get_telesales_summary():
|
|
|
124 |
with gr.Column(visible=False) as main_ui:
|
125 |
gr.Markdown("## 🗂️ CarMat Dashboard")
|
126 |
|
|
|
127 |
df_initial = load_field_sales()
|
128 |
unique_dates = sorted(df_initial["DateStr"].unique(), reverse=True)
|
129 |
|