fediversion/backend/routers/stats.py
fullsizemalt b4cddf41ea feat: Initialize Fediversion multi-band platform
- Fork elmeg-demo codebase for multi-band support
- Add data importer infrastructure with base class
- Create band-specific importers:
  - phish.py: Phish.net API v5
  - grateful_dead.py: Grateful Stats API
  - setlistfm.py: Dead & Company, Billy Strings (Setlist.fm)
- Add spec-kit configuration for Gemini
- Update README with supported bands and architecture
2025-12-28 12:39:28 -08:00

26 lines
853 B
Python

from typing import List
from fastapi import APIRouter, Depends, Query
from sqlmodel import Session, select, func
from database import get_session
from models import Song, Performance
router = APIRouter(prefix="/stats", tags=["stats"])
@router.get("/top-songs")
def get_top_songs(
limit: int = Query(default=10, le=50),
session: Session = Depends(get_session)
):
"""Get top songs by number of performances"""
query = (
select(Song.id, Song.title, func.count(Performance.id).label("performance_count"))
.join(Performance, Song.id == Performance.song_id)
.group_by(Song.id, Song.title)
.order_by(func.count(Performance.id).desc())
.limit(limit)
)
results = session.exec(query).all()
return [
{"id": r[0], "title": r[1], "performance_count": r[2]}
for r in results
]