diff --git a/app/routers/web.py b/app/routers/web.py index 95a45b8..21b3bb2 100644 --- a/app/routers/web.py +++ b/app/routers/web.py @@ -397,12 +397,18 @@ def dashboard(request: Request, user: User = Depends(get_current_user_web), db: else: sent_pct = delivered_pct = received_pct = 0 - # country stats - country_counts: dict[str, int] = {} + # country stats split by sent/received + sent_country_counts: dict[str, int] = {} + received_country_counts: dict[str, int] = {} for c in all_cards: - if c.country: - country_counts[c.country] = country_counts.get(c.country, 0) + 1 - country_stats = sorted(country_counts.items(), key=lambda x: -x[1]) + if not c.country: + continue + if c.status in ("sent", "delivered"): + sent_country_counts[c.country] = sent_country_counts.get(c.country, 0) + 1 + elif c.status == "received": + received_country_counts[c.country] = received_country_counts.get(c.country, 0) + 1 + sent_country_stats = sorted(sent_country_counts.items(), key=lambda x: -x[1]) + received_country_stats = sorted(received_country_counts.items(), key=lambda x: -x[1]) from datetime import datetime, timezone as _tz @@ -411,7 +417,7 @@ def dashboard(request: Request, user: User = Depends(get_current_user_web), db: "total": total, "sent": sent, "delivered": delivered, "received": received, "countries": countries, "recent": recent, "sent_pct": sent_pct, "delivered_pct": delivered_pct, "received_pct": received_pct, - "country_stats": country_stats, + "sent_country_stats": sent_country_stats, "received_country_stats": received_country_stats, "now": datetime.now(_tz.utc), }) diff --git a/app/templates/dashboard.html b/app/templates/dashboard.html index a41dec7..af6f365 100644 --- a/app/templates/dashboard.html +++ b/app/templates/dashboard.html @@ -59,33 +59,43 @@ {% endif %} -{% if country_stats %} +{% if sent_country_stats or received_country_stats %} -