-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2980eda
commit 4fd8f6c
Showing
3 changed files
with
30 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from __future__ import annotations | ||
from fastapi import APIRouter | ||
|
||
from pwncore.models import SolvedProblem, Team, Team_Pydantic | ||
|
||
# Metadata at the top for instant accessibility | ||
metadata = {"name": "leaderboard", "description": "Operations on the leaderboard"} | ||
|
||
router = APIRouter(prefix="/leaderboard", tags=["leaderboard"]) | ||
|
||
|
||
@router.get("/fetch_leaderboard") | ||
async def fetch_leaderboard(): | ||
teams = await Team_Pydantic.from_queryset(Team.all()) | ||
# points = await SolvedProblem.filter(team=2).values("problem__points") | ||
leaderboard = {} | ||
for team in teams: | ||
problems_solved_by_team = await SolvedProblem.filter( | ||
team__id=team.id | ||
).values_list("problem__points", flat=True) | ||
leaderboard[team.name] = sum(problems_solved_by_team) | ||
# Uncomment to return sorted leaderboard | ||
# leaderboard = dict(sorted(leaderboard.items(), key=lambda x: x[0], reverse=True)) | ||
return leaderboard |