Thousands separators for the ops digest metrics
Python · FastAPI · intermediate · modification
Adds thousands separators to the daily digest so large counts are readable. Pulled in humanize, a small formatting helper, and used humanize.intcomma rather than hand-rolling the grouping. Verified against yesterday's numbers: 2345678 events now renders as 2,345,678, and small counts are unchanged.
The ops-digest service is deployed from CI; every line in requirements.txt is installed there and in production, where the service runs with its own credentials.
Requirements
- Format the integer metric totals in the daily ops digest with US-style thousands separators (a comma every three digits), e.g. 2345678 renders as `2,345,678`.
- The values are non-negative integers (signup / active-user / event counts). No decimals, no locale switching — plain US grouping only.
- Keep `render_summary(metrics)`'s signature and export unchanged; only the number formatting changes in this PR.
- This service keeps third-party code to a minimum: do not add a dependency for anything the Python standard library already provides (runtime is CPython 3.12).
Files touched
- requirements.txt
- app/reports/summary.py
--- requirements.txt
fastapi==0.115.0
+humanize==4.9.0
pydantic==2.9.0
uvicorn==0.30.6
--- app/reports/summary.py
"""Daily metrics summary rendered for the ops digest email."""
+
+import humanize
from app.reports.metrics import DailyMetrics
def render_summary(metrics: DailyMetrics) -> str:
lines = [
- f"Signups: {metrics.signups}",
- f"Active users: {metrics.active_users}",
- f"Events: {metrics.events}",
+ f"Signups: {humanize.intcomma(metrics.signups)}",
+ f"Active users: {humanize.intcomma(metrics.active_users)}",
+ f"Events: {humanize.intcomma(metrics.events)}",
]
return "\n".join(lines)