Add analysis status panel to admin page
- GET /api/admin/stats returns total bills, docs fetched, briefs generated (full + amendment), and remaining count - Admin page shows stat cards + progress bar, auto-refreshes every 30s Authored-By: Jack Levy
This commit is contained in:
@@ -4,7 +4,7 @@ from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.core.dependencies import get_current_admin
|
||||
from app.database import get_db
|
||||
from app.models import Follow
|
||||
from app.models import Bill, BillBrief, BillDocument, Follow
|
||||
from app.models.user import User
|
||||
from app.schemas.schemas import UserResponse
|
||||
|
||||
@@ -79,6 +79,35 @@ async def toggle_admin(
|
||||
return user
|
||||
|
||||
|
||||
# ── Analysis Stats ────────────────────────────────────────────────────────────
|
||||
|
||||
@router.get("/stats")
|
||||
async def get_stats(
|
||||
db: AsyncSession = Depends(get_db),
|
||||
current_user: User = Depends(get_current_admin),
|
||||
):
|
||||
"""Return analysis pipeline progress counters."""
|
||||
total_bills = (await db.execute(select(func.count()).select_from(Bill))).scalar()
|
||||
docs_fetched = (await db.execute(
|
||||
select(func.count()).select_from(BillDocument).where(BillDocument.raw_text.isnot(None))
|
||||
)).scalar()
|
||||
total_briefs = (await db.execute(select(func.count()).select_from(BillBrief))).scalar()
|
||||
full_briefs = (await db.execute(
|
||||
select(func.count()).select_from(BillBrief).where(BillBrief.brief_type == "full")
|
||||
)).scalar()
|
||||
amendment_briefs = (await db.execute(
|
||||
select(func.count()).select_from(BillBrief).where(BillBrief.brief_type == "amendment")
|
||||
)).scalar()
|
||||
return {
|
||||
"total_bills": total_bills,
|
||||
"docs_fetched": docs_fetched,
|
||||
"briefs_generated": total_briefs,
|
||||
"full_briefs": full_briefs,
|
||||
"amendment_briefs": amendment_briefs,
|
||||
"remaining": total_bills - total_briefs,
|
||||
}
|
||||
|
||||
|
||||
# ── Celery Tasks ──────────────────────────────────────────────────────────────
|
||||
|
||||
@router.post("/trigger-poll")
|
||||
|
||||
Reference in New Issue
Block a user