feat(family): deploy Single-Writer DuckDB backend, Mila parent cockpit & feeding analytics, and Moritz macro tracker
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Dict, Optional
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, Request
|
||||
|
||||
from app.engine import DuckDBEngine
|
||||
|
||||
router = APIRouter(tags=["Dashboards"])
|
||||
|
||||
|
||||
def get_engine(request: Request) -> DuckDBEngine:
|
||||
return request.app.state.engine
|
||||
|
||||
|
||||
@router.get("/mila/dashboard")
|
||||
async def get_mila_dashboard(
|
||||
as_of: Optional[str] = Query(default=None, description="Optional target date YYYY-MM-DD"),
|
||||
engine: DuckDBEngine = Depends(get_engine),
|
||||
) -> Dict[str, Any]:
|
||||
try:
|
||||
return engine.get_mila_dashboard(as_of_date=as_of)
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
|
||||
@router.get("/moritz/dashboard")
|
||||
async def get_moritz_dashboard(
|
||||
as_of: Optional[str] = Query(default=None, description="Optional target date YYYY-MM-DD"),
|
||||
engine: DuckDBEngine = Depends(get_engine),
|
||||
) -> Dict[str, Any]:
|
||||
try:
|
||||
return engine.get_moritz_dashboard(as_of_date=as_of)
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
|
||||
@router.get("/mila/day/{date}")
|
||||
async def get_mila_day_detail(
|
||||
date: str,
|
||||
engine: DuckDBEngine = Depends(get_engine),
|
||||
) -> Dict[str, Any]:
|
||||
try:
|
||||
return engine.get_mila_day_detail(target_date=date)
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
|
||||
@router.get("/moritz/day/{date}")
|
||||
async def get_moritz_day_detail(
|
||||
date: str,
|
||||
engine: DuckDBEngine = Depends(get_engine),
|
||||
) -> Dict[str, Any]:
|
||||
try:
|
||||
return engine.get_moritz_day_detail(target_date=date)
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
|
||||
@router.get("/summary/{subject}")
|
||||
async def get_summary(
|
||||
subject: str,
|
||||
date: Optional[str] = Query(default=None, description="Target date YYYY-MM-DD"),
|
||||
engine: DuckDBEngine = Depends(get_engine),
|
||||
) -> Dict[str, Any]:
|
||||
try:
|
||||
return engine.get_summary(subject=subject, date_str=date)
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
Reference in New Issue
Block a user