Spaces:
Paused
Paused
CBV01 commited on
Commit ·
fc44113
1
Parent(s): bfaa533
Refine dashboard metrics: Messages Sent now reflects total delivered count, and Leads reflects combined groups/members
Browse files- backend/main.py +9 -8
backend/main.py
CHANGED
|
@@ -2528,7 +2528,7 @@ async def get_dashboard_stats(user_id: str = Depends(get_current_user_id)):
|
|
| 2528 |
c_members = conn.execute("SELECT COUNT(*) FROM leads").fetchone()[0]
|
| 2529 |
total_leads = c_scraped + c_members
|
| 2530 |
pending_tasks = conn.execute("SELECT COUNT(*) FROM tasks WHERE status = 'pending'").fetchone()[0]
|
| 2531 |
-
messages_sent = conn.execute("SELECT
|
| 2532 |
|
| 2533 |
tasks_rows = conn.execute(
|
| 2534 |
"SELECT phone_number, status, message_text, scheduled_time FROM tasks ORDER BY scheduled_time DESC LIMIT 5"
|
|
@@ -2538,19 +2538,20 @@ async def get_dashboard_stats(user_id: str = Depends(get_current_user_id)):
|
|
| 2538 |
for i in range(6, -1, -1):
|
| 2539 |
day = (datetime.now() - timedelta(days=i)).strftime('%Y-%m-%d')
|
| 2540 |
count = conn.execute(
|
| 2541 |
-
"SELECT
|
| 2542 |
(f"{day}%",)
|
| 2543 |
-
).fetchone()[0]
|
| 2544 |
trends.append(count)
|
| 2545 |
else:
|
| 2546 |
# Core counts for regular user
|
| 2547 |
total_accounts = conn.execute("SELECT COUNT(*) FROM accounts WHERE user_id = ? AND status = 'active'", (user_id,)).fetchone()[0]
|
| 2548 |
-
|
| 2549 |
# Dashboard leads should strictly match what the user sees in the Leads page
|
| 2550 |
-
|
|
|
|
|
|
|
| 2551 |
|
| 2552 |
pending_tasks = conn.execute("SELECT COUNT(*) FROM tasks WHERE user_id = ? AND status = 'pending'", (user_id,)).fetchone()[0]
|
| 2553 |
-
messages_sent = conn.execute("SELECT
|
| 2554 |
|
| 2555 |
tasks_rows = conn.execute(
|
| 2556 |
"SELECT phone_number, status, message_text, scheduled_time FROM tasks WHERE user_id = ? ORDER BY scheduled_time DESC LIMIT 5",
|
|
@@ -2561,9 +2562,9 @@ async def get_dashboard_stats(user_id: str = Depends(get_current_user_id)):
|
|
| 2561 |
for i in range(6, -1, -1):
|
| 2562 |
day = (datetime.now() - timedelta(days=i)).strftime('%Y-%m-%d')
|
| 2563 |
count = conn.execute(
|
| 2564 |
-
"SELECT
|
| 2565 |
(user_id, f"{day}%")
|
| 2566 |
-
).fetchone()[0]
|
| 2567 |
trends.append(count)
|
| 2568 |
|
| 2569 |
service_health = {
|
|
|
|
| 2528 |
c_members = conn.execute("SELECT COUNT(*) FROM leads").fetchone()[0]
|
| 2529 |
total_leads = c_scraped + c_members
|
| 2530 |
pending_tasks = conn.execute("SELECT COUNT(*) FROM tasks WHERE status = 'pending'").fetchone()[0]
|
| 2531 |
+
messages_sent = conn.execute("SELECT SUM(sent_count) FROM tasks").fetchone()[0] or 0
|
| 2532 |
|
| 2533 |
tasks_rows = conn.execute(
|
| 2534 |
"SELECT phone_number, status, message_text, scheduled_time FROM tasks ORDER BY scheduled_time DESC LIMIT 5"
|
|
|
|
| 2538 |
for i in range(6, -1, -1):
|
| 2539 |
day = (datetime.now() - timedelta(days=i)).strftime('%Y-%m-%d')
|
| 2540 |
count = conn.execute(
|
| 2541 |
+
"SELECT SUM(sent_count) FROM tasks WHERE scheduled_time LIKE ?",
|
| 2542 |
(f"{day}%",)
|
| 2543 |
+
).fetchone()[0] or 0
|
| 2544 |
trends.append(count)
|
| 2545 |
else:
|
| 2546 |
# Core counts for regular user
|
| 2547 |
total_accounts = conn.execute("SELECT COUNT(*) FROM accounts WHERE user_id = ? AND status = 'active'", (user_id,)).fetchone()[0]
|
|
|
|
| 2548 |
# Dashboard leads should strictly match what the user sees in the Leads page
|
| 2549 |
+
c_scraped = conn.execute("SELECT COUNT(*) FROM scraped_groups WHERE user_id = ?", (user_id,)).fetchone()[0]
|
| 2550 |
+
c_members = conn.execute("SELECT COUNT(*) FROM leads WHERE user_id = ?", (user_id,)).fetchone()[0]
|
| 2551 |
+
total_leads = c_scraped + c_members
|
| 2552 |
|
| 2553 |
pending_tasks = conn.execute("SELECT COUNT(*) FROM tasks WHERE user_id = ? AND status = 'pending'", (user_id,)).fetchone()[0]
|
| 2554 |
+
messages_sent = conn.execute("SELECT SUM(sent_count) FROM tasks WHERE user_id = ?", (user_id,)).fetchone()[0] or 0
|
| 2555 |
|
| 2556 |
tasks_rows = conn.execute(
|
| 2557 |
"SELECT phone_number, status, message_text, scheduled_time FROM tasks WHERE user_id = ? ORDER BY scheduled_time DESC LIMIT 5",
|
|
|
|
| 2562 |
for i in range(6, -1, -1):
|
| 2563 |
day = (datetime.now() - timedelta(days=i)).strftime('%Y-%m-%d')
|
| 2564 |
count = conn.execute(
|
| 2565 |
+
"SELECT SUM(sent_count) FROM tasks WHERE user_id = ? AND scheduled_time LIKE ?",
|
| 2566 |
(user_id, f"{day}%")
|
| 2567 |
+
).fetchone()[0] or 0
|
| 2568 |
trends.append(count)
|
| 2569 |
|
| 2570 |
service_health = {
|