"""The few facts the site may state about itself before anybody signs in. Counts only, and only of published material. No titles, no ids, nothing that could be walked to enumerate the bank — a landing page needs to say how much there is, not what it is. Unauthenticated on purpose: it is read by the page a stranger lands on. """ from fastapi import APIRouter, Depends from sqlalchemy import func from sqlalchemy.orm import Session from app.database import get_db from app.models.article import Article from app.models.exam import Exam from app.models.question import Question from app.models.question_category import QuestionCategory router = APIRouter() @router.get("/stats") def public_stats(db: Session = Depends(get_db)): """What the landing page says there is, taken from what there is. A number written into the markup is a number that goes stale the week after it is written, and nobody notices because nothing breaks. """ questions = db.query(func.count(Question.id)).filter( Question.deleted_at.is_(None)).scalar() or 0 topics = db.query(func.count(QuestionCategory.id)).scalar() or 0 systems = db.query(func.count(func.distinct(QuestionCategory.system_id))).filter( QuestionCategory.system_id.isnot(None)).scalar() or 0 articles = db.query(func.count(Article.id)).filter( Article.status == "published").scalar() or 0 exams = db.query(func.count(Exam.id)).filter(Exam.is_active == 1).scalar() or 0 return { "questions": questions, "topics": topics, "systems": systems, "articles": articles, "exams": exams, }