feat: dashboard & report APIs with real DB stats
Backend: - Add /dashboard/stats API (data_sources, tables, columns, labeled, sensitive, projects) - Add /dashboard/distribution API (level/cat/source distribution, project progress, heatmap) - Add /reports/stats API (total/auto/manual/reviewed counts + level distribution) - Fix report download: add template relationship to ClassificationProject - All stats computed from real DB queries Frontend: - Dashboard.vue: replace all hardcoded data with API-driven computed charts - Report.vue: replace all hardcoded data with API-driven charts - Add dashboard.ts and report.ts API clients
This commit is contained in:
@@ -1,14 +1,46 @@
|
||||
from fastapi import APIRouter, Depends, Response
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlalchemy import func
|
||||
|
||||
from app.core.database import get_db
|
||||
from app.models.user import User
|
||||
from app.services import report_service
|
||||
from app.models.project import ClassificationResult, ClassificationProject
|
||||
from app.models.classification import Category, DataLevel
|
||||
from app.schemas.common import ResponseModel
|
||||
from app.api.deps import get_current_user
|
||||
from app.services import report_service
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/stats")
|
||||
def get_report_stats(
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user),
|
||||
):
|
||||
"""Global report statistics."""
|
||||
total = db.query(ClassificationResult).count()
|
||||
auto = db.query(ClassificationResult).filter(ClassificationResult.source == 'auto').count()
|
||||
manual = db.query(ClassificationResult).filter(ClassificationResult.source == 'manual').count()
|
||||
reviewed = db.query(ClassificationResult).filter(ClassificationResult.status == 'reviewed').count()
|
||||
|
||||
# Level distribution
|
||||
level_dist = db.query(DataLevel.name, DataLevel.code, func.count(ClassificationResult.id)).\
|
||||
join(ClassificationResult, DataLevel.id == ClassificationResult.level_id).\
|
||||
group_by(DataLevel.id).order_by(DataLevel.sort_order).all()
|
||||
|
||||
return ResponseModel(data={
|
||||
"total": total,
|
||||
"auto": auto,
|
||||
"manual": manual,
|
||||
"reviewed": reviewed,
|
||||
"level_distribution": [
|
||||
{"name": name, "code": code, "count": count}
|
||||
for name, code, count in level_dist
|
||||
],
|
||||
})
|
||||
|
||||
|
||||
@router.get("/projects/{project_id}/download")
|
||||
def download_report(
|
||||
project_id: int,
|
||||
|
||||
Reference in New Issue
Block a user