mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-07-12 00:40:07 +08:00
e58ffd64fa
* add /api/v1/users/{user_id}/stats endpoint
* return 0 stats and add /api/v1/users/{user_id}/stats/{time_frame}
* use utcnow() as modified date for 0 stats
22 lines
746 B
Python
22 lines
746 B
Python
from typing import Optional
|
|
|
|
from fastapi import APIRouter, Depends, Query
|
|
from oasst_backend.api import deps
|
|
from oasst_backend.models import ApiClient
|
|
from oasst_backend.user_stats_repository import UserStatsRepository, UserStatsTimeFrame
|
|
from oasst_shared.schemas.protocol import LeaderboardStats
|
|
from sqlmodel import Session
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/{time_frame}", response_model=LeaderboardStats)
|
|
def get_leaderboard(
|
|
time_frame: UserStatsTimeFrame,
|
|
max_count: Optional[int] = Query(100, gt=0, le=10000),
|
|
api_client: ApiClient = Depends(deps.get_api_client),
|
|
db: Session = Depends(deps.get_db),
|
|
) -> LeaderboardStats:
|
|
usr = UserStatsRepository(db)
|
|
return usr.get_leaderboard(time_frame, limit=max_count)
|